Shared and private parts
Cache only the part of a response that is the same for every caller. The product body is shared, so 90 percent or more of body reads can hit the cache. Add the private header after the cache, never inside it.
See it on the board
The same traffic runs on two boards. The simulator measured both when this page was built.
| Measure | Goal | Whole page in the shared cache | Body cached, header added after |
|---|---|---|---|
| Data mismatches | none | 299,824 Fail | 0 Pass |
| Hit ratio | at least 90% | 99.951% Pass | 99.951% Pass |
| p99 latency | under 150 ms | 74 ms Pass | 75 ms Pass |
| Monthly cost | 530 USD/mo | 562 USD/mo | |
| Error rate | 0% | 0% |
Key numbers
| Number | Value |
|---|---|
| Edge cache read, median | 0.1 ms |
| Reads per second, one edge cache | 100,000 ops/s |
| Edge function start time, cold | 90 s |
Shared body cached · body hit ratio 90% · 10 of 100 reads reach the origin
How it works
A page often mixes two kinds of data. The product body is the same for everyone. The header shows the name of the signed-in user. If a shared cache stores the whole page, it can return the header of one caller to another caller. That is a data leak, and no hit ratio can pay for it.
The safe answer looks like a loss: do not cache the page at all. Then every read goes to the origin, and p99 rises with the load.
Split the response instead. The cache holds the shared body under one key for all callers. A small function runs in front of the cache. It asks the cache for the body, adds the private header for this caller, and sends the page. The private data never enters the shared cache.
In the mini board the naive path sends callers straight to the CDN, and the personal data can mix between callers. With the function in front, there are 0 data mismatches and at least 90 percent of body reads hit the cache.
The function adds a hop and some CPU. Keep it small, and keep a warm instance ready so a cold start does not delay the first reads.
In the levels you separate the shared part from the private part and keep the hit ratio high.