Design Google Maps
Difficulty: 🔴 Hard | Time: 45-60 min | Prerequisites: Graph algorithms, Geo-indexing, CDN
1. Requirements Clarification
Functional Requirements
Non-Functional Requirements
- Latency: Route calculation < 200ms, map tiles < 50ms
- Availability: 99.99% uptime
- Scale: 1 billion daily active users, 10B+ daily API calls
- Coverage: 200+ countries, 25+ million miles of roads
Capacity Estimation
2. High-Level Architecture
3. Core Components Deep Dive
3.1 Map Tile System
Maps are divided into tiles at different zoom levels using a quadtree structure.Tile Addressing
Tile Caching Strategy
3.2 Road Graph Data Structure
The road network is stored as a weighted directed graph:Graph Partitioning
The world’s road network is too large for a single machine. We use graph partitioning:- Partition by Geography: Each region (city, country) is a partition
- Border Nodes: Connect partitions at highway entry/exit points
- Contraction Hierarchies: Pre-compute shortcuts for faster long-distance routing
3.3 Routing Algorithm
For optimal routing, we use Contraction Hierarchies (CH) combined with A* search:Route Alternatives
Users often want multiple route options:3.4 Real-Time Traffic System
Traffic Calculation
3.5 ETA Prediction
ETA is not just distance/speed—it requires ML prediction:4. Geo-Indexing for Search
To find nearby places efficiently, we use geospatial indexing:Option 1: Geohash
Option 2: S2 Cells (Used by Google)
S2 geometry provides better coverage at poles and consistent cell sizes:5. Data Pipeline
Map Update Pipeline
6. Scalability Considerations
Geographic Sharding
- Local road graph replicas
- Regional tile caches
- Traffic data aggregation
Caching Strategy
7. Interview Tips
Common Follow-ups
How do you handle offline maps?
How do you handle offline maps?
- Pre-download tiles for a region at multiple zoom levels
- Compact road graph for the region (smaller than server version)
- On-device routing with simplified algorithm
- Sync updates when back online
How do you detect new roads?
How do you detect new roads?
- GPS traces that don’t match existing roads
- Satellite imagery + ML for road detection
- User reports and driver feedback
- Partner data from city governments
How do you handle traffic incidents?
How do you handle traffic incidents?
- Real-time event ingestion from multiple sources
- Immediate routing recalculation for affected areas
- Push notifications to users on affected routes
- Predictive modeling for incident duration
Key Trade-offs
8. Summary
Key Takeaways:- Hierarchical graph with contraction hierarchies for fast routing
- Tile pyramid with aggressive CDN caching for map rendering
- S2 cells for efficient geospatial queries
- Real-time traffic from GPS probes + ML prediction
- Geographic sharding for global scale