The interview problem
Design caching for a public product catalog served through two hundred edge locations. Descriptions change frequently, and an emergency takedown must stop future delivery through controlled caches. Explain cache identity, revalidation, purge acknowledgment and what happens when an old origin response arrives after a purge.
Original system-design practice, not a reported company interview. All loads and deadlines are hypothetical. Primary specification retrieved September 27, 2026; interview date not applicable.
1. Separate freshness from revocation
For ordinary edits, assume a thirty-second stale-content budget. For a takedown, require controlled serving locations to stop starting new responses for the revoked resource after acknowledging the operation. Content already downloaded by a browser cannot be recalled by an edge purge. If the product instead requires a global deadline, define what happens to edges that cannot receive the revocation.
Use immutable URLs for versioned assets and a mutable catalog endpoint that selects the current version. A new immutable URL prevents old bytes from masquerading as the new version, but changing a link does not revoke access to the old URL. A separate deny decision is needed when old content must no longer be served.
Keep personalized responses outside the public catalog cache unless a separately verified design isolates them. The product page and a user's cart are different cacheability decisions. Avoid making checkout trust a cached displayed price as the authority for a purchase.
2. Use a publication path and a serving path
catalog update → committed revision + publication outbox
↓
purge/revocation control stream
↓
edge and shield generation watermarks
viewer → edge identity + policy check → cache lookup
↓ miss/revalidate
regional shield → origin
↓
conditional cache installationCommit the content revision before publishing the invalidation event. An outbox bridges database commit and event delivery so a process crash cannot silently leave a committed edit without its event. Events have resource ID, generation, scope and operation ID. Repeated events are safe, and older generations cannot undo newer ones.
The cache identity includes host, path, relevant query fields and representation variants such as language or encoding. Define canonicalization consistently with the origin. Dropping a meaningful query field can merge different pages; retaining arbitrary tracking fields can explode cardinality. Invalidation by product ID must cover every declared variant, not only the most common URL.
Use a shield to coalesce fills across edges. Purges reach both layers, or edges can immediately refill from stale shield content. A warm cache can still be wrong: measure the served content revision as well as hit rate.
3. Keep HTTP semantics distinct from the purge protocol
RFC 9111 defines freshness, validation and cache directives. Unqualified response no-cache permits storage but requires successful validation before reuse; no-store forbids storage under its stated rules. A cache's freshness calculation accounts for response age, rather than restarting the full lifetime at every hop. HTTP invalidation along a write's path is not a global purge broadcast.
Use a representation validator to ask whether cached bytes remain valid. A successful unchanged validation can avoid transferring a full body, but still consumes origin work. Ensure a validator identifies the intended representation and that the origin's validation path sees an adequately current revision. A lagging origin replica can otherwise incorrectly reaffirm old content.
The generation and acknowledgment protocol below is an original application design layered around controlled caches. It is not behavior guaranteed by ordinary HTTP headers or by every CDN vendor. If using a managed CDN, verify its documented purge scope, completion semantics and handling of in-flight fills before claiming these guarantees.
4. Work through the stale-fill race
At t=0, edge E starts fetching catalog revision 7. At t=1, revision 8 commits. At t=2, E receives a purge for minimum acceptable revision 8 and evicts its cached entry. At t=3, the old fetch returns revision 7. If E blindly inserts that response, the purge has been undone.
Maintain a resource generation watermark independently of the cached body. A fill records its starting generation and returns a content revision. Cache installation and response eligibility check the current watermark atomically: a result from an obsolete generation or below the minimum acceptable content revision is discarded. A takedown also installs an explicit deny state independent of content revision; a newer revision alone does not bypass that deny. The waiting request must retry within its deadline or receive the defined error; it must not receive the rejected bytes simply because they were not cached.
Checking before a network call and writing afterward is insufficient. A purge can occur between the check and publication. Coalesced waiters need the same response eligibility rule. A revalidation response arriving after a purge cannot revive the old object merely by renewing its timestamp.
For an ordinary edit, keep the watermark long enough to cover all old in-flight work, or make a bounded worker lifetime part of the protocol. For a takedown, retain the deny state while the resource remains revoked; expiry of old workers is not permission to serve it again. Evicting a tombstone while an old worker can still publish reopens the race. On edge restart, load current revocation state before serving or fail closed for affected resources. A cache empty of bodies is not necessarily safe if its policy state is stale.
5. Define what a purge acknowledgment proves
A coordinator tracks the intended serving membership and each node's applied generation. A node acknowledges only after the watermark is installed and earlier fills can no longer start an eligible response. The coordinator reports per-region progress and unresolved locations. “Request queued” is not “applied everywhere.”
Membership changes matter: a new edge must bootstrap the current revocation snapshot and subsequent events before joining service. A disconnected edge cannot be counted as successful merely because it stopped reporting. For strict revocation, use expiring serving authorization that requires fresh policy or remove the stale edge from eligible routing, while recognizing that cached DNS and existing connections may delay traffic removal.
A serving lease gives a bounded stale-policy interval only under explicit clock and enforcement assumptions. It trades availability for revocation. State the interval and stop serving when the lease expires; do not promise instantaneous global removal through an unreliable network. Ordinary catalog updates can use weaker freshness rules than emergency takedowns.
Browser caches and third-party caches are outside the custom acknowledgment membership. Select browser caching policy before publishing content based on the needed revocability. A later header change cannot force every previously cached response to be fetched again immediately.
6. Calculate the cost of invalidation
At 100,000 viewer requests/s and a 99% edge hit rate, 1,000 requests/s miss the edge before shield effects. If a broad purge temporarily lowers hit rate to 90%, misses rise to 10,000/s: a tenfold increase, not a nine-percent increase in origin traffic. Actual origin load depends on shield hits, coalescing, distinct keys and revalidation.
Suppose each of two hundred edges requests each of one hundred newly invalidated hot keys once during a refill interval. That is 20,000 edge fills under a one-fill-per-key-per-edge assumption. Five shields with perfect per-key coalescing and one fetch each would send 500 origin fills, forty times fewer. This is an idealized bound for that workload, not a guarantee under retries, eviction or staggered refreshes.
If each representation is 200 KB decimal, 500 full origin fills transfer 100 MB; 20,000 transfer 4 GB. Validators can reduce payload but do not eliminate the validation request load. Enforce bounded fill concurrency, coalescing and per-origin budgets before initiating a large purge.
Prefer precise resource tags and staged ordinary invalidation when allowed. Do not stage an emergency takedown in a way that violates its required stopping time. Warming new immutable assets before switching the mutable pointer can reduce ordinary edit bursts without serving revoked content.
7. Test degradation without breaking the promise
For an ordinary description edit, the product may allow stale delivery within a declared budget when the origin is unavailable, provided the selected HTTP policy permits it. For a revoked item, serving stale is not a fallback. Return an appropriate unavailable or removed response and make sure a cached error does not outlive its own intended policy.
Test duplicate and reordered purges, a delayed old fill, an old validation response, shield lag, an edge restarting from an old snapshot and a new node joining during a purge. Assert response eligibility, not just eventual eviction. Include an already-streaming response in the contract: acknowledgment may stop new responses without retracting bytes already transmitted.
Monitor watermark lag, pending acknowledgments, discarded stale fills, viewer errors, origin concurrency and revision mismatches. Sampled probes provide evidence from sampled paths, not proof every edge is updated. Preserve operation receipts and the membership definition needed to audit the actual completion claim.
Protect purge APIs with resource-scoped authorization and audit trails. An accidental wildcard purge can overload origin even if no content is compromised. Test cache-key normalization against routing behavior so an attacker cannot make one representation populate another resource's entry.
8. Trade-offs and follow-ups
Short freshness lifetimes reduce reliance on push invalidation but increase validation traffic. Immutable keys simplify content identity but retain reachable old objects. Durable watermarks prevent resurrection while adding control-state storage and bootstrap complexity. Strict policy freshness can interrupt service during partitions; a looser policy preserves availability with a stated stale-content risk.
Follow-ups: How would a million product tags affect watermark storage? What if one URL depends on several catalog records? How do you purge language variants without flushing everything? What if the CDN cannot fence in-flight fills? How does a signed URL interact with cached authorization? Which guarantee can be made for browsers that already downloaded the page?
9. Self-review rubric
- Separate ordinary freshness, controlled-cache revocation and already delivered content.
- Define cache keys and every affected variant.
- Order content publication and durable invalidation delivery.
- Prevent old fills and validations from reviving purged content.
- Define membership, acknowledgments and disconnected-edge behavior.
- Calculate miss amplification and shield/coalescing assumptions.
- Test response eligibility and preserve realistic availability trade-offs.
Sources and related practice
RFC 9111: HTTP Caching, June 2022. Background for HTTP freshness, validation and invalidation scope. The generation-fencing protocol and calculations here are original application design, not a CDN vendor guarantee.
Continue with distributed caches, live-event delivery and leases and fencing.
Continue your preparation
Choose a connected learning path or browse more System design questions. Read our editorial method and attribution policy.