Engineering

How We Achieve 18ms P99 Auth Latency at 47M+ Identities

David Chen 14 July 2026 15 min read

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.

Stop asking the database

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.

Cache the shape, not the answer

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.

Move validation to the edge

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.

Measure the tail, not the mean

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.

The lessons that generalise

  • Every network hop on the auth path is a latency budget you cannot get back.
  • Invalidate on write; expiring on a timer trades correctness for a cache hit rate you did not need.
  • Design revocation before you design caching — retrofitting it is how you end up back at the database.
  • Load test with a realistic identity distribution. Uniform random user IDs produce a cache hit rate you will never see in production.

None of this required exotic infrastructure. It required removing work from the hot path, one round trip at a time.

#performance#architecture#scaling

More in Engineering