Before you start
Ride Matching is the last problem in this module — a mix of Strategy (matching algorithm) + basic state management (driver in-pool vs on-ride, ride in-progress vs completed).
The Strategy signal, again
Two matching algorithms today (Nearest, RoundRobin). More possible later: rating-weighted, least-loaded, surge-aware, territorial. Every one is a new strategy class.
Your dispatcher must NOT know which algorithm is
running. It just calls strategy.match(...) and uses
the return.
The state question (again)
Every driver is in one of two states:
- Available — in the pool, can be matched
- On-ride — matched, waiting for complete_ride
Every ride is in one of two states:
- In-progress — matched but not completed
- Completed — done
Do you use the State pattern for two-state entities? No — that's the third time this course has said it. State pattern for 2 states is overkill. A single field is fine.
The rules (this is where design interviews score you)
Three matter:
- A driver is in at most one state. They're EITHER in the available pool OR on a ride. Never both, never neither (except after remove_driver, when they're neither on purpose).
- Completed rides can't be re-completed. complete_ride checks status before running.
- Matching removes the driver from the pool ATOMICALLY. No window where they're "matched but still available" — a bug that would double-match them.
Enforce each in ONE place. Name them.
Where this shows up
- Uber, Ola, Rapido — the whole industry
- Delivery apps (Swiggy, Zomato) — same shape, different entities
- Load balancers routing requests to backends — same Strategy shape, different tie-breaking
- Task schedulers assigning work to workers — same shape
- Any "match-me-with-a-resource" API
The follow-up questions
- "How would you scale this to millions of drivers?" — a spatial index (quadtree, geohash) to make Nearest O(log N) instead of O(N). HLD territory.
- "How would you handle drivers going offline mid-ride?" — ride cancellation path + rematch. Real feature; out of MVP.
- "How would you support pool rides (multiple riders)?" — ride can hold multiple riders + ordered stops. Big change, but doable with the current shape.
Your design.md doesn't have to answer these — but if your design SETS YOU UP to answer them cleanly, that's the extensibility signal.
Module close
25 lessons + 12 LLD problems = 37 lessons total in the LLD course. You've drilled:
- OOP basics (module 1)
- SOLID principles (module 2)
- 14 design patterns (module 3)
- 12 LLD problems, each needing a designed + justified solution (module 4)
The last module (5, the Capstone) lets you apply everything on YOUR chosen domain, not one we gave you.
Every interview problem you meet from here will be some combination of what you've already built.