Building Custom Geocoders with AWS Lambda, DuckDB and GeoParquet
Standard commercial geocoders handle street addresses well, but real-world environmental and infrastructure datasets are rarely that clean. Two patterns break standard locators almost immediately: Puerto Rico's highway kilometer markers (such as Carretera 2 Km 14.5) and relative highway offsets found in legacy field records (such as 5 miles east of Flagstaff, AZ on I-40).

Historically, solving either problem meant standing up a dedicated PostGIS database or an enterprise GIS server, paying for idle compute, and managing a custom ETL pipeline just to keep road networks current.
These two edge cases were something I wanted to explore this weekend. So, as a proof of concept, I built both as stateless, Esri-compatible REST endpoints running inside 1024 MB AWS Lambda container images, powered by Python 3.12, DuckDB Spatial, and GeoParquet on S3. Here is how both architectures work, where DuckDB hit a memory wall inside Lambda, and the benchmarks from fixing it.
Two Geocoders, One Serverless Pattern
Both services expose a standard /GeocodeServer/geocodeAddresses interface so downstream tools and batch pipelines can call them like any other geocoder. Under the hood, they share the same core stack: a Lambda container image with DuckDB's spatial and httpfs extensions pre-installed at build time, reading spatially sorted GeoParquet over S3 byte-range requests.
| Attribute | pr-lrs-geocoder |
relative-offset-geocoder |
|---|---|---|
| Target Pattern | Puerto Rico LRS kilometer markers (PR-2 Km 14.5) |
Relative highway offsets (10 miles north of Rifle, CO on Highway 325) |
| Reference Data | US DOT HPMS Puerto Rico LRS road network | Public Overture Maps transportation (type=segment) |
| Storage Pattern | Spatially sorted GeoParquet in S3 extracted from US DOT server | Direct reads from s3://overturemaps-us-west-2 via bbox manifest |
| Core Geometry Logic | Route lookup + linear interpolation along M-values | Anchor geocode + dual-carriageway gap chaining + directional offset |
| Lambda Memory | 1024 MB | 1024 MB |
1. The Puerto Rico LRS Geocoder (pr-lrs-geocoder)
Addresses in Puerto Rico frequently reference a route number and a kilometer or hectometer marker rather than a street number. Because the island's road network is a bounded dataset, converting the US DOT Linear Referencing System (LRS) network into Hilbert-sorted GeoParquet in S3 makes it straightforward for DuckDB to query.
On each request, the Lambda parses the route and kilometer value, uses DuckDB to pull only the matching route geometry via Parquet row-group pruning, and interpolates the exact coordinate along the line. There is no database server to patch, scale, or keep warm.
2. The Relative-Offset Geocoder (relative-offset-geocoder)
Relative offsets are harder because they can occur anywhere in the United States, on any Interstate, US Highway, or state route. Rather than maintaining a national road database myself, I pointed DuckDB directly at Overture Maps' public GeoParquet files in S3.
For each record, the geocoder:
1. Parses the distance, units (miles, km, feet, meters), direction, anchor place, and route name.
2. Geocodes the anchor city or town to establish a starting point and search bounding box.
3. Queries Overture Maps road segments inside that bounding box.
4. Chains fragmented segments across dual carriageways and interchange gaps, then walks the requested distance in the target direction.
The Lambda Wall: Global S3 Globs and Status 137
Overture's GeoParquet files are already Hilbert-sorted with bbox min/max statistics, so I initially pointed DuckDB straight at the global wildcard path: theme=transportation/type=segment/*.
In a 2048 MB Lambda container, it crashed with status 137 (OOM kill) every time.
Profiling locally showed peak RSS hitting 2207.3 MB on a 3-record batch, even with DuckDB's memory_limit capped at 768MB. The culprit wasn't the road geometries themselves. It was the wildcard glob. On a cold connection against type=segment/*, DuckDB had to list all 128 global Parquet files and download their footers over HTTPS just to read the bbox stats and figure out which files to skip. Those Parquet footers accumulated in unmanaged C++ memory outside DuckDB's memory_limit.
Bumping Lambda to 3008 MB got the 3-record batch to pass, but it took 57.2 seconds (~19.1 seconds per record). That wasn't viable for batch workloads.
The Fix: A 15 KB Spatial Manifest
I didn't want to subset Overture down to specific highway classes and risk dropping rural or county routes that show up in environmental records. Instead, I kept 100% of Overture's road classes and eliminated the S3 glob.
A one-time script (build_manifest.py) runs parquet_metadata() against the Overture release and extracts the file-level xmin, xmax, ymin, and ymax for all 128 files into a ~15 KB JSON file (overture_segment_manifest.json).
At runtime, Python filters that 128-entry list against the request's bounding box in microseconds. Instead of globbing the planet, DuckDB receives an explicit list of 1 or 2 exact S3 URLs:
SELECT ST_AsWKB(geometry) AS geom_wkb
FROM read_parquet(['s3://overturemaps-us-west-2/.../part-00042.zstd.parquet'], hive_partitioning=1)
WHERE subtype = 'road'
AND bbox.xmin <= ? AND bbox.xmax >= ?
AND bbox.ymin <= ? AND bbox.ymax >= ?
That single change dropped memory usage well below 1024 MB. More importantly, because each query now touches only 1 or 2 files, it became safe to reuse a warm DuckDB connection with enable_object_cache = true and memory_limit = '512MB'.
Benchmarks
I tested the relative-offset geocoder locally via Floci (a local AWS emulator) using a 20-record benchmark spanning Interstates, US Highways, state routes, mixed units, intercardinal directions, and two intentional negative test cases (a non-existent I-999 route and an unparseable string).
| Deployment | Configuration | Lambda RAM | Batch Size | Wall Time | Avg / Record |
|---|---|---|---|---|---|
:v14 |
Global type=segment/*, no object cache |
3008 MB (OOM at 2048 MB) | 3 | 57.2s | ~19.1s |
:v15 |
Bbox manifest (1-2 files), fresh DuckDB per record | 1024 MB | 20 | 113.8s | ~6.0s |
:v16 (Run 1) |
Bbox manifest + warm DuckDB + object cache (cold fill) | 1024 MB | 20 | 79.1s | ~4.2s |
:v16 (Run 2) |
Bbox manifest + warm DuckDB + cached footers | 1024 MB | 20 | 18.4s | ~0.97s |
Across the 20-record batch, all 18 valid records matched cleanly (bridging up to 7 carriageway gaps on a 20-mile US 50 offset in Nevada), and both negative cases returned clean Status: "U" responses with diagnostic errors. Cutting out the global glob and caching only the 1-2 active file footers delivered nearly a 20x per-record speedup while cutting Lambda memory by two-thirds.
Avoiding the Hidden Release-Day Out-Of-Memory (OOM)
There is one subtle operational trap with a bundled manifest: the day Overture publishes a new monthly release, a naive "always query latest" check will mismatch the bundled manifest, silently fall back to type=segment/*, and OOM-kill the 1024 MB container.
To prevent that, the Lambda follows three rules on cold start:
1. Check S3 first, fall back to bundled: Try loading manifests/overture_segment_manifest.json from the local lakehouse S3 bucket (~10 ms), falling back to the copy baked into /var/task.
2. Pin to the manifest's release: Always query the Overture release recorded in the loaded manifest so a new upstream release never triggers a global glob.
3. Warn on staleness: Compare the manifest's release against Overture's STAC catalog and log a warning when a newer release is available.
Updating to a new Overture release becomes a single script run that pushes a new 15 KB JSON file to S3, with no Docker rebuild required.
The Takeaway
GeoParquet and DuckDB Spatial make it practical to replace always-on spatial databases with 1024 MB Lambda functions, even against planetary-scale datasets like Overture Maps. The catch is that cloud-native formats still obey the laws of network I/O and metadata overhead. Pair Hilbert-sorted Parquet with a tiny file-level spatial manifest, keep your DuckDB connection warm, and you get fast serverless geospatial queries without maintaining a single database server.
Author: David G. Smith • Source: https://davidgsmith.net/thoughts/building-custom-geocoders-with-aws-lambda-duckdb-and-geoparquet.html
Related Thoughts
Perspectives sharing related architectures, models, and domain context.
CNG Forum 2026 Sessions Posted to YouTube
If like me you missed the Cloud-Native Geospatial (CNG) Forum 2026 in Snowbird, Utah this October, or if you were there...
Cloud-Native Map Tiles With No Drama
For a long time, running your own map service was a real chore. You didn't just need map data. You needed tile servers....
GeoAI Imagery Data Pipelines
The Earth observation community is living through a golden age of AI. Today, it's easier than ever to download a...