Design a Driver Location Heatmap
Understanding the Problem
🗺️ What is a driver location heatmap? A driver heatmap shades a city map by how many drivers have been in each area recently. Operations teams use it to spot where supply is thin, the driver app shows it so drivers can head to busy areas, and the pricing system uses the same numbers as its "supply" input for surge. Under the hood it's a real-time counting problem: turn a firehose of GPS pings into counts per area, per minute, and keep them fresh.
The version you'll usually be asked: show, for every area of a city, the number of distinct drivers seen in the last 20 minutes, broken into 1-minute buckets so the map can be played back minute by minute, and make the counts available to surge pricing in real time. It's a close cousin of the ad click aggregator: high-volume events in, windowed counts out. The geospatial part and the word "distinct" are what make it interesting.
Functional Requirements
Core Requirements
- The system should ingest location pings from all online drivers.
- Users should be able to view a heatmap of a city or map viewport showing the number of distinct drivers per area over the last 20 minutes.
- Users should be able to step through the last 20 minutes in 1-minute buckets (a time slider).
- The surge pricing system should be able to read current supply counts per area in near real time.
Below the line (out of scope)
- Demand heatmaps (ride requests). Same pipeline, different input stream; we'll mention it.
- Long-term historical analytics ("supply in Brooklyn every Friday last year"). That's a warehouse query.
- The surge pricing model itself. We only provide its input.
Non-Functional Requirements
Ask about the scale and how fresh the map needs to be. We'll assume 1.5M drivers online at peak, each sending a ping every 4 seconds.
Core Requirements
- The system should handle 375,000 pings per second at peak, with bursts above that.
- The heatmap should be fresh: a minute's bucket should be available within about 60-90 seconds of the minute ending.
- Heatmap queries should return in under 200ms, and the system should handle thousands of concurrent viewers (ops dashboards plus driver apps).
- Counts should be accurate to within a few percent. A driver pinging 15 times a minute counts once, not 15 times.
- Supply counts for surge should be available within seconds of each minute closing.
Below the line (out of scope)
- Exactly-once billing-grade accuracy. These are operational numbers.
- Multi-year retention.
Back-of-the-envelope:
- Input: 375k pings/s × ~100 bytes ≈ 37MB/s, or about 22.5M pings per minute.
- After de-duplication: in a minute, a driver is in one or two cells at the resolution we'll use. So 22.5M pings become roughly 2-3M distinct (cell, driver) pairs per minute. That's a 10x reduction right at the first step.
- Output: using H3 hexagons at resolution 8 (about 0.7 km² each), a big metro area has a few thousand cells with drivers in them; globally maybe a few hundred thousand active cells. One minute's output for a city is a few thousand
(cell, count)pairs, a few tens of KB.
The output is tiny compared to the input. That tells us where the work is: in a streaming job that compresses the firehose, not in the serving layer.
The word "distinct" is the trap. You can't get "distinct drivers in the last 20 minutes" by adding up twenty 1-minute distinct counts: a driver who sat in the same cell all 20 minutes would be counted 20 times. Point this out early; it decides the data structure.