Skip to content
About
Main content
Query Engines

Caching

What happens when we deliberately keep a second copy of data that no protocol forces to be correct?

Who this mechanism is for: a developer who writes code, calls APIs, knows basic SQL and has probably put a (such as Redis or Memcached) in front of a database at least once. You do not need any database-internals knowledge. Every technical term is explained the first time it appears, and again in the glossary at the end. This mechanism shows that a cache is not "a faster place to keep data". It is a second copy with its own mathematics, its own failure modes and its own hidden costs.

The story we will follow

Ifeoma Okafor is a backend engineer at Dawnpost, an online newspaper. Dawnpost publishes about 400 articles a day and serves about 20 million page views a day. Articles live in a Postgres database. In front of it sits a cache (the "article cache"), and in front of that a CDN (a network of servers that keep copies of web pages close to readers). Behind the newsroom is a second system: an analytics warehouse. Reader events are stored as files (a column-oriented file format) in cloud , and editors run SQL dashboards over them. Her lead, Mateus Silva, reviews every design.

Over one busy season Ifeoma will meet six problems, one at the start of each article below. Each problem looks like a bug: a stale headline, a cache that does nothing when it is doubled, a dashboard that was fast last week, a database that falls over. Each one is actually a consequence of arithmetic about caches. At the end of each article we go back to Ifeoma and solve her problem with the mechanisms of that article.

This is the main idea of this whole mechanism:

How this mechanism is organized

After that: a summary, hands-on labs, interview questions and a glossary.

One request: do not skip the formulas. They are short, and each one replaces an experiment you would otherwise run on production.

What do I do, and what does each option cost?

Can I see it myself?

Can I reason about it under questioning?

Trade-offs

The tensions this mechanism takes a position on. Each recurs across mechanisms.

Show all 11 trade-offs
Recurring principles

Ideas this mechanism meets that keep coming back, mechanism after mechanism.

Show all 12 principles