Cache-Aside Pattern diagram template

The application checks the cache first and loads from the database on a miss.

Cache-Aside Pattern architecture diagramOpen in ArchBoard

Builds a new scene in your browser. Your existing scenes are not touched.

About this design

Cache-aside, sometimes called lazy loading, puts the application in charge of the cache. On a read it asks the cache first; a hit returns immediately, and a miss loads the row from the database, stores it in the cache with a time to live and then returns it. On a write the application updates the database and either deletes or refreshes the cached entry, so the next read repopulates it. The pattern is simple and resilient because the cache can disappear and the system still works, only slower. It is a good fit for read-heavy data that tolerates brief staleness. Use the template to discuss choosing time to live values, race conditions when a stale value is written back after an update, stampedes on a popular key, and why deleting on write is usually safer than updating in place.

Diagram as text

This is the source of the diagram, in the ArchBoard diagram DSL. Paste it into Tools, Diagram from text to rebuild or change it.

title "Cache-aside"
direction LR
service app "Application"
app -[1. get]-> cache redis "Redis"
app -[2. on miss]-> db postgres "Database"
app -[3. set with TTL]-> redis

Related guides

More data and storage templates