Design an EV Fast-Charging Network Backend: Metering, Telemetry, Locator
System DesignModel answerLast updated
Design a backend for a fleet of EV fast-charging stalls covering energy-based billing, long-term health telemetry, and a nearby-available-charger search with prices.
You are asked to design the cloud backend for a worldwide network of electric-vehicle fast-charging sites. Every site contains several charging stalls, and each stall has an energy meter and a controller that can talk to the backend over the internet.
The system must satisfy three functional requirements:
- Metering and billing. Capture how much energy each charging session delivers and persist it so the customer can be charged correctly.
- Stall health telemetry. Collect health metrics and fault information from every stall and retain them in long-term storage.
- Charger locator. In the car's display or companion app, the driver taps a spot on the map and sees the closest sites that currently have a free stall, along with the price at each.
Plan for deep follow-up questions on each requirement rather than a single broad diagram. For billing in particular, be ready to discuss request routing, DNS, secure device communication, on-site buffering, and which calls are synchronous versus asynchronous. Budget your time so that all three requirements get a real design.
What to cover
- State your assumptions and clarifying questions first (scale, how a session is tied to a customer, pricing model, site connectivity, who reads the data).
- Billing: session lifecycle, data model, stall-to-backend path (device identity, transport security, DNS and routing), local buffering and behavior during outages, idempotent upload, and avoiding double or missing charges.
- Telemetry: an ingestion path isolated from billing that absorbs bursts, storage tiers with retention and downsampling, query patterns, and fault alerting.
- Locator: geospatial lookup, how stall status becomes per-site availability, caching, price lookup and its consistency with the billed price, API shape, latency budget, and behavior on a weak connection.
- Failure handling and observability for each flow.
Hints
Hint 1
Separate the three flows by what matters most to each: billing needs correctness (no loss, no duplicates), telemetry needs throughput and cheap retention, and the locator needs fast reads with bounded staleness.
Hint 2
For billing, assume the stall can lose connectivity mid-session. Think about a durable local log of meter readings, a unique session ID and sequence numbers per reading, and an upload the server can safely receive more than once.
Hint 3
For the locator, do not compute availability at query time from raw stall events. Maintain a per-site availability summary from the status stream, index sites geospatially, and fetch prices from the same source of truth that billing uses.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Assumptions
- Roughly 100k stalls across 10k sites, with up to about 50k concurrent sessions at peak.
- Meter samples every few seconds during a session; telemetry every 10 to 30 seconds per stall plus discrete fault events.
- Price is per kWh, set per site with optional time-of-day tiers; the customer is identified by the vehicle (plug-and-charge certificate) or an app-initiated session.
- A stall must be able to finish a session safely when the backend is unreachable.
- Consumers: payments, field service, engineers, the in-car app.
FR1: Metering and billing
Principle: billing is the correctness-critical path. The stall's calibrated meter is the source of truth, and the backend must bill exactly once per session even with retries and outages.
Session lifecycle: authorize -> started -> metering -> stopped -> finalized -> billed.
Data model
sessions(session_id, stall_id, customer_id, price_snapshot, start_ts, end_ts, status)meter_readings(session_id, seq, cumulative_wh, ts). Cumulative readings are robust: a lost sample does not lose energy, since the final value minus the first is the total.billing_records(session_id UNIQUE, energy_wh, amount, currency, state)
Device identity and security
- Each stall has a per-device X.509 certificate provisioned at manufacture and rotated periodically, stored in a secure element.
- Mutual TLS to the backend; the server checks the certificate against the registry (revocation supported).
- Messages are signed by the stall so that a stored reading cannot be forged or altered.
DNS and routing
- The stall resolves a stable hostname such as
ingest.example.net. Latency- or geo-based DNS returns the nearest healthy regional endpoint, with short TTLs for failover and a fallback list built into the firmware. - A regional L7 gateway terminates mTLS, authenticates the device, and routes to the session or ingest service. Do not rely on DNS alone for failover; the stall retries with backoff and tries alternate endpoints.
Local buffering
- The stall appends every reading to a durable local log (flash, write-ahead) before attempting upload. A site controller may aggregate for multiple stalls.
- If offline, the stall can continue a session within a bounded policy (for example, allow it for known vehicles up to a cap) and queues everything. On reconnect it drains the log in order.
Sync vs async
- Synchronous: session authorization at start (customer valid, payment method on file, current price returned and snapshotted) and the stop/finalize call. These need immediate answers. A timeout falls back to the offline policy.
- Asynchronous: the stream of meter readings goes through a message queue/log (Kafka-like) keyed by
session_id. Billing computation, invoice creation and payment capture are asynchronous consumers.
Exactly-once effect
- Delivery is at-least-once; processing is idempotent. Readings are upserted by
(session_id, seq); the billing record has a uniquesession_id; the payment call carries an idempotency key derived fromsession_id. - On finalize, the billing worker verifies a contiguous sequence (or reconciles via the cumulative value) and computes
amount = energy x price_snapshot.
Reconciliation and observability: a periodic job compares stall-reported totals with stored totals, flags sessions stuck in stopped without a billing record, and alerts on gaps, duplicates and abnormally large values.
FR2: Health telemetry
- Ingestion: a separate topic and pipeline from billing, so a telemetry burst (thousands of sites reconnecting after an outage) cannot delay billing. Use batching and compression on the device; the gateway applies per-device rate limits. Backpressure is absorbed by the log.
- Processing: a stream processor validates the schema, enriches with site/stall metadata and splits into (a) hot path for alerting and (b) cold path for storage.
- Storage tiers
- Hot (7 to 30 days): a time-series store keyed by
(stall_id, metric, ts)for dashboards and recent debugging. - Warm/cold: columnar files (Parquet) in object storage partitioned by date and region, queried by an analytics engine.
- Downsample older data (1-minute, then hourly aggregates) while retaining raw fault events indefinitely; this cuts storage by an order of magnitude.
- Hot (7 to 30 days): a time-series store keyed by
- Rough volume: 100k stalls x 1 sample/15 s x ~200 bytes is about 1.3 MB/s, around 110 GB/day raw before compression; very manageable.
- Queries: per-stall time ranges (hot store), fleet aggregates such as failure rates by hardware version (warehouse), and alerts (stream rules like "fault code X for N minutes", or "no heartbeat for 3 intervals").
FR3: Nearest available charger with price
- Geospatial index: sites are static, so keep them in a geospatial index (geohash/S2/H3 cells or a spatial DB). Query the cells around the tapped point, rank by distance, then refine the top candidates by driving time using a routing service if needed. Straight-line is the cheap first pass.
- Availability pipeline: stall status events (
available,occupied,faulted,reserved) feed a consumer that maintainssite_availability(site_id, free_count, updated_at)in a low-latency store (Redis). The locator reads this summary, never raw stall events. - Staleness: every entry carries
updated_at. Past a threshold (for example 2 minutes) the car shows "availability unknown" instead of a confident number. A faulted stall is excluded from the free count. - Price: read from the pricing service, cached with a short TTL. For consistency with billing, the session start returns and snapshots the price. The map price is informational, and the billed price equals the snapshot taken at authorization. If the price changes between display and start, the car shows the confirmed price before charging.
- API:
GET /v1/chargers/nearby?lat=&lng=&radius=&limit=returns sites with distance, free count, price and freshness. Target p99 under 300 ms on the server. Responses are cacheable by cell for a few seconds. Keep payloads small and support the last-known result on a poor connection.
Trade-offs and common mistakes
- Using one pipeline for everything: telemetry bursts then starve billing.
- Relying on exactly-once delivery from the transport instead of idempotent processing.
- Sending only deltas of energy, so a lost message silently under-bills; cumulative readings avoid this.
- Computing availability by scanning stalls at query time.
- Treating DNS as the only failover mechanism, or ignoring certificate rotation and revocation.
- Showing stale availability as fact.
- Spending the whole interview on one requirement; give each a clear budget.