← Two Hard Things: caching bugs

Two Hard Things: caching bugs · Intro

Don't add a cache. Yet.

· by Tony Tang

Every bug in this series exists because someone added a cache, and often the slow query just needed an index: a third of a second became 27 microseconds. Measure first: EXPLAIN, add the index, fix the N+1. Still slow? Cache it, with a TTL, a size limit, jitter, and a key that includes everything.

Comment below: What's the worst caching bug you've ever shipped?

Two Hard Things: a series on the caching bugs you already ship, and how to fix them. "There are only two hard things in computer science: cache invalidation and naming things." (Phil Karlton) All code is real TypeScript on Node, typechecked before it went on screen, and every claim was reproduced against real Redis and Postgres.

More from this series