ADR 0009: Horizontal Pod Autoscaling and pgxpool connection-count tuning (adoption)
Status
Accepted (2026-10-05). Records decisions already in effect with no ADR, found by the 2026-10-04 ADR-conformance audit.
Context
charts/warehouse-planning/templates/hpa.yaml autoscales the api,
analytics-projector, analytics-reports and frontend Deployments on CPU
utilization, each gated independently behind its own
autoscaling.<component>.enabled flag (default false, so a default render
is byte-identical to a chart without this file). internal/adapters/outbound/ postgres/pool.go caps each process's own pgxpool.Pool at a fixed
MaxConns. Neither decision had a written rationale.
Decision
- HPA is per-component and off by default. Four independent
HorizontalPodAutoscalerresources (api,analytics-projector,analytics-reports,frontend), each behind its ownautoscaling.<component>.enabled(defaultfalse). Theanalytics-projector/analytics-reportsHPAs are additionally gated onanalytics.enabled-- they cannot exist without their Deployment.scaleTargetRefis CPUResourceutilization only (autoscaling/v2); no custom-metrics scaler is wired today. MaxConns = 10per process (internal/adapters/outbound/postgres/ pool.go), apgxpool.Configceiling applied uniformly tocmd/api,cmd/mcpand, when it opens a pool,cmd/planning-projector. This bounds the service's worst-case connection footprint on the shared OLTP Postgres instance as HPA scales replica count:replicas * MaxConnsis the number a database-capacity plan must budget for, which is why the ceiling is a single named constant rather than left to the driver's own default.- HPA and the connection ceiling are deliberately coupled, not
independent tuning knobs: raising
autoscaling.api.maxReplicaswithout also reviewingMaxConns(or the database's ownmax_connections) can exhaust the shared Postgres instance under a scale-out event. Any future change to either value should consider the other.
Consequences
- A reviewer changing
maxReplicasorMaxConnsnow has a place to record why, and a reminder that the two are coupled. - No vertical (memory/custom-metric) autoscaling exists yet; CPU utilization is the only signal.
Alternatives considered and rejected
- One shared HPA resource covering every Deployment: components scale on
different load shapes (the OLTP
api, the Kafka-boundanalytics-projector, the read-onlyanalytics-reports); a single HPA would either over- or under-scale at least one of them. - No connection ceiling (driver default): pgxpool's default is
effectively unbounded per process, which combined with HPA scale-out could
silently exhaust the database's
max_connectionsunder load -- the failure this ADR's §2 decision prevents.