Skip to main content
← PROBLEMS / SYSTEM-DESIGN
An end-to-end domain learning journey

Design a Real-Time Geospatial Road
Congestion Analytics System (1M Pings/sec).

Design a Real-Time Geospatial Road Congestion Analytics platform ingesting 1M GPS pings/sec from connected vehicles and mobile apps to power live traffic heatmaps and <10ms dynamic ETA routing.
Start the journey7 stages· Last modified Nov 24, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

If 10M active vehicles each send 1 ping every 10s, raw ingress is 1M pings/sec, batch GPS pings at the mobile SDK, ingest via gRPC into Kafka, run stateful Flink HMM map-matching + 60s tumbling windows, and serve Redis H3 tiles alongside ClickHouse spatial analytics.

TL;DR30-second simplified summary
▾

To handle 1M pings/sec, batch 5 pings at the SDK, run HMM snapping against local mmap OSM tiles in Flink, pack 60s speeds into Redis H3 Res-6 hashes, and route >20s late tunnel pings to ClickHouse.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
H3 Hexagonal Spatial Indexing & HMM Map-Matching
H3 Hexagonal Spatial Indexing & HMM Map-Matching partitions the Earth into uniform hexagonal cells and uses a Viterbi Hidden Markov Model to snap noisy GPS pings onto exact OpenStreetMap road segments.
Full walkthrough · 7 stages
01
foundation

1M GPS Pings/sec Scale & Edge Batching.

Why this matters: Quantify bandwidth, RPC rates, and mobile battery/network savings.

If 10M active vehicles each send 1 ping every 10s, raw ingress is 1M pings/sec.

Sending 1M individual HTTP requests/sec wastes TLS/header overhead.

Ingress Sizing

SDK 5-Ping Batching: 1M Pings/s -> 200K gRPC QPS

10M Active VehiclesTelemetry sourceMobile/Car SDKBatcher5x RPC reductiongRPC Ingest TierStateless gatewayKafka Telemetry BusDurable bufferStreams Protobuf

1.5x Lower RPCs: Batching 5 pings per gRPC frame slashes mobile battery drain and server TLS overhead.

2.Pre-Sorted Trajectory: A 5-ping batch arrives together, giving Flink's HMM instant multi-point context.

Client-side 5-ping Protobuf batching cuts ingress QPS by 5x while giving HMM instant trajectory context.

02
foundation

Dual-Sink Serving & Spatial Analytics Topology.

Why this matters: Serve live heatmaps and ETA APIs from Redis while archiving trajectories in ClickHouse.

Think of Dual-Sink Serving & Spatial Analytics Topology as the intuition layer for Design a Real-Time Geospatial Road Congestion Analytics System (1M Pings/sec): Serve live heatmaps and ETA APIs from Redis while archiving trajectories in ClickHouse.

Flink outputs 60-second aggregated segment speeds to two sinks: Redis H3 Tile Cache (for sub-5ms traffic tile rendering and CCH ETA graph updates) and ClickHouse Spatial Analytics (storing raw/snapped trajectories for urban planning and ST-GNN training).

System Blueprint

Flink Map-Matching -> Redis Tiles + ClickHouse

Kafka GPS BusIngestion logFlink HMM + 60sWindowStream processorRedis H3 Tile CacheHot serving tierClickHouse SpatialOLAPAnalytics lakePushes live tile speeds

1.H3 Tile Grouping: Grouping segment speeds into one Redis Hash per H3 Res-6 cell fetches an entire map tile in 1 RTT.

2.90-Day OLAP: ClickHouse answers city-wide bottleneck queries across months in seconds.

Redis H3 tile hashes power <5ms map overlays while ClickHouse retains 90-day spatial history.

Engineering Decision Framework
Problem
How to implement Design a Real-Time Geospatial Road Congestion Analytics System (1M Pings/sec) without hitting unbounded tail latency, state divergence, or operational fragility.
Naive Solution
Use a single unpartitioned path with unbounded retries and synchronous global coordination.
Why It Fails
Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
Alternatives
Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
Engineering Decision
If 10M active vehicles each send 1 ping every 10s, raw ingress is 1M pings/sec, batch GPS pings at the mobile SDK, ingest via gRPC into Kafka, run stateful Flink HMM map-matching + 60s tumbling windows, and serve Redis H3 tiles alongside ClickHouse spatial analytics.
Trade-Offs
Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
Decision Exercise · Make the Call

When Design a Real-Time Geospatial Road Congestion Analytics System (1M Pings/sec) experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?

03
intermediate

Flink Map-Matching with Local OSM Tile Caching.

Why this matters: Execute 1M HMM snaps/sec in Flink without hitting an external spatial database.

Think of Flink Map-Matching with Local OSM Tile Caching as the intuition layer for Design a Real-Time Geospatial Road Congestion Analytics System (1M Pings/sec): Execute 1M HMM snaps/sec in Flink without hitting an external spatial database.

Querying PostGIS over the network 1M times/sec is impossible. Each Flink TaskManager memory-maps a compact binary OSM road-graph tile (~4 GB per continent) or lazy-loads H3 Res-6 OSM tiles into local RocksDB/RAM, snapping pings in <50 microseconds.

In-Process OSM

Flink TaskManager Local Mmap OSM Tile Cache

