đď¸ Real-World Case Studies
Uber-like Ride Sharing Platform
Designing a real-time ride-sharing platform at Uber scale
Uber processes 20+ million trips per day across 70+ countries. The core technical challenge: process 250,000 location updates per second and match available drivers to rider requests within 2 seconds using real-time geospatial queries.
Key Concepts
Real-Time Location Ingestion
1 million active drivers send GPS coordinates every 4 seconds over Netty Netty/WebSocket connections. Redis Geo (Sorted Set with 52-bit geohash scores) processes updates in <1ms RAM memory.
Uber H3 Hexagonal Grid
The earth map is partitioned into uniform hexagonal H3 cells. Unlike square grids, all neighbor hexagon centers are equidistant, enabling k-ring radius expansion search without boundary distortion.
Intelligent Match Engine
Matching algorithm calculates composite scores: Score = (w1 * ETA) + (w2 * Driver Rating) - (w3 * Cancellation Rate). Top driver gets 15-second dispatch offer window.
Geo-Sharded Cassandra
Trip histories and trajectory logs are sharded by City_ID and H3_Index in Apache Cassandra to distribute write IOPS across multiple database nodes.
⥠Interactive Architecture Simulator
Uber-like Dispatch Architecture Trade-off Simulator
Compare Spatial Indexing algorithms (Geohash vs Quadtree vs Uber H3) for driver matching speed.
Uber H3 Hexagonal Grid + Redis Geospatial (Recommended)Recommended
Hexagonal cell spatial index with uniform distance metrics. k-ring radius neighbor lookups in O(1).
PostGIS Spatial Query (ST_DWithin)High Risk
Direct SQL queries using PostGIS R-Tree B-Box indexes on main database.
Standard Geohash 7-Char Prefix + Redis ZSETBaseline
Rectangle grid geohash prefixes stored in Redis ZSET.
250,000 ops/s
Throughput Capacity
18%
Peak DB CPU Load
12ms
P99 Response Latency
$$
Infrastructure Cost
Architectural Assessment & Bottleneck Analysis
Production Grade â â Zero distortion at poles/equator. 1M driver locations updated every 4s with 12ms P99 matching latency.
Capacity Math & Throughput Breakdown
| Metric | Calculation | Scale Requirement |
|---|---|---|
| Active Drivers Ingestion | 1,000,000 drivers / 4s interval | 250,000 Location Writes / sec |
| Payload Ingestion Bandwidth | 250k updates Ă 200 bytes JSON | 50 MB / sec (400 Mbps Network IO) |
| Redis RAM Footprint | 1M drivers Ă 128 bytes ZSET record | ~ 128 MB RAM (Ultra lightweight) |
Geospatial Indexing Comparison: Geohash vs Quadtree vs Uber H3
| Indexing Tech | Cell Geometry | Neighbor Distance Uniformity | Uber Suitability |
|---|---|---|---|
| Geohash | Rectangle Box | Non-uniform (Diagonal is longer) | Boundary edge bugs near equator/poles |
| Quadtree | Variable Rectangles | Complex dynamic tree rebalancing | High memory overhead for tree nodes |
| Uber H3 (Recommended) | Hexagon Grid | 100% Uniform Center-to-Center Distance | Production standard for global matching |
Production Code Snippet 1: WebSocket Driver Location Ingestor
driver-location-ws.tstypescript
1import Redis from 'ioredis';
2import { latLngToCell } from 'h3-js';
3
4const redis = new Redis({ host: 'redis-geo.internal', port: 6379 });
5
6export interface DriverPing {
7 driverId: string;
8 lat: number;
9 lng: number;
10 timestamp: number;
11}
12
13export async function handleDriverLocationPing(ping: DriverPing) {
14 const { driverId, lat, lng } = ping;
15
16 // Resolution 8 = ~0.737 sq km hexagon cell
17 const h3Index = latLngToCell(lat, lng, 8);
18
19 const pipeline = redis.pipeline();
20
21 // 1. Store location in Redis Geo Spatial index
22 pipeline.geoadd('drivers:geo:active', lng, lat, driverId);
23
24 // 2. Add driver to specific H3 cell set for fast matching
25 pipeline.sadd(`h3:cell:${h3Index}:drivers`, driverId);
26
27 // 3. Set heartbeat expiry for offline detection
28 pipeline.set(`driver:heartbeat:${driverId}`, 'ONLINE', 'EX', 10);
29
30 await pipeline.exec();
31}Production Code Snippet 2: H3 k-Ring Neighbor Driver Matcher
match-h3-driver.tstypescript
1import { gridDisk, latLngToCell } from 'h3-js';
2import Redis from 'ioredis';
3
4const redis = new Redis();
5
6export async function findNearbyDriversH3(riderLat: number, riderLng: number, maxRadiusKm: number = 3) {
7 // Get rider's current H3 Cell (Resolution 8)
8 const originCell = latLngToCell(riderLat, riderLng, 8);
9
10 // k-ring radius disk (ring 1 = 7 hexagons, ring 2 = 19 hexagons)
11 const nearbyCells = gridDisk(originCell, 2);
12
13 const candidateDriverIds: string[] = [];
14
15 for (const cell of nearbyCells) {
16 const driversInCell = await redis.smembers(`h3:cell:${cell}:drivers`);
17 candidateDriverIds.push(...driversInCell);
18 }
19
20 // Filter available drivers & calculate exact distances
21 const availableDrivers = [];
22 for (const driverId of candidateDriverIds) {
23 const isOnline = await redis.exists(`driver:heartbeat:${driverId}`);
24 if (isOnline) {
25 const pos = await redis.geopos('drivers:geo:active', driverId);
26 if (pos && pos[0]) {
27 availableDrivers.push({
28 driverId,
29 lng: parseFloat(pos[0][0]),
30 lat: parseFloat(pos[0][1]),
31 });
32 }
33 }
34 }
35
36 return availableDrivers;
37}đĄ
Senior Architect Insight: The secret to Uber-scale real-time matching is Uber H3 hexagonal spatial indexing paired with in-memory Redis Geo. Hexagons guarantee equidistant neighbor expansion without boundary anomalies, processing 250k location updates/sec effortlessly.