</> MAANG.io
system design · 301

Advanced

Master system design interviews with scalable architecture patterns, distributed systems, and real-world design challenges.

0/480 solved 0% complete

Section 7: The Microsecond That Must Agree Everywhere - Deep Dive: Evaluation Engine & Deterministic Bucketing

Executive Summary: This section opens the engine that runs 50M times a second across the fleet. The rule pipeline is compiled once per snapshot, stops at the first match, and never throws. Bucketing comes down to one exact line, hash(flagSalt + ":" + unitId) mod 10,000, compared against integer thresholds. That line is why Dana, at bucket 1,234, is out at 5%, in at 25%, and never flips back. Then come salts, units, cross-language determinism, and why random() and assignment tables lose.

The interviewer taps the "Server SDK" box. "You said evaluation never leaves the process. Walk me through isEnabled, and convince me today's 25% still includes yesterday's 5%." If the engine is wrong, every rollout plan is theatre.

The Evaluation Pipeline

You: "There are two phases. The expensive one runs once, when a snapshot arrives. The cheap one runs on every call."

When mail-compose applies a snapshot, the SDK compiles each flag's ordered rules into a flat array of predicates. Segment lists become hash sets, so checking whether Contoso is in the 50,000-tenant list (about 800 KB) is an O(1) lookup. Semver constraints and regexes are parsed once, and percentages become integer thresholds. The compiled snapshot is immutable and is read through one atomic pointer load, with no locks. Section 8 covers how that pointer gets swapped.

Evaluation pipeline for isEnabled: return the code default if the flag is missing from the snapshot, then check the kill override, individual targets, segment rules such as no-preview or Ring 0, and the unit attribute before bucketing and comparing to the threshold

Two rules keep this safe. First, a missing attribute means the rule doesn't match, never that something went wrong. A background job with no tenantId falls past the Contoso rule. A call with no userId can't be bucketed, so it gets the default variation. Second, the engine never throws. An unknown key or a type mismatch returns the caller's code default (D10) and bumps an error counter in the per-minute telemetry (D9). A flag library that can crash its caller has turned itself into a dependency, which is exactly what D1 rules out.

Interviewer: "Why does kill beat individual targets?"

You: "At 14:07, off has to mean off for everyone, with no exceptions to reason about. Kill is the top-priority rule by definition (D5)."

Quick check before moving on:

Sign in to continue reading

The rest of this lesson is available with a free account. Signing in with Google or Microsoft is free.

Sign in to read the full lesson

Sign in to MAANG.io

Use your Google or Microsoft account — no password to remember.

Continue with Google Continue with Microsoft

Please accept the terms above to continue.