System Design (50 Qs)•Part 2: Real-World High-Scale Architecture Problems (11 - 25)
Design a Proximity / Ride-Sharing Service (Uber / Lyft).
In Simple Words: Connect drivers with nearby riders in real-time while processing location updates every 4 seconds from millions of active vehicles with sub-100ms spatial matching.
Spatial Indexing Technologies:
- Geohash: Hierarchical spatial data structure that subdivides Earth into bounding grid boxes and encodes them into Base32 strings. Nearby locations share common string prefixes!
- Example: Prefix
9q8yycovers an area of roughly $4.9\text{ km} \times 4.9\text{ km}$.
- Example: Prefix
- Google S2 / Uber H3: Uses hexagonal cells rather than rectangular boxes, eliminating corner distortion and ensuring all neighbors are equidistant.
Architecture Flowchart
flowchart TD
Driver["Driver Phone App"] -->|"GPS Update Every 4s"| LB["Geo-DNS / Envoy LB"]
LB --> LocationSvc["Location Ingestion Service"]
LocationSvc --> RedisGeo["Redis Geospatial Engine (GEOADD / GEORADIUS)"]
Rider["Rider App"] -->|"Find Rides Near (Lat, Lon)"| MatchSvc["Ride Dispatcher Engine"]
MatchSvc --> RedisGeo
RedisGeo -.->|"Return Top-10 Drivers within 3km"| MatchSvc
MatchSvc --> DispatchSvc["Optimal Routing & Notification"]