Course contentsShow
← System Design
Lesson 1537 of 1,91937. Real-World System: URL ShortenerFree lesson

Hot Key Problem and Mitigation

Handle viral URLs that receive millions of requests by using local caches, CDN, and distributed cache warming.

Hot Key Problem and Mitigation

What You'll Learn

You'll learn how to handle viral URLs that become "hot keys"—receiving millions of requests that can overwhelm your URL shortener system—using local caches, CDN layers, and proactive cache warming.

The Hot Key Problem

When a URL goes viral (imagine a celebrity tweet or breaking news link), that single short URL can receive millions of redirect requests within minutes. This creates a hot key: one database or cache key accessed far more frequently than others.

Even with caching enabled, the problem persists:

  • A single cache server becomes overwhelmed handling the same key repeatedly
  • Cache server CPU and network bandwidth saturate
  • Other URLs suffer because resources are monopolized by one hot key

Mitigation Strategy: Multi-Layer Defense

Local Application Cache

Each redirect server maintains a small in-memory cache (e.g., LRU with 1000 entries). Hot URLs get cached directly in the application process, eliminating network calls entirely. Think of this as keeping your most-used tools right on your desk rather than walking to the supply closet.

CDN Layer

Deploy your redirect logic behind a Content Delivery Network. The CDN edge nodes cache popular URLs geographically close to users, distributing load across hundreds of points-of-presence worldwide instead of hammering your origin servers.

Proactive Cache Warming

When analytics detect a URL trending (requests spiking rapidly), preemptively push that URL to all cache nodes and CDN edges before demand peaks. This prevents the thundering herd of requests from creating a stampede.

Request Coalescing

Multiple simultaneous requests for the same hot key can be collapsed into one backend query, with all callers receiving the same result.

Key Takeaway: Hot keys are defeated through defense-in-depth: local caches eliminate network hops, CDNs distribute load geographically, and proactive warming prevents cache misses during viral events.