Simple forward/reverse geocoder for WhosOnFirst admin data
README.md

Waldo #

This is a low-resource forward/reverse geocoder that uses only WhosOnFirst administrative data. That means: no addresses, no postal codes, no points of interest. It only geocodes adminstrative boundaries, so you should think cities, regions, neighborhoods, countries and the like, but not addresses like 1600 Pennsylvania Avenue.

Why? If you look at the typical resource requirements for running a planet-scale geocoder like Nominatim or Pelias, it requires on the order of 64GB of RAM to hold the dataset and can have a complicated operational architecture with Elasticsearch in the mix. That's because it's dealing with a lot of disparate data sources including postal addresses from all over the U.S. and Europe. But what if you don't need all that?

I use this geocoder in my adventure motorcyle trip planning app: https://rtw.run. When planning a motorcycle trip, searching for a city like Washington DC, is sufficient for planning a trip. You don't need the precise location of the Army-Navy Country Club or the White House.

If you can get away with city or neighborhood-level precision, the benefit is you can run a planet-scale geocoder on less than 1GB of RAM with response times < 250ms (about 250 MB from a prebuilt database file; see Resource use).

Data sources #

Head over to https://geocode.earth/data to download a parquet-formatted extract of the WhosOnFirst administrative data for a country or the whole world.

Running as a service #

Waldo serves from either of two data files:

waldo serve [-address 0.0.0.0] [-port 8999] whosonfirst-data-admin-latest.parquet
waldo serve [-address 0.0.0.0] [-port 8999] waldo.duckdb

(waldo [options] <file> without serve does the same.)

  • A WhosOnFirst parquet file is loaded into an in-memory database at startup. That takes a while and a lot of memory (see Resource use), and it downloads the DuckDB spatial and h3 extensions the first time.

  • A prebuilt database file (.duckdb) is opened read-only. Startup takes well under a second, and memory stays around 250 MB because DuckDB reads pages from the file as it needs them. Build one with:

    waldo build whosonfirst-data-admin-latest.parquet waldo.duckdb
    

    It runs the same loading query as the parquet mode and writes the result and its index to the file (about 370 MB for the world). It also installs the spatial and h3 extensions, which serving the file needs; a server opening a file never downloads anything if they're already installed. Rebuild it when you download a new parquet file: the new file is written beside the old one and renamed into place.

To pick up new data without restarting, replace the file (download a new parquet, or waldo build over the old .duckdb) and send SIGHUP. The new database is opened while the old one keeps serving, then swapped in. With a parquet file that briefly doubles memory use; with a .duckdb file it costs almost nothing.

Routes available:

GET /forward?q=<query>&lat=<lat>&lon=<lon>
GET /reverse?lat=<lat>&lon=<lon>
GET /health

The forward geocoding route allows you to set a bias point by passing lat and lon query parameters. This orders results by their distance from your bias point. To keep response times reasonable, these routes only return the top 10 results as you would typically want in an autocomplete component. The bias point helps find results that are more relevant to the current map bbox.

Response type #

Responses for both forward and reverse geocoding have the same shape (in Typescript format):

{
  results: Array<{
    gid: number; // int32 WhosOnFirst id
    name: string; // English name
    placetype: string; // WhosOnFirst placetype: typically neighbourhood, locality, county, region
    lon: number; // float64
    lat: number; // float64
    distance: number; // metres from the bias point (forward) or the query point (reverse) to the place's centroid, approximate; 0 for forward search without a bias point
    bearing: number; // degrees from that point to the place: 0 = N, 90 = E, 180 = S, 270 = W (handy for an arrow); 0 for forward search without a bias point
    region: string[] | null; // names of the place's ancestors, nearest first, not including the place itself; stops below the country. Names can repeat (["Delhi", "South West Delhi", "Delhi"]). null for a top-level place
    country: string; // the country's English name ("India"), or the raw WhosOnFirst code if it isn't a known ISO code
  }>;
  num_results: number; // at most 10 for forward geocoding, always 1 for reverse geocoding
}

For example, reverse geocoding a point near Munnar, India (/reverse?lat=10.0889&lon=77.0595):

{
  "results": [
    {
      "gid": 1779874649,
      "name": "Pallivasal",
      "placetype": "neighbourhood",
      "lon": 77.059307,
      "lat": 10.087817,
      "distance": 122.26,
      "bearing": 190.1,
      "region": ["Munnar", "Idukki", "Kerala"],
      "country": "India"
    }
  ],
  "num_results": 1
}

