City-Wide EV Charging Network — Part A
Definitions
Charge point protocol
- In plain English
- A charge point protocol, such as the open standard OCPP, is the agreed message format chargers use to talk to their backend, often over WebSockets.
- Think of it like
- It is like a shared language every charger brand agrees to speak.
Telemetry
- In plain English
- Telemetry is a stream of measurements a device sends automatically, such as energy delivered and temperature.
- Think of it like
- Like a fitness watch sending your heart rate every few seconds.
The brief
A city operator runs 8,000 chargers at 1,200 sites for 200,000 drivers. Support reservations, remote charging, energy billing, and operator alerts over unreliable cellular connections.
What it must do
- Find nearby chargers with live availability.
- Reserve one connector for 15 minutes and remotely start or stop charging.
- Record energy, bill per kWh, and alert operators about faults.
How well it must do it
- Never double-book a connector.
- Bill accurately after offline records are recovered and checked.
- Reflect received availability changes on the map within about 30 seconds.
- Contain faults in individual chargers and unreliable connections.
Out of scope
- Hardware design, grid load balancing, and roaming between operators.
Design walkthrough
Estimates
Assume one meter sample per charger every 30 s, all day.
Meter rate: 8,000 ÷ 30 ≈ 266.7 samples/s
Samples per charger per day: 86,400 ÷ 30 = 2,880
Daily meter rows: 8,000 × 2,880 = 23,040,000
If heartbeats are separate at the same interval:
266.7 meter messages/s + 266.7 heartbeats/s ≈ 533.3/s
Assume 200 bytes per stored reading before indexes:
23,040,000 × 200 = 4,608,000,000 bytes/day ≈ 4.61 GB/day
Map search peak assumption: 2,000 requests/s
Reservation and session peak assumption: 30 actions/s
One connection per charger: 8,000 WebSockets
Assume 4,000 connections per gateway: 8,000 ÷ 4,000 = 2- Use at least one extra gateway for failure capacity under that connection assumption. Benchmark actual message and TLS costs.
- Separate heartbeats from meter samples; not every heartbeat creates an energy reading.
- Only actively charging devices may emit meter samples, so continuous sampling is a conservative scenario.
- This is Module 2 estimation; 23 million rows alone does not prove a relational database cannot cope.
API sketch
GET /chargers?near=12.97,77.59
POST /reservations
Idempotency-Key: reserve-42
POST /sessions/{id}/start
Idempotency-Key: start-42
POST /sessions/{id}/stop
Idempotency-Key: stop-42
GET /sessions/{id}Charger opens an authenticated WebSocket.
BootNotification: identify the charger.
StatusNotification: report connector state.
MeterValues: report energy readings.
StartTransaction: report a session beginning.
StopTransaction: report the final session meter value.A command acceptance reply does not prove charging started. Wait for the session event before showing charging.
Data model
| Store | Records and keys |
|---|---|
| Relational database | Sites, connectors, reservations, sessions, tariffs, invoices, and command progress |
| Wide-column meter store | Charger ID and day group readings; time plus sample ID identifies each reading |
| Status cache | Connector state, observation time, receipt time, and last heartbeat |
| Connection ownership | Charger ID maps to gateway and current connection generation |
Use unique charger identities and original transaction identities for replay. Fix the session tariff at start; store its version and integer energy units.
Module 3 wide-column storage suits repeated readings by device and time. Daily groups prevent one device key growing forever.
Architecture
Chargers connect through gateways to an event stream; drivers read cached status and use a transactional service that sends commands through gateways.
The driver API uses a location index before joining status values. Operators read fault events and receive alerts through the same API.
A charger opens an outbound connection through cellular NAT; backend commands look up its gateway and return over that established connection.
This reuses Module 1 NAT and WebSockets. Consistent hashing chooses a preferred gateway; commands use the directory and verify its current connection generation.
Core flow
The driver reserves and requests start, a gateway delivers the command, and session reports lead to a validated invoice.
Meter values stream throughout charging. The final record closes the energy interval; missing or contradictory records require investigation before billing.
Design decisions
How do chargers stay connected?
Our choice
Chargers open WebSockets; track each live gateway owner. This combines Module 1 NAT with Module 5 consistent hashing.
Why not the alternatives
- Call each charger directly from the backendCellular NAT usually blocks unsolicited inbound connections; hashing alone cannot locate an existing socket.
Where does telemetry go?
Our choice
Use an event stream and wide-column meter storage. This combines Module 4 delivery with Module 3 write-oriented storage.
Why not the alternatives
- Mix all readings into the billing workloadFrequent inserts, retention, and queries compete with critical transactions; capacity must still be measured.
Where do reservations and billing live?
Our choice
Use relational constraints and transactions from Module 3.
Why not the alternatives
- Use eventually consistent ownership checksCompeting requests may both believe a connector is free.
How does the map stay fast?
Our choice
Use a location index and event-fed status cache. This reuses Module 3 indexing and Module 4 caching.
Why not the alternatives
- Ask every charger during each searchOffline devices and cellular latency would delay the whole map response.
Trade-offs
Pros
- Readings and billing scale separately.
- Outbound connections carry commands through cellular NAT.
- Cached status keeps map searches fast.
Cons
- Gateway ownership must follow reconnects.
- Several stores need recovery procedures.
- Offline devices leave uncertain status.
Use when
- Connected-device fleets with commands and billing.
Avoid when
- A small device fleet where one server and database meet the requirements.
Quick check
Takeaways
- Devices open WebSockets; route commands to their current gateway.
- Stream frequent readings into storage suited to device history.
- Keep money and reservations in a transactional database.