KatInterview

Design a Distributed Cache for High-Traffic Static Assets

System DesignModel answer
MediumModel answerSystem Designcachingcdndistributed-systems

Last updated

Design a globally distributed caching layer that serves small static assets at hundreds of thousands of requests per second with sub-50ms latency and resilience to origin failures.

Design a Distributed Cache for High-Traffic Static Assets

Your platform serves large volumes of small static files — think icons, thumbnails, and UI asset images — to users around the world. The files are small (typically under 25 KB each), read far more often than they are written, and must be retrievable with minimal latency regardless of where the user is located.

Functional Requirements

  • GET /asset/{id} — retrieve an asset by ID.
  • PUT /asset/{id} — upload or replace an asset; the previous cached version must no longer be served after an update.
  • The system should support versioning so that clients pinning a specific version can continue doing so, while other clients always receive the latest.

Non-Functional Requirements

  • Latency: p99 response time under 50 ms for globally distributed users.
  • Availability: the system must keep serving assets even if the origin data store experiences intermittent outages.
  • Burst handling: popular assets must not cause cascading failures when their cache entries expire or are invalidated simultaneously.

What to Cover

  • Cache topology: how many tiers, where they sit, and why.
  • Invalidation strategy: how an update propagates globally while keeping the system eventually consistent.
  • Degraded-mode behavior: what happens when the origin is unreachable, and what staleness guarantees you offer.
  • Hot-key problem: how the design prevents a single wildly popular asset from overwhelming any layer.

Expected Output

Describe the end-to-end architecture and data flow for both reads and writes. Discuss the trade-offs in your consistency model. Explain how the system behaves during a regional failure and during an origin-side outage. Numbers and sizing estimates are expected.

Hints

Hint 1

Start by estimating the working set size. If the hot 1% of assets drives 90% of reads, does that hot set fit in memory? Your answer determines whether a memory-only regional tier is feasible and what capacity to provision there.

Hint 2

Think about what makes cache invalidation hard at global scale: you have many edge nodes, invalidation events can arrive out of order, and a TTL safety net is the last line of defense. Versioned, immutable URLs sidestep most of this — sketch out how that changes the write path.

Hint 3

The thundering herd is not one problem but several: simultaneous expiry of related keys, a flood of misses during a purge, and a single Redis shard melting under hot-key traffic. Walk through each scenario and name a concrete mitigation for each one.