System Design
Case Study: Uber
Requirements
Functional
- Rider requests ride
- Match with nearby driver
- Real-time location tracking
- ETA calculation
- Pricing
Scale
- 100M active users
- 10M trips/day
- Real-time GPS updates
Core Challenge: Matching
Problem: Eng yaqin driver’ni topish (location-based search).
Geospatial Indexing
QuadTree
Divide map into quadrants
Each quadrant → 4 sub-quadrants
Leaf nodes → drivers in that area
class QuadTree {
search(lat, lon, radius) {
// Find quadrant
// Return drivers in quadrant
}
update(driverId, lat, lon) {
// Move driver to new quadrant
}
}
Geohash
Location → String encoding
lat: 37.7749, lon: -122.4194
→ Geohash: "9q8yy"
Nearby locations have similar prefixes
9q8yy1, 9q8yy2, ... (all nearby)
SELECT * FROM drivers
WHERE geohash LIKE '9q8yy%'
AND status = 'available'
LIMIT 10;
Architecture
Rider App → API Gateway
→ Matching Service (finds drivers)
→ Location Service (QuadTree/Redis)
→ Driver App (WebSocket)
Real-time updates:
Driver → Location Service (GPS)
→ Update QuadTree
→ Broadcast to nearby riders
ETA Calculation
// Simple: Distance / average_speed
const distance = haversine(rider, destination);
const eta = distance / 50; // 50 km/h average
// Advanced: Historical traffic data
const eta = routingService.calculate(rider, destination, time_of_day);
Pricing (Surge)
// Demand > Supply → Surge pricing
const demand = activeRiders(area);
const supply = availableDrivers(area);
if (demand / supply > 2) {
surgeMultiplier = 1.5x;
}
Scaling
10M trips/day:
- ~120 requests/sec
- Millions of GPS updates/sec
Strategies:
- Geosharding (city-based)
- Redis for hot data
- Kafka for GPS streams
- Cassandra for trip history
Xulosa
32 mavzu to’liq tayyor!
O’rgangan narsalar: 1-4: Asoslar (Kirish, Scalability, Tarmoq, Protokollar) 5-9: Kengayish (Load balancing, Scaling, Stateless, CDN, Proxy) 10-15: Ma’lumotlar (ACID, SQL/NoSQL, Indexes, Replication, Sharding, CAP) 16-19: Keshlash (Basics, Invalidation, Redis, Eventual) 20-23: Asinxron (Queues, Pub/Sub, Events, Microservices) 24-27: Qo’shimcha (Rate limit, Monitoring, Security, DR) 28-32: Case Studies (Interview, URL Shortener, Twitter, WhatsApp, Uber)
System Design masterlik sari!