Kafka use case
- Updated: 2026/05/12
Review the use case to understand how Kafka is used to allocate rides in a sample ride booking app.
In this use case, the rider app automatically assigns the nearest available driver to a new rider request using Kafka event streams, while ensuring each ride request is processed exactly once.
The following is the end-to-end workflow of completing a ride request in a sample ride booking app:
- Rider requests a trip from Santa Monica to Beverly Hills.
- Rider app connects to a Kafka broker
session.
Rider app acts as the Kafka producer.
- Rider app publishes the request as a message to a Kafka topic. For example,
ride-requests. - Kafka stores this event in one partition of
ride-requests. For example, partition2.All events for this ride are tracked through a unique ID and are sent to the same partition.
- Ride allocation service acts as a Kafka consumer of
ride-requests. For example,group.id = ride-allocation-service.If there are multiple allocation service instances, Kafka assigns different partitions to different consumers in the same group ID. This allows only one service instance to process a ride request. For example,ride-allocation-service-1 -> ride-requests partition 0, 1 ride-allocation-service-2 -> ride-requests partition 2, 3 - Allocation service also consumes driver availability or location data from a Kafka topic. For example,
driver-location-updates.All events for the driver availability are tracked through a unique ID.
- Allocation service selects the closest eligible driver.
- Allocation service now acts as a producer and publishes an assignment event to a Kafka topic
ride-assignments. - Kafka stores the assignment event in a partition
ride-assignments. - After the assignment is saved successfully, the allocation service commits the
offset for the consumed
ride-requestsmessage. - Rider app disconnects from the Kafka broker session. Kafka then reassigns its partitions to other active instances in the same group.