System design walkthroughs 3: geo and marketplaces
Problem. Full interview answers for the bank’s geo and marketplace questions. Part 3 of 6. (1: foundations · 2: feeds · 4: media & storage · 5: money · 6: AI era)
15. Uber / ride-hailing [Uber, Lyft, DoorDash, Ola]
Requirements. Functional: request ride, match driver, track trip, bill. Non-functional: match in seconds at rush hour, billing exactly once, driver locations fresh within seconds.
Estimation. 10M trips/day ≈ 120/s average, 10× at rush; 1M drivers × location ping/5s = 200k writes/s of tiny payloads — the hottest path, so it gets its own pipeline.
API. POST /rides {from, to}, GET /rides/{id} (trip state machine:
requested → matched → ongoing → billed), POST /rides/{id}/pay.
Core design. Geo-shard driver locations by geohash cells; dispatch searches the rider’s cell plus neighbors; trip state in a transactional store; billing as a separate exactly-once path (idempotency keys, never double-charge on retry).
flowchart LR
R[Rider request] --> D[Dispatch]
L[(Driver cells)] -.->|nearby drivers| D
D --> T[Trip state]
T --> B[Billing]
Deep dives. Ping frequency vs battery/load, surge as a supply-demand signal (not just pricing), ETAs from segment speeds, and cite Uber’s engineering blog once — interviewers notice.
16. Airbnb / bookings [Airbnb, Booking, Expedia]
Requirements. Functional: search listings, book dates, reviews. Non-functional: never double-book, search p99 under 300 ms.
Estimation. 1M searches/day ≈ 12/s average, 10× seasonal; bookings a trickle beside it — search is the system, booking is the transaction.
API. GET /search?geo=&dates=&filters=, POST
/bookings {listing, dates} (hold-then-confirm), POST /reviews.
Core design. Search index over listings (geo + filters + calendar snapshots), booking as hold-with-TTL then confirm, reviews on a separate write-heavy path, async trust/safety checks off the booking path.
17. Food delivery [Swiggy, DoorDash]
Requirements. Functional: order, assign courier, live-track all three sides (eater, restaurant, courier). Non-functional: assignment in under a minute at dinner rush, restaurant tablets work through flaky networks.
Estimation. Dinner rush is a daily flash sale: 5M orders in 3 hours ≈ 500/s sustained, 2k/s peaks; courier pings mirror the Uber math above.
API. POST /orders, POST /orders/{id}/assign, websocket
GET /track/{id}, POST /orders/{id}/status.
Core design. Order state machine shared by all three apps; assignment batches nearby orders (when to bundle is the algorithm question); prep-time estimates feed dispatch; restaurant client tolerates offline (queued actions, conflict apology, not conflict prevention).
18. E-commerce checkout [Amazon, Flipkart]
Requirements. Functional: cart, pay, confirm/cancel. Non-functional: never charge without reserving, never reserve without expiry, survive payment-provider timeouts ambiguously (did it charge? must be answerable).
Estimation. Normal day 1k checkouts/s, sale day 50k/s for hours; each checkout fans into inventory + payment + notification — size the saga coordinator, not just the API.
API. POST /checkout {cart, idempotency_key}, GET
/orders/{id}, POST /orders/{id}/cancel.
Core design. Reserve inventory with TTL holds → charge via idempotent payment calls → confirm; failures trigger compensating actions (release, refund) — a saga, never 2PC across services. Flash-sale mode: queue plus oversell protection at the inventory service, stated before asked.
19. Ticket booking like BookMyShow [Flipkart, MakeMyTrip-type; widely asked in India]
Requirements. Functional: browse shows, pick seats, pay. Non-functional: zero double-sells, seat map live for thousands of concurrent viewers.
Estimation. 50k seats per blockbuster weekend, 1M concurrent browsers at sale open; reads 1000:1 over booked seats — the map is a cache problem, the booking is a serialization problem.
API. GET /shows/{id}/seats, POST /holds {seats, ttl}, POST
/holds/{id}/pay, POST /holds/{id}/release.
Core design. Optimistic seat holds with TTL visible to everyone immediately; payment converts holds, timeouts release them; map reads from cache/replicas, writes serialized per show; waiting-list promotion on release.