Analytics Service — Migration Plan
Status: populated Owner: Platform Engineering + SRE Last updated: 2026-04-18
1. Context
Greenfield service. No predecessor. Migration involves:
- Backfilling historical analytics from NATS stream replay (up to stream retention limits).
- Migrating any pre-existing manual reporting (spreadsheets/ad-hoc queries) to this service's REST API.
2. Schema Migration
Standard Prisma migrations applied in order. No complex data transformations — tables start empty and are filled by event processing.
# Staging
pnpm --filter @ghasi/service-analytics prisma migrate deploy
# Production
# Applied via CI/CD pipeline on deploy
3. Historical Backfill
NATS streams retain:
BILLING_EVENTS: 7 days.SMS_DLR: 3 days.
Backfill procedure:
- Deploy analytics service with empty DB.
- Seek durable consumers to the oldest available sequence:
nats consumer edit BILLING_EVENTS anlyt-billing-consumer --deliver all. - Service replays all retained events;
processed_eventsdedup ensures correct single-processing. - After catch-up, consumers switch to normal push delivery.
For history beyond stream retention, a data migration from the existing PostgreSQL orch.sms_messages and billing tables may be performed by a one-time backfill script. Estimate: ~3 hours for 90 days of data at expected platform scale.
4. Dashboard Cutover
Admin-dashboard currently reads ad-hoc queries from orch schema directly. Migration plan:
- Deploy analytics service + seed data.
- Update admin-dashboard to call analytics REST API.
- Smoke-test dashboard accuracy vs old ad-hoc queries.
- Remove ad-hoc query code from admin-dashboard.
5. Rollback
- Analytics DB can be dropped and recreated (it is a projection — source of truth is always NATS/billing/orch schemas).
- Admin-dashboard can revert to direct DB queries if analytics API is unavailable (feature flag).