AlgoMaster Logo

Geohash

High Priority21 min readUpdated July 4, 2026
AI Mock Interview

Practice this topic in a realistic system design interview

Many location systems need to answer a simple question quickly:

What places are near this point?

The slow way is to scan every latitude and longitude in the database and compute distance one by one. That does not work when the database has millions of restaurants, drivers, stores, or devices.

Geohash helps by turning a location into a short string. Nearby places often share the same starting characters, so a normal ordered index can fetch a smaller set of candidates first.

Geohash is not an exact distance calculator. It is a first-pass filter. Real systems still need to check neighboring cells, compute the actual distance, and choose the right precision for the product.

This chapter explains how Geohash encoding works, how precision changes the search area, how nearby search works, and where Geohash can surprise you.

1. What Is Geohash?

Geohash is a way to turn latitude and longitude into a short string.

It works by dividing the Earth into rectangles. Each rectangle gets a string. Longer strings point to smaller rectangles.

For example:

  • 9q8yy covers a broad area around San Francisco.
  • 9q8yyk covers a smaller cell inside that area.
  • 9q8yyk8 covers a still smaller cell.

Invented by Gustavo Niemeyer in 2008, Geohash became popular because it fits cleanly into existing storage systems. A geohash is just a string, so you can store it in a normal column, sort it, search by prefix, and index it with a B-tree.

Here is the core idea:

This nesting is why prefix queries work. Searching for 9q8yy% means "find points stored in this cell and smaller cells inside it."

2. How Geohash Encoding Works

Premium Content

This content is for premium members only.