Lesson 2 of 3
Caches and partition keys
8 min
A cache stores an answer so you do not recompute it. The cost is staleness. A ten-minute price cache is a decision that the price may be wrong for ten minutes. If the merchant changes the price and buyers must see it now, the write has to invalidate that cache. A longer TTL makes the bug last longer. A CDN does not fix a stale value you never expire.
Partitioning splits data so no single machine takes every write. The key decides who is busy. Sharding orders by customer id looks fair until one customer is 40% of orders. That customer’s shard is hot, and hiring more shards does not move their writes.
Example
A SaaS product caches each workspace’s plan for an hour. Support upgrades a customer who is blocked on a feature. The feature stays locked until the hour ends. The upgrade handler should delete the cache key for that workspace, not wait for the TTL.
Practice
Why can a “fair” customer-id shard still melt one machine?