01
Caching
Preventing the same response from being reproduced: cache layers stretching from the client to the database, cache-aside and write strategies, time-based, event-based, and version-based invalidation, key design carrying namespace and tenant separation, preventing the stampede effect with single-flight, HTTP validators, and measuring the hit ratio.
- 01 Cache Layers Measuring a read path that produces the same response over and over, and setting up client, edge, server, and database caches as a chain: how many requests each layer stops, the split between shared and private caches, and lowering the rate of requests that reach the origin.
- 02 Cache Strategies Comparing cache-aside, write-through, and write-behind on the same workload: the number of reads and writes reaching the origin, the hit ratio, the durability trade-off of write-behind, and the race between a miss and a write in cache-aside.
- 03 Invalidation Measuring time-based, event-based, and version-based invalidation on the same workload: the trade-off a lifetime sets up between origin reads and stale reads, the delay of an event consumer fed by an outbox, and the orphaned-entry cost of putting the version in the key.
- 04 Cache Key Design Demonstrating, by running them, two flaws of a hand-concatenated key — collision and tenant leak — and writing a function that generates a key from namespace, schema version, generation, tenant, and canonical criteria; measuring the effect of key cardinality on the hit ratio and on correctness.
- 05 Hot Key and Stampede Effect Measuring how a hundred concurrent requests pile onto the origin when a hot key's entry drops, and collapsing that to a single production with a single-flight lock; stale-while-revalidate zeroing out the wait, jittering the lifetime to prevent simultaneous expiry, and spreading a hot key across shards.
- 06 HTTP Caching The response carrying its own cache rules: ETag and Last-Modified validators producing a 304 on conditional requests, the body transfer dropping to zero, the validator changing when the resource changes, and choosing the public, private, max-age, and no-store directives, along with stale-while-revalidate, by resource type.
- 07 Cache Metrics Calculating the hit ratio and its effect on average response time: the curve the hit ratio traces as capacity grows, what the eviction count means, the per-namespace breakdown a single total ratio hides, the difference between byte hit ratio and request hit ratio, and the measured gain from removing low-repeat data from the cache.