The interview problem

Practice prompt

Limit each signed-in viewer to three admissions of a campaign in a rolling 24-hour window across devices. Ad requests can race, confirmations can arrive late, and regions can become disconnected. Design the serving check and explain what the cap actually guarantees.

Original worked adaptation of a second-hand Netflix L4 interview report labeled August 2026, posted August 6, 2026. The report describes frequency capping, but the precise numbers and contract here are invented. Not company-confirmed. Reviewed September 26, 2026.

Quick answer

Ad frequency capping limits how many qualifying ad events a viewer can receive within a defined window. Specify whether the event is admission, delivery or verified impression, and atomically check and consume capacity for that event. A counter checked separately from its update can overserve concurrent requests.

1. Define the event being capped

Ask whether an exposure means selection, response delivery, playback start or viewable impression. These events are different. An admission service controls permission to serve; it cannot prove that a disconnected device displayed an ad at a particular instant. For the baseline, cap admitted serving decisions. Separately record confirmed impressions for analytics. This conservative contract may suppress an ad that was admitted but never shown.

Assume a stable authenticated viewer ID, one campaign cap and a rolling window measured by authoritative server time. Anonymous browsers cannot reliably be unified into one person without a separate identity policy. Do not call a cookie a person. Spend 5 interview minutes on semantics, 10 on atomic admission, 10 on scaling, 10 on regional failure and 10 on late events and trade-offs.

2. Make check-and-consume one operation

The ad selector proposes a candidate campaign and calls POST /cap-admissions with viewer ID, campaign ID, policy version and stable decision ID. The cap service routes that viewer to an authoritative shard. In one serialized operation, it deduplicates the decision ID, discards admissions outside the current window, checks the remaining count and inserts the new admission if capacity remains. It returns an allow/deny decision with policy and admission identity.

Keep the decision ledger and window state consistent within the same transaction or atomic script. A separate read followed by an increment permits two requests to consume the last slot. Serialization failures need bounded retries; do not turn every timeout into a fresh decision ID. A repeated decision returns its original result while its deduplication record remains valid.

Logical flow: candidate selection → viewer shard → atomic admission ledger → ad response → asynchronous impression events. Events reconcile delivery outcomes but do not retroactively rewrite whether the original admission was allowed. A missing acknowledgement is an unknown outcome; retry the same decision ID or serve a fallback that does not require this campaign's cap.

3. Choose an exact or approximate window explicitly

For a small cap, store the at-most-three accepted timestamps per viewer/campaign plus deduplication records. Prune entries at or before t − 24 hours when the contract's active interval is (t − 24 hours, t]. Define that boundary consistently. Use authoritative time and guard against clock rollback; wall-clock jumps require an explicit operational policy.

A fixed daily counter is cheaper but is not a rolling window: three admissions just before midnight and three just after can occur seconds apart. Bucketed sliding counters approximate a rolling count unless they preserve sufficient detail at the boundary. This approximation may be acceptable for a soft advertising preference but must not be described as an exact hard cap.

If the policy adds campaign, advertiser and total-ad caps together, all relevant checks must succeed before any are consumed. Co-locating one viewer's scope keys permits a single transaction. Otherwise a distributed reservation protocol or conservative capacity allocation is needed. An atomic operation on one key does not make several independently sharded counters atomic.

4. Estimate state and request load

Assume 20 million active viewers each interact with ten campaigns during the retained window: 200 million active viewer/campaign pairs. At an illustrative 80 bytes of compact window state per pair, raw state is 16 GB. Three copies make 48 GB before indexes, allocator overhead, deduplication, log storage and safety headroom. Measure actual object overhead rather than treating this lower-bound estimate as a deployment size.

At 100,000 serving decisions per second and one checked candidate per decision, the service handles 100,000 atomic checks per second. Evaluating five candidate campaigns independently multiplies the work to 500,000 checks per second. Batch candidate lookup and consume only the selected candidate's capacity, while retaining an atomic final check. Never reserve five candidates permanently for one ad slot.

