44. Design Ride-Hailing with Surge Pricing (Uber / Rapido)
1
The interview prompt2
44.1 What do you ask first?3
44.2 How big is this, really?4
44.3 What are the doors?5
44.4 What do we store?6
44.5 What does the whole system look like?7
44.6 How are location updates handled?8
44.7 How does matching work?9
44.8 How does surge pricing work?10
44.9 How does the trip state machine work?11
44.10 What would you say in the last five minutes?12
Score yourself13
Variations to practise14
Sources15
Code lab44. Design Ride-Hailing with Surge Pricing (Uber / Rapido)
44.3 What are the doors?
3 min read+10 XP
Step 3: API and data model (10 minutes)
(driver WebSocket) → { "type": "loc", "lat": 12.97, "lng": 77.59, "ts": ..., "available": true }
← { "type": "offer", "trip_id": "t1", "pickup": {...}, "expires_in_s": 12 }
→ { "type": "accept", "trip_id": "t1", "event_id": "e-55" }
POST /v1/quotes { "pickup": {...}, "drop": {...}, "product": "bike" }
returns: { "quote_id": "q9", "price": 180, "surge": 1.5, "expires_at": "..." }
POST /v1/trips Idempotency-Key: … { "quote_id": "q9" } → 201 { "trip_id": "t1", "state": "requested" }
POST /v1/trips/{id}/events { "event_id": "e-61", "type": "arrived" } (driver app; idempotent)
GET /v1/trips/{id} → state, driver, live location
The quote locks the price (including surge) for a few minutes, so the rider pays what they saw.