← All patterns
Caching · Architecture pattern

Cache-aside

Load repeated reads into a cache while keeping SQL authoritative.

The problem

A popular product page repeatedly reads the same records. Database work grows even though most readers need the same data.

When it fits

Repeated reads tolerate a declared freshness window and cache misses can still reach the source.

The whole architecture

Architecture diagram

Read and write paths share authoritative SQL while the application manages cached copies.

Blue arrows are application calls. Cache has no onward request path to SQL.

100%

Scroll to pan. Select a component for its role.

cache aside architectureRead and write paths share authoritative SQL while the application manages cached copies. Blue arrows are application calls. Cache has no onward request path to SQL.Application-owned cache-aside logicData dependenciesclients → read: readclients → write: writeread → cache: lookup / fillread → sql: miss → sourcewrite → sql: commit firstwrite → cache: invalidate after commitreadwritelookup / fillmiss → sourcecommit firstinvalidate after commitClients call an application API rather than an authoritative database.ClientsRead or change dataOn a miss, this API calls SQL separately and fills the cache.Read APICache lookup / fillA successful source write precedes cache invalidation.Write APICommit then invalidateCopies can become stale; expiration and invalidation need an explicit freshness policy.CacheExpiring keyed copiesThe source of truth remains available to the application on a cache miss.Authoritative SQLBusiness recordsCache invalidation races and miss stampedes need separate handling.Freshness policyTTL, invalidation races and cold-cache load

Select a component, or focus it and press Enter, to read its role.

Walk through the design

Follow one operation

Select a step to highlight its participants. This conceptual walkthrough is separate from challenge scoring.

Arrows show the conceptual relationships used by this walkthrough.

ClientActive in this stepAppActive in this stepCacheActive in this stepSQLWaiting
Step 1 of 3

Look up the key

Client asks App for a product. App reads Cache first.

Trade-offs to make explicit

  • Hits save source reads; misses add a cache lookup before the source lookup.
  • Expiration and invalidation bound some stale data but do not make concurrent readers strongly consistent.

Failure modes to plan for

  • A cold cache or synchronized expiry can overwhelm the database.
  • A reader can repopulate an old value after a writer invalidates it. Consider versioning and request coalescing.
Before you build

Explain your decision

What freshness contract would you declare for a product price, and how would you prevent a cache-miss stampede?

Use Plan & estimate inside practice to record your assumptions and trade-offs.

Connect concept to practice

Related challenges

Browse challenges →

These links open the original challenges. Existing round unlocks, completions and points apply.

Rescue the overloaded API

Practice app/cache/SQL capacity. Invalidation races are discussed here, not scored by that workload.

Open challenge →

The great ticket rush

Use cache-aside for eligible reads while keeping reservation writes authoritative.

Open challenge →

Further reading

Microsoft · Cache-aside ↗

Original PractiseGrid explanations and conceptual diagrams, with primary references for further study. Dedicated scored exercises can be added as coverage grows.