PrepZone Logo
PrepZone

Google Maps and Geospatial Systems

Tile rendering, routing graphs and geospatial indexes for location-aware applications.

Read these first

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

tilesroute APICLIENT
Map client
NETWORK
CloudFrontS3 map tiles
COMPUTE
Routing svcEKS
DATABASE
RDS PostGISroad graph
CloudFront tile CDN; PostGIS RDS routing; cached traffic API.

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.

Java
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.

Java
{
  "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]]
}
AspectAlgorithmWhen to use
Dijkstra / A*Correct shortest pathSmall graphs, offline preprocessing
Contraction HierarchiesPreprocessed shortcutsProduction routing at Google/OSM scale
Isochrone queriesReachability within N minutesDelivery radius, EV range
Multi-modalWalk + transit + drive legsUrban mobility apps
  • Dijkstra / A*

    AlgorithmCorrect shortest path
    When to useSmall graphs, offline preprocessing
  • Contraction Hierarchies

    AlgorithmPreprocessed shortcuts
    When to useProduction routing at Google/OSM scale
  • Isochrone queries

    AlgorithmReachability within N minutes
    When to useDelivery radius, EV range
  • Multi-modal

    AlgorithmWalk + transit + drive legs
    When 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.

Java
-- 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

MetricEstimate
DAU using map features5M
Tile requests per user session~40
Peak tile QPS5M × 40 / 86400 × 3 ≈ 7K
Routing queries per day500K
POI database size~200M points globally
  • DAU using map features

    Estimate5M
  • Tile requests per user session

    Estimate~40
  • Peak tile QPS

    Estimate5M × 40 / 86400 × 3 ≈ 7K
  • Routing queries per day

    Estimate500K
  • POI 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 etag or 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.