Analytics Service — Deployment Topology
Status: populated Owner: SRE Last updated: 2026-04-18
1. Runtime
- Node.js 22 LTS, TypeScript 5.x strict.
- NestJS 10 +
@nestjs/platform-fastify. - Image: distroless Node, multi-stage build, non-root.
- Listen ports:
3030HTTP,9464metrics.
2. Kubernetes
| Object | Value |
|---|---|
| Kind | Deployment |
| Replicas | 2 (min) / HPA 2–8 |
| HPA triggers | CPU 70%; custom metric anlyt_nats_consumer_pending (target 5,000 per pod) |
| Rolling update | maxSurge=1, maxUnavailable=0 |
| PDB | minAvailable=1 |
| Resources | requests: 500m CPU / 512Mi; limits: 2 CPU / 1Gi |
| ServiceAccount | analytics-service |
3. Dependencies (at runtime)
| Dep | Mode | Notes |
|---|---|---|
| PostgreSQL | Primary writer + read replicas | Read-heavy; separate read replica for REST API queries |
| NATS JetStream | 3-node cluster | 2 durable consumers (anlyt-billing-consumer, anlyt-dlr-consumer) |
| ClickHouse (optional) | ETL only | Not in real-time path |
4. No Kong Route
This service has no Kong route. Kubernetes Service is of type ClusterIP. External traffic cannot reach it without going through admin-dashboard or customer-portal (which are Kong-fronted).
5. Read Replica Usage
- NATS consumer processing writes go to PG primary.
- REST API queries go to PG read replica (connection pool configured by
DATABASE_READ_URL). - This separation prevents dashboard query load from blocking event processing.
6. Scheduled Jobs
| Job | Schedule | Description |
|---|---|---|
anlyt-daily-rollup | 0 * * * * (hourly) | Rolls hourly buckets into daily |
anlyt-processed-purge | 0 2 * * * (daily 02:00 UTC) | Purges processed_events older than 48 h |
anlyt-clickhouse-etl | 0 3 * * * (daily 03:00 UTC, optional) | Copies rows > 90 d to ClickHouse |
Jobs run as Kubernetes CronJob objects using the same image as the main Deployment.
7. Regions
Single-region deployment matches PostgreSQL primary region. ClickHouse can be cross-region if needed for BI.