Skip to content

Examples/Mobility

Ride hailing dispatch (example)

Riders request trips, nearby drivers get 15-second offers, and trips move through a state machine until the rider is charged. Redis GEO indexes driver positions, Postgres holds trips, and Kafka carries trip events.

Scale: 50k active drivers pinging every 4 s; 300 trip requests/s at peak

1234567891011121314CLIENTRider appCLIENTDriver appEDGEAPI gatewaySERVICELocation serviceCACHERedis GEOSERVICEDispatch serviceSERVICEPricing serviceEXTERNALMaps providerSERVICETrip serviceDATABASEPostgresLOG / STREAMKafkaWORKERNotificationworkerEXTERNALPush providerEXTERNALPayment provider

Select a component to see what it is responsible for and which state it owns.

  1. 1Driver app → Location service: Send GPS ping
  2. 2Location service → Redis GEO: Update position
  3. 3Rider app → API gateway: Request ride
  4. 4API gateway → Dispatch service: Find a driver
  5. 5Dispatch service → Redis GEO: Nearby drivers
  6. 6Dispatch service → Pricing service: Price trip
  7. 7Dispatch service → Maps provider: ETA
  8. 8Dispatch service → Driver app: Offer trip
  9. 9Driver app → Trip service: Accept offer
  10. 10Trip service → Postgres: Transition trip
  11. 11Trip service → Kafka: Trip events
  12. 12Notification worker → Kafka: Consume events
  13. 13Notification worker → Push provider: Notify
  14. 14Trip service → Payment provider: Charge fare
  • Request / response
  • Server push
  • Asynchronous

Select a part to trace its flows.

  • Request / response
  • Server push
  • Asynchronous

Parts 14

Flows 14

  1. 1Driver app → Location serviceSend GPS pingRequest / response
  2. 2Location service → Redis GEOUpdate positionRequest / response
  3. 3Rider app → API gatewayRequest rideRequest / response
  4. 4API gateway → Dispatch serviceFind a driverRequest / response
  5. 5Dispatch service → Redis GEONearby driversRequest / response
  6. 6Dispatch service → Pricing servicePrice tripRequest / response
  7. 7Dispatch service → Maps providerETARequest / response
  8. 8Dispatch service → Driver appOffer tripServer push
  9. 9Driver app → Trip serviceAccept offerRequest / response
  10. 10Trip service → PostgresTransition tripRequest / response
  11. 11Trip service → KafkaTrip eventsAsynchronous
  12. 12Notification worker → KafkaConsume eventsRequest / response
  13. 13Notification worker → Push providerNotifyRequest / response
  14. 14Trip service → Payment providerCharge fareRequest / response

Invariants 3

  • A trip has one driver and a driver one active trip

    UPDATE trips SET driver_id = $d, state = 'accepted' WHERE id = $t AND state = 'offered' AND offer_id = $o, plus a partial unique index on trips(driver_id) WHERE state IN ('accepted','in_progress').

    Kept by

  • A stale offer cannot be accepted

    Offers are 15 s leases with an offer id; acceptance checks the id (fencing) and state; dispatch re-offers after expiry.

    Kept by

  • A trip is charged once

    Charge on the completed→charged transition with idempotency key = trip id.

    Kept by