Skip to main content

Audit Service — Deployment Topology

Status: populated Owner: TBD Last updated: 2026-04-18 Companion: Service Template

1. Runtime

AttributeValue
RuntimeNestJS 11 / Node 22 LTS / TypeScript 5.x
Container imageghasi/audit-service:latest
Base imagenode:22-alpine
Port3006 (internal)
Health endpointGET /health
Readiness probeDB connectivity + NATS subscription alive

2. Kubernetes deployment

apiVersion: apps/v1
kind: Deployment
metadata:
name: audit-service
namespace: ghasi-ehealth
spec:
replicas: 2 # minimum; HPA scales to 6
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
template:
spec:
containers:
- name: audit-service
image: ghasi/audit-service
resources:
requests: { cpu: 200m, memory: 256Mi }
limits: { cpu: 500m, memory: 512Mi }

3. Scaling

MetricTargetMinMax
CPU70 %26
NATS consumer lag> 1 000 pending msgsTriggers alert

The audit service is write-heavy (high event ingestion) and read-light (compliance queries are infrequent). Scaling is driven primarily by NATS consumer lag.

4. Regions and data residency

DeploymentRegionNotes
PrimaryAfghanistan (AF)MoPH data-residency; Postgres and NATS co-located in-country
DR passiveSecondary on-prem or cloud regionAsync replica; DNS failover
Dev/stagingShared cloudSynthetic events only; no real PHI

5. Database topology

ComponentTechnologyNotes
Primary DBPostgreSQL 16audit schema; INSERT-only role; monthly range partitions on recorded_at
audit_app DB roleINSERT on audit_entries, SELECT on audit_entries + audit_exports, INSERT + UPDATE on audit_exportsUPDATE and DELETE on audit_entries explicitly revoked
BackupDaily pg_dump + WAL archiving7-year minimum retention (MoPH BR-AUD-003)
MigrationsDrizzle Kit, CI-appliedNever auto-run on startup

6. Object storage (export files)

ComponentTechnologyNotes
Export bucketS3-compatible (MinIO on-prem / AWS S3)NDJSON and CSV files; signed URLs with 1-hour TTL
Retention90 days for export filesUnderlying audit_entries persist 7 years

7. NATS JetStream

StreamSubjects consumedNotes
All platform streams (wildcard)com.ghasi-ehr.>, patient_chart.>, ai_gateway.>, etc.Wildcard consumer subscribes to all event streams
AUDIT_DLQaudit.dlqDead-letter queue; max-deliver exhausted messages

The audit service does not publish to streams (except audit.export.requested.v1, audit.export.completed.v1, audit.dlq.alert.v1).

8. Network and security

ControlValue
IngressKong edge gateway; query + export APIs only
mTLSEnabled in-cluster
NATS TLSRequired for all consumer connections
SecretsKubernetes Secrets via Vault Agent
Network policyDeny-all; allow list: NATS ingress, Postgres, Kong, object storage

9. Canary and rollout

StageTraffic %DurationValidation
Canary5 %30 minNATS consumer lag stable; no chain-hash errors; no DLQ growth
Progressive50 % → 100 %15 min eachSame gates
Rollback triggerChain-hash integrity test fails or DLQ growingAutomated via Argo Rollouts