---
title: "Case study: Update deployed. Cache empty. · Alexander Hirschfeld"
description: "Anonymised case study: a page cache inside the container was empty after every Kubernetes update. A distributed cache in Rust holds the hit rate through rollouts and scale-ups."
url: https://www.alexander-hirschfeld.de/en/case-studies/cache-under-load
language: en
---

[All case studies](https://www.alexander-hirschfeld.de/en/case-studies)

Case study, personal project

# Update deployed. _Cache empty._

A PHP application kept its page cache as files inside the container. After every Kubernetes update those files were gone, and every new pod from the autoscaler started empty. Both hit the application under full load. A distributed cache in Rust solves this: in the same rollout the application stays well below its limit.

Hit rate during an update, 1,200 requests per second

Test cluster, median of three runs. The axis starts at 50 %.

- Project

  Distributed HTTP cache in front of a PHP application, developed with AI

- Technology

  Rust on Pingora, Kubernetes, three instances that actively sync

- Size

  About 15,900 lines of Rust, June to September 2026

- Measurement

  Load test in a local Kubernetes cluster, starting point reconstructed

## At a glance

1. ### Day to day, it runs.

   The file cache answers 99.3 % of requests. That leaves the application plenty of headroom.

2. ### During an update, it doesn’t.

   Every new container starts empty. At 1,200 requests per second the application hits its limit, p99 climbs to 6.6 s.

3. ### Now it stays warm.

   The cache lives apart from the application and keeps itself in sync. In the same test the hit rate stays at 95 % or above and p99 at 252 ms.

## The cache lived _in the container._

A finished page was written as a file to the container’s file system. While the container was running, that was fast enough. The trouble came with every new container, on deployment and on scale-up.

What an update does to the file cache

Before the update

- Container Files present
- Container Files present
- Container Files present

After the update

- Container Empty
- Container Empty
- Container Empty

A container’s file system only lives as long as the container. A new image means new containers, and so new, empty file systems.

- ### Gone on restart

  Kubernetes replaces every container during an update. Even a plain restart after a crash starts from zero.

- ### Cold when it matters most

  When load rises, the autoscaler starts new pods. They are meant to relieve the system, but they arrive empty and render everything themselves first.

- ### Each on its own

  Three containers mean three separate caches. What container A has already rendered, container B renders again itself.

- ### No protection from a rush

  When many requests hit a cold page at once, every free PHP process renders it for itself. Every hit occupies a PHP process as well.

## A few percent _decide everything._

A cache hit costs about one millisecond in my rig, a render costs 250. That is why the hit rate almost single-handedly sets how much work reaches the application. Try it.

When does the application overflow?

Requests per second **1,200** Hit rate **98 %**

**24** renders per second needed

The application can handle this. At this load it only gets tight below a 84 % hit rate.

Calculation: requests × (1 − hit rate). The capacity of 192 renders per second comes from the rig: three pods × 16 PHP processes ÷ 0.25 s per page.

At 1,200 requests per second the application copes down to an 84 % hit rate. Below that the queue grows, and it keeps growing every second. Since a waiting process helps nobody else, the system tips over abruptly. One moment everything is smooth, the next everyone waits several seconds.

## How this _was measured._

To keep the numbers comparable, both variants run against the same application in the same cluster under the same load.

| Cluster           | Kubernetes 1.33 (kind) with one node on a machine with 16 cores and 32 threads                                                                                        |
| ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Application       | Three pods with Apache and PHP-FPM, 16 PHP processes each. A page takes 250 ms and is about 18 KB. That gives 192 renders per second.                                 |
| Starting point    | File cache in the container as described, valid for one hour, with no coordination between pods                                                                       |
| Distributed cache | Three pods with 2 CPU each in front of the application, warm-up up to 30 s, sync every 10 s, purges acknowledged on two pods                                          |
| Load              | Open-loop load at a fixed rate, 2,000 pages with a Zipf distribution (s = 1.1). Response time counts from the scheduled start, after 10 s a request counts as failed. |
| Update            | kubectl rollout restart under load. The default strategy replaces one pod after another.                                                                              |
| Repetition        | Three runs per variant at 1,200 requests per second with the median per second. The other scenarios are single runs of a minute at most.                              |

The starting point is reconstructed, the values don’t come from production. Render time and process count are chosen values. A real application has different absolute numbers, and exactly where it tips over depends on its capacity. Load generator and cluster share one machine.

## The same rollout, _measured twice._

1,200 requests per second are running, then the update starts.

- 95 %

  lowest hit rate in any second with the distributed cache. File cache: 68 %

- 252 ms

  highest p99 with the distributed cache. File cache: 6.6 s

- 57

  renders per second at the peak. File cache: 192, which is the capacity limit

Hit rate, axis from 50 %

Renders per second, the load on the application

Response time p95, logarithmic axis

Median per second of three runs. The 30 seconds before the update show normal operation. With the file cache the application itself is replaced, with the distributed cache the cache pods are. For the distributed cache that is the harder case. p95 rather than p99, because from around 1 % renders p99 mostly just shows the render time. p95 jumps between about 1 and 250 ms once more than 5 % render.

Show values as a table

| Second | File cache in the container: Hit rate | Distributed cache: Hit rate | File cache in the container: Renders/s | Distributed cache: Renders/s | File cache in the container: p95 | Distributed cache: p95 |
| ------ | ------------------------------------- | --------------------------- | -------------------------------------- | ---------------------------- | -------------------------------- | ---------------------- |
| -30    | 99 %                                  | 100 %                       | 8                                      | 0                            | 1.2 ms                           | 1.1 ms                 |
| -15    | 100 %                                 | 100 %                       | 5                                      | 0                            | 1.2 ms                           | 1.1 ms                 |
| 0      | 100 %                                 | 100 %                       | 4                                      | 0                            | 1.2 ms                           | 1.1 ms                 |
| 15     | 90 %                                  | 100 %                       | 191                                    | 0                            | 2,245.5 ms                       | 1.1 ms                 |
| 30     | 95 %                                  | 98 %                        | 62                                     | 19                           | 1.3 ms                           | 1.1 ms                 |
| 45     | 97 %                                  | 96 %                        | 40                                     | 40                           | 1.2 ms                           | 1.1 ms                 |
| 60     | 98 %                                  | 98 %                        | 28                                     | 34                           | 1.2 ms                           | 1.1 ms                 |
| 75     | 99 %                                  | 99 %                        | 15                                     | 9                            | 1.2 ms                           | 1.1 ms                 |
| 90     | 99 %                                  | 100 %                       | 12                                     | 4                            | 1.2 ms                           | 1.1 ms                 |
| 105    | 99 %                                  | 100 %                       | 10                                     | 2                            | 1.2 ms                           | 1.1 ms                 |
| 120    | 99 %                                  | 100 %                       | 6                                      | 1                            | 1.2 ms                           | 1.1 ms                 |

To Kubernetes the update is done after 5 seconds with the file cache, since the new pods respond. The load spike only starts then: for about 15 seconds the application runs flat out at 192 renders per second. Since every hit needs a PHP process too, everyone waits during that time. Even the median rises to 5.7 s.

The distributed cache takes longer to roll out, because every new pod first fetches data from the others. The application gets 57 renders per second at most, and the median stays below a millisecond. An update of the application itself hardly shows at all: 99.9 % hit rate, 1 render per second at most.

### And the hit rate of zero?

Every new pod starts at zero. If all are replaced at once, that hits in full: in the worst second of the test run only 28 % of requests hit, response time sat at the 10-second limit, and 1,332 requests failed. So the rolling update above is the benign case.

## More pods _in the middle of a spike._

An autoscaler reacts exactly when load rises, and with the file cache its new pods start empty. In the test load jumps from 600 to 2,400 requests per second, and five seconds later three pods join.

- 96 %

  lowest hit rate in any second with the distributed cache. File cache: 90 %

- 251 ms

  highest p99 with the distributed cache. File cache: 465 ms

- 78

  renders per second at the peak with the distributed cache. File cache: 229

Renders per second during scale-up

Response time p95, logarithmic axis

One run of a minute per variant. Start: three new pods are requested, the load jumped five seconds earlier. With the file cache the application scales, with the distributed cache the cache pods do. Triggered with kubectl scale, the same action an autoscaler takes. p95 jumps between about 1 and 250 ms once more than 5 % of requests render.

The file cache gets through this without errors here, because the new pods also bring capacity. But they cause work first: for about 15 seconds the application renders over 200 pages per second, p95 climbs from about 1 to over 350 ms, all in the middle of the spike. If the application has less headroom, with costlier pages or a database at its limit, this is exactly where it tips over. With the distributed cache the new pods fetch their pages from the others, and p95 stays at about a millisecond.

## Where it tips over _depends on the load._

When traffic is light, even the file cache absorbs an update: at 300 requests per second p99 stays at 282 ms. That changes quickly with load.

Update under rising load

|            | File cache |        | Distributed cache |        |
| ---------- | ---------- | ------ | ----------------- | ------ |
| Requests/s | p99 max.   | Errors | p99 max.          | Errors |
| 1,200      | 6.6 s      | 0      | 252 ms            | 0      |
| 2,400      | 10 s       | 6,496  | 2.3 s             | 143    |

From the start of the update to the end of the run. 1,200 requests/s: median of three runs, 2,400: one run of a minute. A request counts as failed after 10 s. The distributed cache’s errors are 503 responses: its admission limit protects the application from too many concurrent renders.

That explains why a problem like this often goes unnoticed for a long time. In quiet periods updates run through smoothly. It strikes exactly when traffic is high, when an update is urgent or a campaign is running.

Warm operation: p99 from 4,000 requests per second

7 seconds per level, no update, after warming up. x-axis: requests per second. Application pods have 4 CPU each, cache pods 2. The file-cache reconstruction only reads a file and loads no framework; a real application costs far more per hit.

## Three instances _that talk to each other._

The cache is a reverse proxy in front of the application and keeps finished pages in memory. It runs in its own pods, so an application update doesn’t touch it at all. Coordination between the instances takes care of rolling out the cache itself.

How the pieces fit together

Visitors

Browsers, crawlers, apps

Ingress

TLS ends here

Service

Only targets ready pods

Pod A

- :8080

  Pages

- :9090

  Metrics

- Pages in memory

  Page store

- Journal on a volume

Pod B

- :8080

  Pages

- :9090

  Metrics

- Pages in memory

  Page store

- Journal on a volume

Pod C

- :8080

  Pages

- :9090

  Metrics

- Pages in memory

  Page store

- Journal on a volume

Pod D new

- :8080

  Pages

- :9090

  Metrics

- Warming up

  Page store

- Journal on a volume

Headless Service

Every pod finds the others via DNS and talks to them directly, even while warming up.

- Ask the owner
- Spread purges
- Sync every 10 s
- Warm up new pods

Application

Apache and PHP in their own pods

Autoscaler

Reads the metrics via Prometheus and raises the number of pods when needed

Metrics

/metrics on every pod: requests, hits, trips to the application, pods in the cluster

The cluster grows by raising the replica count. New pods appear via DNS, fetch their pages from the others and only then report ready. The autoscaler isn’t part of the cache; the cache supplies the metrics.

1. Service

   Kubernetes

   Spreads requests across ready cache pods.

2. Cache pod

   Rust, Pingora

   Checks key and memory. On a hit, the work ends here.

3. Owner pod

   Rendezvous hash

   One pod is responsible for each page and fetches it when needed.

4. Application

   Apache, PHP

   Renders only what nobody has any more.

Sync

Purge bus, anti-entropy, warm-up

Purges reach every pod, new pods take over their pages from the others before they start.

What happens when …

Hit

- Trigger

  The page is in this pod’s memory

- What the cache does

  Serve directly from memory

- Result

  p50 0.6 ms

The most common case. No PHP and no file access. In the measured runs that was 97.9 % of all requests.

Hit at the owner

- Trigger

  Missing here, but the owner has it

- What the cache does

  Fetch from the responsible pod and keep a copy

- Result

  p50 0.7 ms

About 0.1 ms more, and the application notices nothing. The copy’s age travels with it, so a detour can’t extend its lifetime.

Miss

- Trigger

  No pod has the page

- What the cache does

  The owner renders once at the application

- Result

  p50 251 ms

The only path to the application for public pages. If the owner fails, the pod goes to the application itself; that costs one extra render and no error.

Rush on one page

- Trigger

  1,000 requests for the same cold page

- What the cache does

  One renders, all the others wait for it

- Result

  1 render instead of 48

This is called single-flight. The first requests wait briefly for that one render, but the application only ever sees one.

Page expired

- Trigger

  The page’s freshness has just run out

- What the cache does

  Serve the old version at once, refresh in the background

- Result

  No waiting

Stale-while-revalidate from RFC 5861. Whoever opens the page doesn’t wait. With conditional requests the application even skips rendering when nothing changed.

Application fails

- Trigger

  The application doesn’t answer or returns 5xx

- What the cache does

  Serve the last valid version

- Result

  97.9 % of requests answered

As long as the stale-if-error window is open. Pod readiness deliberately doesn’t depend on the application, otherwise Kubernetes would also take the cache out of service during an outage.

Pod restarts

- Trigger

  Update or crash, memory is empty

- What the cache does

  Fetch pages from the others before becoming ready

- Result

  Warm before it gets traffic

While the pod warms up it gets no traffic. If that doesn’t finish in time it starts cold, which is slower but correct.

Content changes

- Trigger

  The application purges by tag, path or pattern

- What the cache does

  Invalidate on all pods, acknowledge only after durable storage

- Result

  Acknowledged after 3.2 ms (p50)

Exactly the affected pages disappear, the rest stays warm. More in the chapter on cache tags.

### Who is responsible for which page?

Every pod computes a score for every page from the page and the pod’s ID. The pod with the highest score owns the page. All pods reach the same result without talking and without a central authority, and the jump during a failure stays small. Switch a pod off.

Grid of 72 pages coloured by owning pod. When a pod is switched off, only its pages change owner.

Each dot is a page, its colour shows the owner. Pick a pod to switch it off.

Demonstration in the browser using the same method. The cache itself uses xxh3 as its hash function.

### A thousand requests, one render

Without protection every request renders a cold page itself until the first one is done. With the file cache that means as many as there are PHP processes, all 48. The distributed cache lets only one request through, the others wait for its result.

Renders for 1,000 requests on the same cold page

- File cache in the container 48
- Three cache pods without sync 3
- Three cache pods with sync 1

About 1,000 requests within one second, three repetitions with a new page each, median. Without sync, every pod renders the page once for itself.

### Three time windows for every page

A page isn’t simply valid or invalid. The application sets three periods via Cache-Control, and the cache behaves differently in each.

1. Fresh max-age: serve without asking the application.
2. Stale-while-revalidate Serve the old version and refresh once in the background.
3. Stale-if-error Old version only if the application fails.

Following RFC 9111 and RFC 5861. Private responses, Set-Cookie and signed-in users stay out: they are never stored in the shared cache.

### Warm-up: fill first, then ready

A pod’s content only lives in memory and doesn’t survive a restart. That’s deliberate, since nothing outdated can then reappear after a restart. A new pod warms up from the others and only then reports ready.

1. #### Step 1: Sync purges

   The new pod fetches the purge state from every reachable pod before accepting a single page.

2. #### Step 2: Request the list

   Each pod names the pages it holds. The new pod keeps only the entries it will be responsible for.

3. #### Step 3: Fetch pages

   Up to eight transfers in parallel, within a fixed memory budget. Each page’s age comes along.

4. #### Step 4: Sync once more

   Whatever was purged during warm-up goes now. If this step fails or the 30 s limit runs out, the pod discards everything and starts cold.

### A purge has to reach everyone

A cache that keeps serving an outdated page is worse than one that does nothing. So a purge has to reach every pod reliably.

- 3.2 ms

  until a purge is acknowledged on two pods (p50, 30 measurements)

- 3.7 ms

  p95 of the same measurement, including fsync to the journal

- 60/60

  reads on the other pods right after the acknowledgement fetched the new version

* #### Every purge has a number

  Made up of pod, boot ID and a running number. That lets every pod spot duplicates and, above all, gaps in the sequence.

* #### Anti-entropy repairs what got lost

  Every 10 seconds a pod asks another for missing purges. If a gap can’t be closed, it empties its cache to be safe.

* #### Acknowledged means persisted

  A purge only counts as successful once two pods have stored it durably. Otherwise the application gets an error and can retry.

* #### Old content can’t come back

  Every transfer between pods carries the sender’s purge state. If the sender is behind, the receiver rejects the page.

## Purge exactly the pages _that are affected._

Without tags, a change leaves you two options: wait for pages to expire, or empty the whole cache. With tags, the application writes into every response what the page is made of, for example X-Cache-Tags: article-17, author-2. The cache remembers which page carries which tag and removes the header before the response reaches the visitor. When author 2 gets a new photo, the application just sends “author-2” to the cache. On every pod, exactly the pages with that tag become invalid, and the rest stays warm. This can be hard, so the next request renders again, or soft: visitors briefly keep getting the old version while a single request refreshes it in the background. That spares the application a rush even after large changes.

Purge by tag: author-2

- /article/17 article-17 author-2 invalid
- /article/23 article-23 author-5 stays cached
- /author/2 author-2 invalid
- /home article-17 article-23 author-2 author-5 invalid

## Memory alone _isn’t enough._

Would a simple in-memory cache do? For comparison, the same software runs with sync switched off, as three independent pods.

Renders per second during the cache rollout

Without sync: median of two runs. With sync: median of three runs. 1,200 requests per second each.

Without sync, renders during the rollout climb to 145 per second instead of 57, the hit rate falls to 85 instead of 95 %, and about 160 requests per run get a 503 because the admission limit kicks in. With sync there wasn’t one. Memory makes the cache fast; the pods talking to each other keeps it stable during a rollout.

## The application is gone. _The pages stay._

For this test pages are fresh for only 20 seconds. Then the application runs with zero pods for 30 seconds, at 300 requests per second. The file cache inevitably goes down with it, since it lives in the application’s pods.

- 97.9 %

  of requests answered by the distributed cache during the outage

- 5.4 s

  p99 during the outage

- 13.8 %

  of requests answered by the original setup in the same period

During this time the cache serves the last valid version. The median mostly stays at about a millisecond. Individual responses take seconds though, because until the health check detects the outage after about 30 seconds, the cache keeps trying the application. None of this helps personal areas: they bypass the cache and are simply gone.

## Why not _just Vinyl?_

Vinyl Cache (formerly Varnish) is the yardstick for HTTP caches. The community version, however, runs as a single instance, or you build your own cluster with distributed hashes yourself. An HA option only comes with the enterprise package. So I built my own reverse proxy, developed with AI and with the aim of keeping up on performance. Vinyl was the comparison throughout.

Requests per second by connection count

Response time p99 by connection count, logarithmic

The same 18 KB page from cache, 6 seconds of wrk per level, two passes, median. Caches on eight dedicated cores, wrk on separate ones. Short runs: differences below about 10 % are noise.

- 438,000

  peak throughput in requests per second, rounded. Vinyl: 428,000

- 0.61 ms

  p99 at 64 connections. Vinyl: 0.40 ms

- 8.4 MiB

  memory at 4 connections. Vinyl: 95.5 MiB

Up to 64 connections Vinyl leads on throughput, by 8 to 20 % depending on the level, and has the lower p99. From 128 connections both are level, and the own cache’s p99 is only about half as high. It also uses less CPU at every level, 12 to 33 %. For 10,000 pages of 8 KB each both need about 200 MiB; in gzip-only mode the own cache needs 96 MiB. Architecture tipped the decision to build it: instances that coordinate with each other aren’t part of the Vinyl community version.

## How this _is safeguarded._

Automated tests on three levels, plus targeted audits for races and edge cases.

- 260

  unit and property tests in Rust, plus 33 process and 12 demo tests

- 26

  checks in a real Kubernetes cluster, including pod kill and rollout

- 697,512

  verified responses in a five-minute soak, with 2,987 concurrent purges and zero failures

### What the tests safeguard

- Requests with cookies or sign-in don’t share content
- Purged pages don’t come back through races between purging and storing
- A transfer between pods doesn’t extend a page’s lifetime
- If a DNS lookup for a pod fails, the request falls back to the application
- Background work for purges stays bounded, even with slow pods

On a staging environment in a real cluster, 60 acceptance checks pass on top.

## What this _doesn’t prove._

The numbers show the behaviour in a test rig. These limits are part of the picture.

### Shown

- A rollout under load stays free of errors and major hit-rate drops in the rig
- Concurrent misses on the same page reach the application only once
- During a 30-second application outage, 97.9 % of requests are still answered
- Purges are acknowledged durably and reach all pods

### Still open

- The solid evidence comes from a staging environment, not from production under real load
- Behind the real gateway there were still brief errors during the rollout: 19 of 1,094 probes got a 502, because the gateway kept targeting old pods for longer than their shutdown delay
- The loss of a whole availability zone is untested
- A cut-off pod keeps serving its copies until they expire. Where that isn’t good enough, the route has to bypass the cache
- Capacity depends on the real application and has to be measured there

## What other teams _can take from this._

1. ### Convert the hit rate into load

   At 98 % everything looks fine. What matters is the value at which the application overflows, and no dashboard tells you that by itself.

2. ### Separate the cache from the lifecycle

   If the cache restarts with the application, it is missing at the hardest moment. Separate pods decouple the two.

3. ### Test the update, not only normal operation

   In the warm state a file cache looks fine. The problem only shows when you roll out under load.

4. ### Pick the tool by the bottleneck

   Vinyl leads with few connections, the own cache on p99 under many. Rollout and cluster sync decided it, which is exactly what the system lacked.

5. ### Green tests check what someone thought of

   The most dangerous bugs sit in races and edge cases. It takes a targeted hunt to find them.

### Your system runs. Also during an update?

In a tech check I look at architecture, operations and load behaviour. You get in writing what holds up and what’s needed before the next growth step.

[Book an intro call](https://www.alexander-hirschfeld.de/en?offer=technik-check#contact) · [See all services](https://www.alexander-hirschfeld.de/en#services)

[Next case study It works. That does not mean it holds up. A data platform built with AI runs in production. Will it carry hundreds of accounts too?](https://www.alexander-hirschfeld.de/en/case-studies/vibe-coding-scaling)

## Sources and background

- [RFC 9111: HTTP Caching](https://www.rfc-editor.org/rfc/rfc9111.html)
- [RFC 5861: stale-while-revalidate and stale-if-error](https://www.rfc-editor.org/rfc/rfc5861.html)
- [Rendezvous hashing (Thaler, Ravishankar)](https://en.wikipedia.org/wiki/Rendezvous_hashing)
- [Cloudflare Pingora](https://github.com/cloudflare/pingora)
- [Kubernetes: Volumes (on-disk files in a container are ephemeral)](https://kubernetes.io/docs/concepts/storage/volumes/)
- [Vinyl Cache (formerly Varnish Cache)](https://vinyl-cache.org/)

Anonymised: project, company and client names are removed. Load figures from the rig described above, test figures from the project.

As of 1 November 2026
