Real-time requirements for EV charging stations
An EV charging station must address several simultaneous, real-time concerns:- Notify drivers which chargers are free so they can find or reserve a charger.
- Track how long a vehicle was charged (and energy delivered) so users can be billed correctly.
- Provide administrators with remote monitoring of station health, faults, and utilization.
Event types and topic strategy
- Station status events — indicate availability and operational state (e.g.,
free,occupied,fault,reserved). - Charging session events — capture session lifecycle data (start time, stop time, energy delivered, user id).
Separate topics allow independent scaling, retention policies, and schema evolution. Use message keys (for example
station_id) to ensure all messages for the same station route to the same partition (Kafka guarantees ordering within a partition) and to enable partitioned processing.Topic configuration patterns (recommended)
Sample message formats
Use a clear schema (Avro/Protobuf/JSON Schema) and register schemas in a schema registry so producers and consumers evolve safely. Example station status event (JSON):End-to-end data flow (high level)
- IoT devices and charger controllers (producers) publish events into Kafka topics when plug-in/out, faults, reservations, or payments occur.
- Messages should be keyed by
station_id(orsession_idfor session-scoped ordering) so updates for a given charger are routed to the same partition and ordering is preserved. - A stream processing layer (Kafka Streams, ksqlDB, or another consumer) aggregates status events to compute real-time metrics such as “available chargers at station X” and publishes aggregates or exposes them via APIs.
- Downstream consumers:
- Mobile/web apps subscribe to status aggregates or the
station-statustopic to show availability and enable reservations. - The billing/payment system consumes
charging-sessionevents to calculate duration/energy and perform invoicing or payment processing. - Admin dashboards and alerting systems consume both topics for monitoring, fault detection, and capacity planning.
- Mobile/web apps subscribe to status aggregates or the
Consumers and processing patterns
- Real-time aggregates: use Kafka Streams or ksqlDB to compute running counts (e.g., available connectors), time-windowed metrics, or alerts.
- Billing pipelines: process append-only session events for accurate invoicing and audit. Use transactional producers/consumers or idempotent design when possible to ensure accuracy.
- Monitoring and alerting: feed metrics into Prometheus/Grafana or an observability platform; use compacted status topics to quickly reconstruct current station states.
For billing and financial workflows, ensure exactly-once semantics or strong deduplication. Use Kafka transactions, idempotent producers, or a robust reconciliation process to avoid duplicate charges or missing sessions.
Benefits of this architecture
- Real-time user experience: drivers receive immediate availability updates and can reserve chargers.
- Accurate billing: session events provide an audit trail with start/stop times and energy consumption.
- Operational observability: administrators can monitor utilization, detect faults, and respond remotely.
- Scalability and decoupling: Kafka separates producers (IoT devices) from many independent consumers so each downstream service can scale and evolve separately.

Further reading and references
- Apache Kafka: https://kafka.apache.org/
- Kafka Streams documentation: https://kafka.apache.org/documentation/streams
- ksqlDB: https://ksqldb.io/
- Schema design and registry concepts (Confluent Schema Registry)