πŸ’¬
βœ‰οΈ
πŸ“Έ
▢️

Loading…

Design Uber: location, matching, and trip service

UberGuided Mode

Step 7 β€” Trip Service

Request Flow

1

Create trip on match

Trip Service consumes MatchConfirmed from the queue and creates a trip record in Cassandra (state: REQUESTED). Idempotency key = trip_id β€” duplicate queue messages produce no duplicate trips.

2

Advance state machine

As the trip progresses, driver actions arrive via the API Server β†’ Trip Service: ACCEPTED β†’ DRIVER_ARRIVED β†’ IN_PROGRESS β†’ COMPLETED. Each transition is appended to the event log with a timestamp.

3

Downstream fan-out

On COMPLETED: Trip Service emits trip.completed. Billing computes and charges the fare. Rating Service prompts both users. Analytics updates driver earnings. All from one event.

Why We Need This

Without Trip Service, trip state leaks into the Matching Service and API. Billing has no authoritative record. Support cannot reconstruct the event sequence. Analytics cannot compute ETA accuracy. A single owner with an event log solves all three.

Key Insight

Own the trip lifecycle in one service. Event-sourced state machine = complete audit trail + decoupled downstream consumers + reliable billing.

Step 7 of 8