If every decision, including denials, retains a 32-byte deduplication record for 24 hours at 100,000 requests/second, the raw ledger reaches 8.64 billion records or 276.48 GB before replication and overhead. Under the 200-million-pair, three-admission contract, accepted admissions alone are bounded by 600 million per window, or 19.2 GB at that record size. Denial retention and retry traffic can therefore dominate storage; define their retention separately without allowing replay of expired decisions to create unintended new admissions.

5. Choose failure behavior before adding replicas

For a hard global cap, route a viewer to one fenced writer. During an ambiguous partition, fail closed for the capped campaign or serve a suitable uncapped fallback. A stale replica can allow an extra exposure even when its local increment is atomic. Redis transactions provide local execution guarantees; durability and failover behavior need their own design. A lost acknowledged admission cannot safely be treated as unused capacity.

To reduce cross-region latency, allocate disjoint admission rights whose total never exceeds remaining capacity. For a cap of three, giving two rights to one region and one to another preserves the bound but can strand capacity. Transfers must revoke old ownership before granting it elsewhere; a partition cannot authorize both copies to spend the same right. For rolling windows, rights also need a sound expiry and replenishment model, making this substantially more complex than a counter.

For a soft cap, asynchronous regional counters may be acceptable with a measured overrun budget. State that trade-off clearly. Do not claim exact enforcement and independent regional availability at the same time when every region can spend the full cap.

6. Handle late and duplicate impressions honestly

Deduplicate impression events by an event/admission identity and preserve event time separately from ingestion time. Confirmations can validate the delivery funnel and reveal duplicate playback, but a late event cannot undo an already displayed ad. Alert on admissions versus observed impressions and investigate discrepancies by client version and region.

If the product insists on capping confirmed displays rather than admissions, provisional reservations can reduce underdelivery, but reclaiming an unconfirmed reservation is unsafe when the device might still display it later. A bounded display token plus clients that enforce expiry offers a more explicit protocol; it still requires assumptions about client clocks, playback and trust. The simple baseline deliberately retains the admission for the full window, even when confirmation is missing.

Changing a cap from three to two should deny new admissions until the retained count falls below two. It cannot erase past exposures. Preserve sufficient history when lengthening the window, or defer the new policy until an explicitly documented warmup period completes.

7. Defend the implementation

Foundation: show the race between two check-then-increment requests. Senior: handle a timeout after a committed admission and simultaneous campaign/advertiser caps. Staff: defend regional failure behavior and explain the admission-versus-display limitation to product stakeholders.

Score 0–2 each for event semantics, atomicity, window correctness, retry handling and regional guarantees. Two points require a concrete mechanism and acknowledged limitation. Compare with API rate limiting: the counter mechanics overlap, but exposure identity and delayed playback create a different product contract.

What happens when the cap is lowered?

Define the active window as (t − 24 hours, t], so an event exactly 24 hours old is excluded. A viewer has three qualifying admissions still in that window under cap 3. The policy changes to cap 2. Keep the existing admission history and deny further admissions until the active count is below two; the new policy cannot undo previously admitted ads.

Resetting the counter on every policy revision would allow two more immediately and violate a policy intended to cover existing history. Instead, apply the new threshold to the same event ledger, and serialize the policy revision used by the admission decision with its capacity consumption. If the business instead intends a fresh campaign window, make that a different, explicit policy.

Specify how retries crossing the policy change behave: a duplicate of a previously accepted operation returns its stored result rather than consuming another slot. Retain that idempotency result for the documented retry horizon, independent of the rolling count’s expiry.

Original worked follow-up, reviewed October 7, 2026. Reference: Redis: transactions.

Sources and next steps

Architecture, assumptions and arithmetic are original practice material, not a description of Netflix's production implementation.

Continue your preparation

Choose a connected learning path or browse more System design questions. Read our editorial method and attribution policy.