Why this matters
- Location features appear in ride-hailing, delivery, social check-ins, and StreamHub's live-event discovery — all share the same geospatial primitives.
- Naive latitude/longitude B-tree queries degrade at scale; purpose-built spatial indexes (R-tree, geohash grids, H3) are the difference between 5 ms and 5 s.
- Tile pyramids and vector tiles let you serve the entire planet without loading one giant image per request.
Core components of a maps platform
- Tile server — pre-rendered raster or vector tiles at zoom levels 0–20; clients request only visible tiles.
- Routing engine — directed graph of road segments with weights (distance, time, tolls); A* or Contraction Hierarchies for fast pathfinding.
- Geospatial index — R-tree, geohash prefix, or H3 hex cells for proximity and bounding-box queries.
- Reverse geocoder — converts coordinates to human-readable addresses using a spatial + text index.
- Traffic overlay — real-time speed data merged into routing weights via streaming ingestion.
Tile pyramid architecture
Geospatial maps architecture
Clients request map tiles by zoom level and tile coordinates (z, x, y). At zoom 0 the world is one tile; each level quadruples tile count.
GET /tiles/14/4821/6156.pbf
Host: tiles.streamhub.com
Accept: application/vnd.mapbox-vector-tile
Routing graph design
Road networks are stored as a graph: nodes are intersections, edges are road segments with attributes.
{
"edge_id": "e_88421",
"from_node": 10442,
"to_node": 10443,
"length_m": 312,
"speed_limit_kmh": 50,
"one_way": true,
"geometry": [[12.97, 77.59], [12.971, 77.591]]
}
| Aspect | Algorithm | When to use |
|---|---|---|
| Dijkstra / A* | Correct shortest path | Small graphs, offline preprocessing |
| Contraction Hierarchies | Preprocessed shortcuts | Production routing at Google/OSM scale |
| Isochrone queries | Reachability within N minutes | Delivery radius, EV range |
| Multi-modal | Walk + transit + drive legs | Urban mobility apps |
Dijkstra / A*
AlgorithmCorrect shortest pathWhen to useSmall graphs, offline preprocessingContraction Hierarchies
AlgorithmPreprocessed shortcutsWhen to useProduction routing at Google/OSM scaleIsochrone queries
AlgorithmReachability within N minutesWhen to useDelivery radius, EV rangeMulti-modal
AlgorithmWalk + transit + drive legsWhen to useUrban mobility apps
Routing latency targets: under 100 ms for a single origin-destination query at production scale.
Geospatial indexing for POIs
Points of interest (restaurants, venues, parking) live in a spatial index keyed by location.
-- PostGIS example: find venues within 2 km of a point
SELECT id, name, ST_Distance(location, ST_MakePoint(77.59, 12.97)::geography) AS dist_m
FROM venues
WHERE ST_DWithin(location, ST_MakePoint(77.59, 12.97)::geography, 2000)
ORDER BY dist_m
LIMIT 20;
For StreamHub event discovery, index live-stream venues by H3 resolution-7 cells (~1.2 km²) so "events near me" is a cell lookup plus a small refinement query.
Scale estimates for StreamHub maps
| Metric | Estimate |
|---|---|
| DAU using map features | 5M |
| Tile requests per user session | ~40 |
| Peak tile QPS | 5M × 40 / 86400 × 3 ≈ 7K |
| Routing queries per day | 500K |
| POI database size | ~200M points globally |
DAU using map features
Estimate5MTile requests per user session
Estimate~40Peak tile QPS
Estimate5M × 40 / 86400 × 3 ≈ 7KRouting queries per day
Estimate500KPOI database size
Estimate~200M points globally
Back-of-envelope for a mid-scale maps layer — CDN caches 95%+ of tile traffic.
Failure modes and mitigations
Production concerns
- Stale tiles — version tiles by
etagor timestamp; invalidate CDN cache on map data updates. - Routing divergence — A/B test new graph versions in shadow mode before promoting to production.
- Hot regions — pre-warm CDN cache for major events; scale tile servers horizontally per region.
- GPS inaccuracy — snap user coordinates to nearest road segment before routing.
Quick recall
Everything you need if you only revisit this box.
- Maps = tile pyramid (imagery) + routing graph (directions) + spatial index (nearby search).
- Vector tiles (
.pbf) are smaller and styleable; raster tiles are simpler but less flexible. - Use PostGIS R-tree, geohash prefixes, or H3 for proximity — not naive lat/lng range scans.
- Contraction Hierarchies make continent-scale routing sub-100 ms.
- Cache tiles at CDN edge; keep routing and POI queries on regional clusters.
Test yourself
Answer these before moving on — recall is what makes it stick.