← Back to projects

Infrastructure · 2026

EV Control Plane

NestJSTypeScriptPostgreSQLTypeORMundiciPostgres LISTEN/NOTIFYVitest

The Problem

A bank of EV chargers on the same circuit shares one fixed amperage budget — a parking level wired to a 200A breaker can't let every stall draw full power at once. Operators need to cap, pause, reserve, and override how that budget is split across chargers, with safety rules always winning over partner and operator ones.

The hard part is speed and trust. A rule change has to reach the physical chargers almost immediately, it must never overshoot the breaker, and it can't be silently lost when a process restarts or a database connection drops mid-flight.

The Solution

We built a control plane that separates the fast read-heavy math from the slower write-heavy hardware calls. A stateless resolver recomputes each charger's target amperage from the prioritised rule set whenever anything changes; a fleet of per-charger reconcilers — one lightweight async worker each, modelled on the Kubernetes controller pattern — pushes those targets to the downstream OCPP gateway.

The two halves communicate through a durable Postgres desired-state table plus LISTEN/NOTIFY, so rule writes never block on hardware and a restarted worker simply rebuilds from committed state instead of trusting an in-memory queue. Rules are source-keyed with a database-enforced 'one active rule per source' invariant, and wall-clock-driven changes fire from a Postgres-backed scheduler rather than fragile in-process timers.

Results

  • Rule write to downstream dispatch measured at 19–33 ms end-to-end — comfortably inside the 100 ms SLA
  • Cold-start convergence of a 20-charger fleet in 21 ms wall-clock, first request to last
  • Survives lost notifications and process restarts by rebuilding from durable Postgres state, never in-memory queues
  • Rapid successive rule changes collapse into a single downstream call to the latest value, sparing hardware redundant commands