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:

  1. Rider requests a trip from Santa Monica to Beverly Hills.
  2. Rider app connects to a Kafka broker session.

    Rider app acts as the Kafka producer.

  3. Rider app publishes the request as a message to a Kafka topic. For example, ride-requests.
  4. Kafka stores this event in one partition of ride-requests. For example, partition 2.

    All events for this ride are tracked through a unique ID and are sent to the same partition.

  5. 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
    
  6. 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.

  7. Allocation service selects the closest eligible driver.
  8. Allocation service now acts as a producer and publishes an assignment event to a Kafka topic ride-assignments.
  9. Kafka stores the assignment event in a partition ride-assignments.
  10. After the assignment is saved successfully, the allocation service commits the offset for the consumed ride-requests message.
  11. Rider app disconnects from the Kafka broker session. Kafka then reassigns its partitions to other active instances in the same group.