Caching layers: what to get right first
Every audit we run turns up some version of this. If you only fix one thing about caching layers this quarter, make it the first item below.
Most systems fail at the seams rather than inside any one component. It rarely shows up as a line item, which is exactly why it slips.
Start here
Caching is easy until something has to be invalidated. There is a version of this that is over-engineered, and it is worth avoiding. The version that survives contact with a real deadline is the simple one.
Then this
Cache close to where the cost is, not everywhere. Where this goes wrong is almost never a lack of knowledge. Anything you cannot measure here, you are deciding by taste, which is fine as long as everyone knows it.
Eventually
A stale cache with no expiry is a future incident. Small and consistent beats large and occasional here. Assume whoever inherits this will have half your context and none of your patience.
The short version
The right architecture for a team of three is the wrong one for a team of thirty, and vice versa. Three things worth confirming about caching layers before you move on:
- Someone can say what the current setup is without going to look
- Caching is easy until something has to be invalidated — and you know whether that is true here
- There is a way to tell whether the last change to this helped
If you are not sure where your systems currently stand on this, it takes us about an hour to find out.