SDI.
All Strategies
Application

Refresh-Ahead Cache

The cache proactively refreshes entries before they expire, ensuring that frequently accessed data is always served from cache with consistently low latency.

Refresh-ahead caching automatically reloads cache entries before their TTL expires, so that hot data is never served from the database. When a cached entry reaches a configurable refresh threshold (e.g., 80% of TTL elapsed), the cache triggers an asynchronous reload from the database. The current cached value continues to be served until the refresh completes. This eliminates the latency spike that occurs when a popular entry expires and must be reloaded synchronously.

Read/Write Pattern

Reads always go through the cache. When a read accesses an entry within its refresh window (near TTL expiry), the cache asynchronously reloads the entry from the database in the background while serving the current value. Writes use a separate strategy.

Consistency

Eventual consistency with bounded staleness. Entries may be stale by up to the refresh window duration. For frequently accessed keys, staleness is typically much shorter because the async refresh completes quickly after being triggered.

Failure Mode

If the background refresh fails, the cached entry continues to be served until its TTL expires, at which point it becomes a regular cache miss. If the database is slow, the refresh may not complete before TTL expiry, causing a miss. If the cache fails, all requests hit the database (same as read-through/cache-aside).

Likely Follow-Up Questions

  • How would you tune the refresh factor for a cache with 10-minute TTLs serving 50K requests per second?
  • What is the relationship between refresh-ahead and HTTP stale-while-revalidate?
  • How does refresh-ahead prevent thundering herd for hot keys but not cold keys?
  • When would refresh-ahead waste resources, and how would you detect that?
  • How would you implement refresh-ahead on top of Redis?

Source: editorial — Synthesized from standard distributed systems caching literature and production engineering best practices.

Command Palette

Search for a command to run...