Versioned OSM Tiles(S3)Map artifactTaskManager MmapCacheLocal geometryViterbi HMMOperatorIn-memory snapSnapped SpeedStreamWindow inputReturns 50m candidates

1.Zero DB Hops: Memory-mapped local R-trees eliminate network latency during map-matching.

2.Weekly Map Sync: New roads and turn restrictions roll out via versioned S3 tile broadcasts.

Memory-mapped H3-sharded OSM tiles inside Flink TaskManagers enable 1M snaps/sec with zero DB calls.

04
intermediate

60-Second Tumbling Windows & Late-Ping Watermarks.

Why this matters: Handle cellular tunnel dropouts without skewing live congestion tiles.

Cars entering tunnels lose cellular signal and flush buffered pings 30–60 seconds later.

Flink uses a 60-second tumbling window with a 20-second event-time watermark.

Tunnel Dropouts

20s Watermark & Late-Ping Side-Output

Tunnel BufferedPingsLate telemetryFlink 20s WatermarkFreshness gateRedis Live TileCurrent trafficClickHouseSide-OutputComplete historyEmits timely windows

1.Fresh Live Maps: Excluding >20s stale tunnel pings prevents ghost traffic jams from appearing later.

2.Complete History: ClickHouse still receives every delayed ping for accurate rush-hour baselines.

Event-time watermarks keep live traffic maps fresh while preserving delayed tunnel pings in ClickHouse.

05
intermediate

Live Traffic Heatmap & Dynamic ETA APIs.

Why this matters: Serve viewport traffic tiles and CCH shortest-time routes under 10ms p99.

Think of Live Traffic Heatmap & Dynamic ETA APIs as the intuition layer for Design a Real-Time Geospatial Road Congestion Analytics System (1M Pings/sec): Serve viewport traffic tiles and CCH shortest-time routes under 10ms p99.

Map clients request traffic overlays by H3 Res-6 tile ID, hitting a CDN + Redis cluster (<5ms). Simultaneously, the Dynamic ETA Routing API pulls updated segment speeds from Redis every 1 second to customize CCH edge weights and answer routing queries in <10ms.

Serving APIs

CDN/Redis Tile Serving & 1s CCH Weight Refresh

Map Viewport ClientHeatmap consumerEdge CDN (15s TTL)Read shieldRedis H3 Tile CacheTile sourceDynamic ETA EngineRouting APICache miss <5ms

1.15s CDN Caching: Caching public H3 traffic tiles for 15s at the CDN absorbs 95% of rush-hour map loads.

2.Historical Fallback: Rural segments with zero live pings seamlessly fall back to time-of-day priors.

15-second CDN caching and Redis H3 tile hashes scale traffic overlays to millions of commuters.

06
advanced

Privacy-Preserving Telemetry & Trajectory Stripping.

Why this matters: Prevent tracking individual commuters' home/work addresses.

Think of Privacy-Preserving Telemetry & Trajectory Stripping as the intuition layer for Design a Real-Time Geospatial Road Congestion Analytics System (1M Pings/sec): Prevent tracking individual commuters' home/work addresses.

Raw GPS trajectories can reveal home addresses. The Ingestion API rotates ephemeral device_session_ids every 15 minutes (long enough for 5-ping HMM, too short for trip reconstruction) and strips the first/last 200 meters of trips before archiving to ClickHouse.

Location Privacy

15-Min Ephemeral IDs & 200m Endpoint Fuzzing

gRPC Ingest EdgeUnlinkable IDFlink HMM SnapperAnonymous match200m EndpointStripperHome/work guardClickHouse ArchiveCompliant lakeFilters trip endpoints

1.15-Min Rotation: Short-lived session tokens support HMM continuity without enabling cross-day tracking.

2.200m Fuzzing: Dropping trip start/end tails prevents reverse-engineering home driveways.

Ephemeral 15-minute session IDs and 200m endpoint stripping protect commuter privacy without hurting traffic accuracy.

07
advanced

Anomaly Detection for Incidents & Road Closures.

Why this matters: Detect accidents and sudden road closures within 2 minutes of occurrence.

Think of Anomaly Detection for Incidents & Road Closures as the intuition layer for Design a Real-Time Geospatial Road Congestion Analytics System (1M Pings/sec): Detect accidents and sudden road closures within 2 minutes of occurrence.

A sudden 80% speed drop on a highway segment paired with zero downstream throughput signals an accident or closure. A Flink Z-score detector compares live segment speeds against ClickHouse 8-week same-hour priors, flagging incidents to routing engines within 120 seconds.

Incident Detection

2-Minute Z-Score Congestion Anomaly Detector

60s Live SpeedCurrent signal8-Week Hour PriorBaseline normFlink Z-ScoreDetectorIncident triggerRouting PenaltyPushTraffic reliefSupplies historical norm

1.2-Minute Detection: Automated Z-score triggers detect highway crashes faster than manual 911 feeds.

2.Cross-Check Quorum: Require >=5 independent vehicles reporting slowdowns to avoid false-positive closures.

Comparing live 60s speeds against 8-week priors detects accidents and closures within 2 minutes.

Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

Why should the mobile/vehicle SDK batch 5 GPS pings into one Protobuf gRPC request instead of sending every ping immediately?

Recommended Learning Flow