Interview's MateSystem Design
Interview's Mate

System Design

Architecture & trade-offs

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
System Design topics
Lesson 29/ 31
Reliability, Security & Case Studies

Geo-Spatial & Location Systems

Index moving drivers, restaurants, and landmarks in 2D space for sub-100 ms proximity queries.

AdvancedGeohash · Quadtree · H3/S23 quiz questions0/2 subtopics done
Practice in AI HLD
In plain wordsDiagramTheorySubtopics (2)Step by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice
Deep-dive subtopics (2) - 0/2 completed
Geohash, Quadtrees & Uber H3

Compare static grids, adaptive trees, and hexagonal spatial indexes.

Advanced
Driver Matching, Dispatch & Live ETA

Stream 4-second GPS pings, lock a driver atomically during offer dispatch, and compute road-network ETAs.

Advanced

In plain words

Location systems answer questions like "what is near me?" quickly by dividing the map into cells, so they only search the cells around you instead of the whole world.

Think of it like…

Dividing a city map into numbered square/hexagonal tiles: to find nearby taxis, you only check your tile and its 8 neighbors instead of every taxi in the country.

Where you’ve seen it

When you open Uber, it looks only at drivers in the map cells around you to find the nearest car in milliseconds.

Words you’ll hear

Geohash
Encodes a location as a short string; nearby places share prefixes.
Quadtree
A map split into four squares, recursively, where it is busy.
H3 / S2
Grid systems (hexagons or squares) from Uber and Google.
Proximity search
Finding everything within a distance of a point.

Visual diagram

Loading interactive diagram
Loading interactive exercise

Theory & deep dive

Why 2D `BETWEEN lat AND lon` indexes fail (and how Grid Hashing fixes it)

A standard B-Tree sorts one number well, not two (lat AND lon) together. Querying lat BETWEEN A AND B AND lon BETWEEN C AND D still scans huge strips across the whole globe.

Geohash, Google S2, and Uber H3 map 2D earth coordinates into 1D grid cell IDs where nearby locations share the same prefix or cell ID. Always query the user’s cell plus its 8 neighboring cells so a driver 50 meters away across a grid boundary is never missed!

Key takeaway: Index live driver locations in memory (Redis GEO / Geohash / H3) and always include the 8 neighbor cells.

How it works, step by step

Step 1 of 4
Location Stream

1. Ingest frequent location pings cleanly

Drivers send GPS updates every 3–5 seconds. Write current positions to an in-memory geo store (Redis GEO / sharded cell index) and stream history to Kafka/cold storage.

Never update a relational disk DB every 3s for 1M drivers
Key numbers at this step
Ping Interval
3–5 seconds
Hot Store
In-memory / Redis

When to use it & trade-offs

What it is

Geo-spatial systems convert 2D (latitude, longitude) coordinates into 1D prefixes or hierarchical grid cells (Geohash, Quadtrees, Google S2 / Uber H3) to support fast “find nearest K drivers within 3 km” queries.

Why it matters: Filtering WHERE lat BETWEEN ... AND lon BETWEEN ... on 10M moving drivers forces expensive 2D scans; spatial cells turn proximity into simple prefix/cell lookups.

When to reach for it

  • Ride-hailing (Uber/Lyft), food delivery (DoorDash), nearby restaurants (Yelp), and dating discovery
  • Real-time surge pricing per H3 hexagon based on local supply/demand counts
  • Live courier/driver location streaming on a map while trip is active

When to avoid or be careful

  • Updating PostgreSQL rows every 3 seconds per active driver when an in-memory geo index handles ephemeral pings
  • Querying only a single Geohash cell without checking its 8 surrounding neighbors

Spatial Indexing Structures

Geohash (Base32 Prefix / Redis GEO)
Best for: Fast proximity lookups on uniform-to-moderate density maps

Strengths: Simple 1D string prefix (u4pru), native Redis GEORADIUS support.

Watch out: Boundary edge cases (must query 8 neighbors) and fixed grid sizes.

Quadtree (Adaptive Grid Tree)
Best for: Uneven density (dense Manhattan vs. rural highways), static POIs (Yelp)

Strengths: Splits dense cells automatically so every leaf holds ~100–500 places.

Watch out: Frequent moving-driver updates require tree rebalancing/locking.

Google S2 / Uber H3 (Hexagons)
Best for: Ride-hailing dispatch, surge pricing zones, global spatial analytics

Strengths: Hexagons (H3) have uniform distance to all 6 neighbors; S2 handles spherical earth cleanly.

Watch out: Requires spatial library integration and multi-resolution aggregation.

Interview signals & numbers to know

When this topic comes up

  • nearby drivers
  • within 5 km
  • ride hailing
  • food delivery
  • ETA routing

Benchmarks & rules of thumb

Driver ping cadence -
Every 3–5 seconds
Geohash precision 6 -
~1.2 km × 0.6 km
Geohash precision 5 -
~4.9 km × 4.9 km
Offer lock timeout -
10–15 seconds

Common mistakes & follow-ups

Common interview mistakes

  • Returning drivers sorted by Haversine straight-line distance when a river or one-way highway doubles the real driving ETA
  • Querying only one Geohash cell - a driver 50 meters away across a cell boundary gets missed
  • Writing high-frequency ephemeral GPS pings directly into a primary SQL table

Likely interviewer follow-ups

  • Why must you query a Geohash cell AND its 8 neighbors for proximity search?
  • Why does Uber prefer hexagonal H3 cells over square grids for surge pricing and dispatch?
  • How do you avoid assigning one driver to two simultaneous ride requests?
Interview tip: Split the location pipeline cleanly: ephemeral GPS pings → in-memory spatial index (Redis GEO/H3), while trip state transitions live in an ACID DB.

Knowledge check

Loading quiz

Put it into practice

Design full architectures with AI feedback

Apply Geo-Spatial & Location Systems inside real High-Level Design prompts or review Q&A flashcards.

Open AI HLD Practice →SD Interview Q&A
Previous topic
Security, Auth & Payment Systems
Next topic
Trade-offs & Bottlenecks