GET /health answers 200 with JSON: {"status": "healthy", "version": "<vcs revision>", "uptime": "1m2s", "uptime_seconds": 62.0}.

Finding points of interest #

Running lean requires using a database that only includes adminstrative boundaries. But users may also want to forward geocode points of specific places they want to go that won't be in the database, such as a restaurant, hotel, or venue. For that use case, the forward geocoder can also decode Google's open location codes, also known as plus codes.

Every location on Google Maps also includes a plus code that looks something like 35X7+FH Shimla, Himachal Pradesh, India. When one of these values is passed to the forward geocoding route or the Forward function, it will first forward geocode the reference location, here Shimla, HP, then use the associated plus code to find an exact location.

Usage as a library #

db, err := waldo.LoadParquetFile("world.parquet") // in memory, slow to load
// or, once: waldo.BuildDatabaseFile("world.parquet", "waldo.duckdb")
// then:     db, err := waldo.OpenDatabaseFile("waldo.duckdb") // read-only, fast, small
if err != nil {
  return err
}
results, err := waldo.Forward(db, "my query", [2]float64{lon, lat})
// do something with results

How it works #

A curated subset of the data in the parquet file is loaded to a DuckDB database (in memory, or written once to a file by waldo build) and then queried with SQL. An index on a 3-letter prefix of the location name speeds up queries substantially. Reverse geocoding queries are slow, but the cost to use an RTree index in terms of memory consumption is very high.

Performance #

Benchmarking code lives in the bench directory. To run all of them:

go run bench/*.go

Or just forward benchmarks:

go run bench/run.go bench/forward.go

Typical forward geocoding performance on my ancient laptop (quad core i5, 2.6GHz) is:

 Benchmark            Min      Max       Median   Mean     p95
 Forward N=3          27.3 ms  230.8 ms  84.9 ms  89.8 ms  172.0 ms
 Forward N=4          27.8 ms  165.6 ms  65.2 ms  67.5 ms  127.4 ms
 Forward No Bias N=3  52.3 ms  163.4 ms  68.5 ms  72.8 ms  100.4 ms
 Forward No Bias N=4  54.3 ms  125.4 ms  74.8 ms  79.6 ms  115.7 ms

More benchmarks and data are in the bench/ directory.

Resource use #

Measured on the world file (whosonfirst-data-admin-latest.parquet, 5.9 GB, November 2026), on a 4-core x86 laptop and under cgroup CPU and memory limits standing in for small containers:

Parquet file (in memory) Prebuilt .duckdb file
Data on disk 5.9 GB (only 9 columns are read: a trimmed copy is 109 MB) 368 MB
Startup work ~16 CPU-seconds (building the table and index) opening the file
Ready in, 4 cores 4.4 s 0.2 s
Ready in, 1/2 vCPU 30 s —
Ready in, 1/4 vCPU 60 s 1.5–1.7 s
Ready in, 1/16 vCPU — 6 s
Memory ~950 MB peak, ~880 MB steady ~250 MB (same speed capped at 256 MB as at 1 GB)
Forward, 4 cores / 1/4 vCPU 0.04 s / 0.4 s 0.06 s / 0.4 s
Reverse, 4 cores / 1/4 vCPU 0.15 s / 2.2 s 0.3 s / 3.3–3.6 s
CPU per request forward ~270 ms, reverse ~540 ms about the same

Queries are CPU-bound: DuckDB scans in parallel, so a reverse lookup that takes 0.15 s on 4 cores takes several seconds on a quarter of a core. waldo build itself takes ~8 s and ~1 GB of memory on 4 cores.

Container image #

The Dockerfile builds a self-contained image in three stages: it compiles Waldo, downloads the world parquet file and builds waldo.duckdb from it, then copies the binary, the database file and the installed DuckDB extensions into a small runtime image (about 0.5 GB). The image needs no network at startup and serves on port 8999.

make image          # builds waldo:<date>, tagged with the date of the WhosOnFirst data (from its Last-Modified)
make push           # pushes it as atcr.io/rtw.run/waldo:<date> and :latest (log in first: podman login atcr.io)

The build downloads 5.9 GB and needs about 1 GB of memory; the data download is cached as a layer until the WhosOnFirst file changes. CONTAINER=docker make image uses Docker instead of Podman.

License #

MIT