← All posts
BLOG · · Sebastien Le Touze

Country-only geo lookup, in a trie that fits in a megabyte

Walking away from city-level mmdb data, the compile-time OOM that forced our hand, and the trie format we ship instead.

1 MIN READ TUTORIAL

Until last week we shipped a full city-level MaxMind-format database. The compile step ran out of memory on our shared-hosting target. We had two options: pay for bigger compute, or shrink the data.

We shrank the data. We never needed city, ASN, or coordinates; the only geo decision LoginSeal makes is whether a session is inside the EEA, and at most which member state the user is in (for jurisdiction-aware age verification). That fits in a trie keyed on the first N bits of the IP and tagged with an ISO 3166-1 country code.

The numbers. The compiled trie is 740 KB unzipped, 230 KB gzipped. It lives in an APCu cache and is rebuilt by a nightly geo:refresh cron. A cold lookup walks the trie in microseconds; a warm lookup hits the in-process cache.

What we kept from the old design. The diagnostic tooling. geo:check now traces the trie walk and reports which prefix matched. That was non-negotiable for triaging customer complaints in production.

← Previous
Magic-link and QR cross-device sign-in, side by side
Next →
Magic links and the case for soft credentials
🇪🇺Operated in the European Union
🛡️Designed for GDPR
🧪In beta: anything not marked Next works today