A deep dive into our distributed token validation architecture, edge caching strategy, and the lessons learned scaling from 1M to 47M identities without touching auth latency.
Authentication is on the critical path of every request your users make. A hundred milliseconds added here is a hundred milliseconds added to every page load in every application you protect. When we started, our P99 was 140ms. Today it is 18ms, and we grew from one million to forty-seven million identities in between.
This is what actually mattered, in rough order of impact.
The first version validated every token by loading the session, the user, and their effective permissions from Postgres. That is three round trips before you can answer yes or no. The fix is unglamorous: put everything the validator needs inside the token, sign it, and validate signatures in process.
The objection is obvious — revocation. We handle it with a small, aggressively cached denylist of revoked token families rather than an allowlist of valid sessions. The denylist is tiny, changes rarely, and fits comfortably in memory at every edge.
Permission sets change far less often than they are read. We cache the entitlement snapshot for an organization — plan features, seat state, role-to-permission mapping — and invalidate it on write rather than expiring it on a timer. Reads are then a map lookup.
The subtlety is that invalidation has to be correct on every write path, including the ones nobody thinks about: SCIM deprovisioning, subscription lapse, an admin editing a custom role. We publish a single domain event for each and let the cache subscribe, instead of scattering cache.del() calls through the codebase.
Once validation is CPU-only, it can run anywhere. Pushing it to regional points of presence removed the transatlantic round trip that dominated our European P99. Signing keys are distributed with short lifetimes and rotated automatically; an edge node that cannot refresh its keys fails closed.
Our mean latency was healthy long before our P99 was. Averages hide exactly the requests your users complain about. We alert on P99 and P99.9 per region, and we treat a tail regression as an incident even when the mean is flat.
None of this required exotic infrastructure. It required removing work from the hot path, one round trip at a time.