AlgoMaster Logo

S2 and H3

Medium Priority18 min readUpdated October 25, 2026
AI Mock Interview

Practice this topic in a realistic system design interview

Premium Video

This video is available to premium subscribers only

Unlock Full Access

Global systems often need to group, search, and count locations across the whole Earth.

S2, from Google, and H3, from Uber, both do this by dividing the Earth's surface into cells and giving each cell a compact numeric ID. That ID can then be used as an index key, a grouping key for analytics, or a shard key.

In this chapter, we'll explore Google's S2 and Uber's H3, two systems that divide the Earth's surface into uniform geographic cells. We'll look at how they work, how they differ, and when to use each one.

1. The Problem with a Flat Grid

Many spatial indexing systems, like Geohash, represent the Earth using a flat grid of latitude and longitude. Longitude runs horizontally, latitude runs vertically, and the grid divides the map into smaller cells.

This works well for searches within a city. But it introduces some problems when we start working at a global scale.

  • Cells shrink toward the poles. Lines of longitude get closer together as we move toward the poles. As a result, a grid cell near the equator covers a much larger area than a cell at the same grid resolution near the Arctic.
  • The map has edges the Earth doesn't. For example, two ships on opposite sides of the 180° line of longitude in the Pacific Ocean might be just a few kilometers apart. But on a flat grid, they appear at opposite ends of the map.

For global applications like ride-hailing services, shipping trackers, and mapping platforms, these differences can make location searches more complicated. To handle them, we need a way to divide the Earth's surface into cells that account for its spherical shape.

2. Two Global Cell Systems

S2 and H3 take a similar approach. Both divide the Earth's surface into cells and assign each cell a compact numeric ID. They also support multiple levels of resolution, so we can represent large geographic regions or zoom in to much smaller areas.

However, they organize these cells differently and were designed with different use cases in mind.

S2H3
Built byGoogleUber
Main purposeIndexing geographic data and location-based searchesAnalyzing trips, traffic, and demand across cities
Cell shapeRoughly squareMostly hexagonal
HierarchyEach cell splits into 4 children that fit exactly inside itEach cell has 7 children that only roughly fit
StrengthRepresenting regions as ranges of IDsWorking with neighboring areas and distances
  • S2 uses roughly square-shaped cells that fit neatly inside larger parent cells.
  • H3 uses mostly hexagonal cells, which make it easier to work with neighboring areas and measure distances across the grid.

Let's start by understanding how S2 works.

3. S2: Mapping the Earth onto a Cube

Premium Content

This content is for premium members only.