Skip to main content

Orders Service — Deployment Topology

Status: populated Owner: TBD Last updated: 2026-04-18 Companion: Service Template · SERVICE_OVERVIEW · 17 Technology Stack

1. Runtime

AttributeValue
RuntimeNode.js 22 LTS / NestJS 11
LanguageTypeScript 5.x
Container imageghcr.io/ghasitech/orders-service:latest
Port3010 (HTTP)
ProtocolHTTP/1.1 (internal), HTTP/2 optional via Kong
Health endpointsGET /health/live, GET /health/ready, GET /health/startup

2. Kubernetes Deployment

3. Replica and Scaling Policy

EnvironmentMin replicasMax replicasScale trigger
Production38CPU ≥ 65% or p95 latency > 700 ms
Staging24CPU ≥ 70%
Development11n/a

Anti-affinity: Pod anti-affinity rules ensure replicas do not share a node (zone-spread preferred).

PodDisruptionBudget: minAvailable: 2 — at least 2 replicas available during rolling updates.

4. Regions and Data Residency

Deployment targetRegionNotes
Primary prodAfghanistan (AFG) — on-premise or private cloudMoPH data residency requirement
DR / SecondaryConfigurable per tenantSame-region preferred; cross-region requires MoPH approval
StagingSame infrastructure as prod (separate namespace)Data anonymised

Data residency is enforced at the PostgreSQL and NATS storage level. No patient data leaves the declared jurisdiction without explicit tenant consent configuration.

5. Resource Requests and Limits

ContainerCPU requestCPU limitMemory requestMemory limit
orders-service200m1000m256Mi512Mi
Init container (migrate)100m200m128Mi256Mi

6. Dependencies at Runtime

DependencyTypeRequiredFallback
PostgreSQL 16 (orders schema)Data storeYes — hardCircuit-breaker; 503 on startup
NATS JetStreamEvent busYes — for outbox relayOutbox buffered in DB; relay retries
RedisAllergy cache + idempotency keysYesFallback to DB cache (degraded, slower)
terminology-serviceCDS rule lookupYes — softCDS check skipped with CDS_DEGRADED alert (hard-stop rules disabled)
medication-serviceDrug interaction referenceYes — softCDS degraded
registration-servicePatient/encounter validationYes — hard503 returned if unreachable
KeycloakJWT validationYes — hard401 until recovered

7. Database Schema Isolation

The orders-service operates on the orders schema in the shared PostgreSQL cluster. Row-Level Security (RLS) is enforced on all tables with tenant_id as partition key. The service connects using a dedicated orders_service_role DB role with no cross-schema read access.

8. Outbox Relay Worker

The outbox relay is a co-located worker thread within the same NestJS process. It polls orders.outbox every 500 ms, publishes pending events to NATS JetStream, and marks them delivered. A distributed lock (Redis SETNX) prevents duplicate relay across pods.

9. Rolling Update Strategy

strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0

Pre-stop hooks drain in-flight requests with a 15-second grace period. Database migrations run as a separate Job before the Deployment rollout begins.

10. Canary Deploy

Production changes use a 5% canary weight via Kong's weighted routing for 30 minutes before full rollout. Rollback is triggered automatically if error rate > 1% during canary window.

11. Environment Variables (Key)

VariablePurpose
DATABASE_URLPostgreSQL connection string (Vault-injected)
NATS_URLNATS JetStream URL
REDIS_URLRedis for cache and locks
CDS_SERVICE_URLCDS engine HTTP endpoint
TERMINOLOGY_SERVICE_URLterminology-service base URL
REGISTRATION_SERVICE_URLregistration-service base URL
KEYCLOAK_REALM_URLKeycloak realm issuer URL
ORDERS_TENANT_ISOLATEFeature flag: RLS enforcement (default true)

All secrets injected via Vault Agent Injector; never stored in image or ConfigMap.

12. Open Questions

  • Dedicated read replica for high-volume patient order list queries — evaluate when p95 > SLO consistently.