Engineering

Building a Policy Engine That Evaluates 2M Rules Per Second

David Chen 20 June 2026 13 min read

Our conditional access engine evaluates hundreds of policy rules per authentication request across millions of concurrent users. Here's the architecture that makes it possible.

A conditional access policy is a small thing: some conditions, an effect, maybe a few exceptions. The difficulty is that a large tenant has hundreds of them, every authentication has to evaluate all of them, and the answer is needed in single-digit milliseconds.

Compile, do not interpret

The naive engine walks a tree of policy objects per request, allocating as it goes. Ours compiles each tenant's policy set into a flat decision structure once, at write time, and caches it. Evaluation then touches a contiguous array rather than chasing pointers through a hundred small objects.

This trades write latency for read latency, which is exactly the trade you want: policies change a few times a week and are evaluated a few thousand times a second.

Index by what discriminates

Most policies do not apply to most requests. Rather than evaluating every rule and discarding the misses, we index rules by their most selective condition — usually the application, sometimes the user group — and evaluate only the candidate set. In production this reduces the rules considered per request by well over an order of magnitude.

Short-circuit on deny

Deny beats allow, always. Once a deny matches, the remaining rules cannot change the outcome, so evaluation stops. Ordering the candidate set to put likely denies first turns the common blocked case into a handful of comparisons.

Make the expensive signals optional

Some conditions need data that is expensive to fetch: device posture, a risk score, a geo lookup. We evaluate the cheap conditions first and only resolve an expensive signal if a rule that needs it is still a candidate. A policy set that never mentions device posture never pays for a posture lookup.

Determinism is a feature

Two evaluations of the same request against the same policy set must produce the same result, or nobody can debug anything. That means no wall-clock dependence inside evaluation, no iteration over unordered collections, and a decision trace that records every rule considered and why it matched or did not.

The trace is what makes the engine supportable. When an administrator asks why a request was denied, the honest answer comes from replaying the recorded trace rather than from reasoning about the policy set by hand.

What we would do differently

We under-invested in the policy authoring experience for too long. A fast engine evaluating a policy set nobody fully understands is not a safe system. Simulation — "show me who this change would have blocked yesterday" — turned out to be more valuable to customers than another few microseconds of evaluation time.

#policy#architecture#performance

More in Engineering