Caching: Ferron Fox and the Long Ride to Oakhollow

updated 2026-10-07 · 20 min


ONELINE

A cache is a copy, so once the original can change underneath it, you need a deliberate freshness strategy — and a timer expiring isn't the same thing as being told the copy is wrong.

METAPHOR

A shelf that skips the ride to Oakhollow, a shared cart that skips the ride for everyone else too, and a handful of carts that split the load instead of all leaning on just one.

Cheat sheet: the fairground map

StorySystem
Ferron Fox and his Fireside Stew cartOne running service instance (a single server/process)
Pip's cart, and the rest of the fairground's cartsThe fleet — other instances of the same service, running alongside Ferron's
Hazel's larder, kept in Oakhollow Forest, a half-day's ride awayThe origin / backing data store — physically distant, so every round trip costs real time regardless of how busy it is
The venison stew, fourteen hours to simmerAn expensive computation worth keeping once produced
Mustard, chili flakes, the day's price slateSmall, individually-cheap data requested often enough that the total cost adds up
Ferron's own cart shelfA local (in-process) cache — fast, but each instance stocking its own full working set duplicates effort across the fleet
The one shared cart at the fairground's centerA single-node remote cache — shared across instances, removing the duplication, but still one node with a hard capacity ceiling
Several shared carts, each stocked with a different sliceA distributed remote cache — that same shared layer spread across multiple nodes, each owning a subset of the data
Shelf first, then the shared cart(s), then Oakhollow — restocking the layers on the way backA cache hierarchy: fastest layer checked first, fall through only on a miss, backfill on the way back
The chalked "good until sundown" labelA TTL (time-to-live)
Warden Olwen's recall callExplicit cache invalidation — an active signal, not an expiring timer
The ledger back at Hazel's larderThe system of record a write must eventually reach

Keep these at separate levels: Ferron is the whole running service, never the shelf itself. The shelf, the shared cart(s), and Hazel's larder are three different places the same stock can live — which one you're looking at changes how fast it answers and how far it can drift from the truth, never who's asking.

What problem is a cache actually solving?

A cache exists to avoid redoing work that's expensive for one of two different reasons: reaching the answer takes real time because it lives far away or because producing it takes real effort, or reaching it too often adds up even when any single trip looks cheap. Either way, keeping a copy closer to where it's needed also keeps traffic off whatever's slow or far away in the first place — the origin can't take unlimited visits any more than Hazel's larder in Oakhollow Forest can take every cart riding out to it at once.

The shelf that had to hold everything

Ferron Fox ran the Fireside Stew cart at the edge of the fairground, nearest the tree line. Everything that went into a bowl — the venison, the mustard, a pinch of chili flakes, even the little slate that listed the day's prices — technically all came from the same place: Hazel Hedgehog's larder, a full day's round trip away in Oakhollow Forest. Nobody minded the occasional ride. The trouble was it wasn't occasional.

A bowl of stew needed mustard. The next customer wanted extra chili flakes. The one after that just wanted to see the price slate. None of these were big requests on their own — but each one, fetched from Hazel's larder specifically, cost Ferron the same twelve-hour round trip as if he'd gone for a full wagonload. He couldn't run his cart and be on the road to Oakhollow at the same time. The stew made things worse before anything got better: a proper batch of his venison stew took fourteen hours to simmer from nothing, no matter how badly someone wanted a bowl right now.

So Ferron started keeping things. A jar of mustard, a tin of chili flakes, a chalked copy of the price slate — and, once a batch finished simmering, a pot of the stew itself — all on a shelf at the back of his own cart. Reaching for any of it took about as long as reaching for anything does. No ride, no fourteen-hour wait, just whatever was already sitting there.

Three different costs, one shelf Riding to Oakhollow for a small item costs about 720 minutes round trip, simmering a fresh batch of stew from scratch costs about 840 minutes, and reaching for either one on the shelf once it is already there costs about a minute. Ride to Oakhollow for mustard 720 min, round trip Simmer a fresh batch of stew 840 min, from scratch Reach for the shelf — either one ~1 min, once it's already there
The shelf answers the cheap errand and the expensive batch in about the same instant — but only because the work already happened once. (Break marks show the two long bars aren't drawn to true scale.)

It worked for Ferron. It also meant that to never make the ride, he'd eventually have to keep a little of everything Hazel's larder carried — not just the handful of things he reached for most, but genuinely everything he might someday need, just in case. And he wasn't the only cart doing this. Pip Otter's pickle cart kept its own shelf. So did the next cart, and the one after that. Six carts in, the fairground wasn't storing Hazel's stock once — it was storing most of it six separate times, once per cart, each shelf a little bigger than it needed to be for any single customer.

NAPKIN — Tech translation

Story: Each cart's shelf is fast and simple on its own — the problem only shows up once you count every cart's shelf together.

Python: This is a local (in-process) cache used with no sharing between instances: each running copy of a service keeps its own in-memory copy of whatever it needs. Reachable instantly from inside that one process, invisible to every other process — so if ten instances all need the same data, you don't get one cached copy, you get ten, and total memory used grows with the number of instances, not with how much data actually exists.

One shared cart, checked in order

The fix the carts landed on, eventually, was obvious enough once somebody said it out loud: stop keeping six shelves, keep one. A single shared cart went up at the center of the fairground, stocked with the staples every cart reached for, restocked from Oakhollow as needed, and open to any cart's runner.

Ferron's own habit changed to match. Check his own shelf first — if it's there, done. Not there? Send a runner to the shared cart instead of riding anywhere himself. Only if the shared cart didn't have it either did anyone saddle up for the full ride to Oakhollow — and whatever they brought back got left in two places on the way through: a jar on the shared cart for the next runner, and a smaller jar on Ferron's own shelf, in case he needed it again before anyone else did.

Ferron's full chain the first time, Pip's shortcut the second Ferron checks his shelf, then the shared cart, finds neither has it, rides to Oakhollow, and backfills both the shared cart and his own shelf on the way back. Later, Pip checks his own shelf, finds a miss, but the shared cart already has it, so he never has to ride anywhere. Ferron (first time) shelf: miss shared cart: miss rides to Oakhollow backfills the shared cart, then his own shelf, on the way back Pip (later) shelf: miss shared cart: hit no ride needed — Ferron already stocked it
The shared cart is why Pip's request stops one layer short of Oakhollow — it was never about Pip and Ferron talking to each other directly.

It removed the fleet-wide duplication of the shared stock — one shared stockpile instead of six copies of it, even though Ferron's own shelf still kept a little of its own. It didn't, on its own, make the fair infinitely scalable. By midsummer the fairground had grown from six carts to forty, and forty carts' worth of runners were queuing at the same one shared cart for everything none of them had on their own shelf. The cart wasn't any roomier than any other single cart at the fair — it was just the one expected to hold the entire fairground's working stock, for everyone, at once. Long before Oakhollow's actual supply ran thin, the shared cart's own shelf space, and the line of runners waiting on it, became the real limit.

NAPKIN — Tech translation

Story: One shared cart removes the duplication from before — every cart now reaches the same stock through the same place — but it's still exactly one cart, with one cart's worth of room and one cart's worth of hands serving runners.

Python: This is a single-node remote cache — one separate shared service (one Redis instance, say) that every instance of the application calls into over the network instead of keeping its own copy. It solves the fleet-wide duplication from the local-cache beat, but introduces a different limit: the whole shared working set has to fit on that one node, and that one node has to keep up with every instance's traffic at once.

Too much for one cart to carry

Stocking more onto the one shared cart wasn't really an option — a cart only has so much room, and forty carts' worth of staples doesn't fit on one, no matter how it's arranged. So the fairground split it instead. Three shared carts went up around the center instead of one, each stocked with a different slice of what Oakhollow carried: one carried grains and spices, one carried root vegetables, one carried dairy and preserves. No single cart held everything anymore — but between the three of them, everything was still there, somewhere.

Ferron didn't start asking the grain cart, then the root-vegetable cart, then the dairy cart, hoping one of them had his chili flakes. The carts had already agreed among themselves which one owned what, so a runner went straight to the grain cart for chili flakes and straight to the dairy cart for a jar of preserves, no asking around required. Nothing about Ferron's own habits changed otherwise: his shelf was still checked first, the three carts together were still the one layer he reached for next, and Oakhollow was still the one place anyone rode to if even that layer came up empty. It was the same three-layer order as before — shelf, shared layer, Oakhollow — the middle layer had just stopped being one cart and become three, each covering a slice of what the single cart used to try to cover alone.

The middle layer becomes three carts, not three sequential checks Ferron's shelf is still tier one and Oakhollow is still the origin. In between, tier two is now three carts, each holding a different category of stock, and a request for chili flakes goes straight to the grain cart that owns it instead of being tried against each cart in turn. Tier 1 Ferron's shelf Tier 2 — the distributed cache Grains & spices Root vegetables Dairy & preserves Origin Hazel's larder, Oakhollow Forest needs chili flakes — goes straight to the cart that owns it only if all of Tier 2 misses
Three carts, one logical layer: which cart owns an item is decided once, not discovered by asking each cart in turn.

NAPKIN — Tech translation

Story: Splitting the stock across carts solves the one-cart capacity ceiling — but only because something, in advance, decided which cart owns what; without that agreement, Ferron really would be asking around.

Python: This is a distributed cache — the same shared layer from the last beat, now spread across multiple cooperating nodes, each owning a partition (a shard) of the full key space, typically decided by hashing the key. It's still a remote cache from any one instance's point of view — "remote" and "distributed" describe different things: where the cache lives (not in-process) versus whether that remote layer is one node or several. Splitting the data buys more room and more throughput, in exchange for needing that routing agreement — not a strictly better cache in every respect, just a different tradeoff than one node.

The recall that beat the label

Every jar that went up on a shelf or a shared cart got chalked with a label — "good until sundown," usually, since that's about how long a fair day's prepared stock was trusted to sit out. Nobody checked much beyond that. If the chalk hadn't run out, the jar was fine.

One afternoon, a batch of the dipping sauce turned bad at two o'clock — hours before any label chalked that morning said it should. Warden Olwen, the fairground's food-safety owl, caught it on an inspection round at ten past two and called the recall over the signal-horn network the carts used for exactly this. But a recall has to physically reach every shelf and every shared cart before any of them stop serving from it, and that took the better part of half an hour to make the rounds. Ferron, three bowls deep into the lunch rush with his horn turned down against the noise, kept serving straight off the shelf the whole time — not because he'd ignored anything, but because the only thing he'd actually checked was the label, and the label, chalked that morning, still said "good until sundown." It had no way of knowing anything had happened at the larder at all.

The label's countdown keeps running long after the sauce is actually bad The label claims the sauce is good from ten in the morning until six in the evening. The sauce actually spoils at two o'clock. Warden Olwen's recall goes out ten minutes later and reaches Ferron's cart at twenty minutes to three. Between two o'clock and twenty minutes to three, the sauce is being served while genuinely bad, and the label would have kept claiming it was fine for over three more hours after that if the recall hadn't arrived. label says "good" — chalked 10:00am sauce turns bad 2:00pm Olwen calls the recall, 2:10pm reaches Ferron's cart, 2:40pm served bad label still says "good" until 6:00pm
Forty minutes of bad sauce reach customers before the recall catches up — and the label alone would have kept saying "fine" for over three hours more.

NAPKIN — Tech translation

Story: The label's countdown and Olwen's recall are two completely different mechanisms, and only one of them actually knows the sauce went bad. The chalk just counts down on a clock set that morning; the recall is the one message actually watching whether anything's still true.

Python: This is TTL (time-to-live) versus explicit invalidation. A TTL bounds how long an entry is trusted without being rechecked — cheap, automatic, and completely indifferent to whether the underlying data actually changed in the meantime. Invalidation is an active signal — something that knows the origin changed reaches in and removes (or corrects) the cached copy immediately, regardless of how much TTL is left. A short TTL narrows the gap; it never closes it the way an explicit invalidation call does, delivery time permitting.

WATCHOUT

A TTL's job is to bound how long you'll trust a copy without hearing otherwise — it is not a guarantee that the copy is still right. TTL and invalidation solve different problems, and data where staleness is unsafe often benefits from combining both.

  • TTL alone — cheap, handles ordinary drift, but leaves exactly the kind of window this beat just dramatized
  • Explicit invalidation alone — catches changes immediately, but only if something is watching the origin and the message actually gets delivered
  • Both together — TTL as a safety net, invalidation for anything that can't wait, like a recall

RECALL

Olwen's recall has to physically reach every shelf and every shared cart before any of them stop serving the bad batch. What happens to a cart that isn't listening on the signal horn at that exact moment — and what would actually have to change for the recall to guarantee delivery, rather than just announce it?

ASIDE

This lesson doesn't cover what decides which items get bumped off a full shelf when something new needs the room. Eviction policies like LRU or LFU are a separate, later question from whether an entry is right or wrong in the first place.

Three ways to write it down

Reading from a cache only covers half of what Ferron's cart does. Every restock, every custom order, every new batch eventually has to be written down somewhere — not just on his shelf, but back on Hazel's actual ledger at the larder, the record the rest of the fair's accounting trusts. Where that write lands first, and when the other copy catches up, turned out to matter more than Ferron expected.

On an ordinary morning restock, Ferron does both before moving on to anything else: chalk the new count on his shelf, and send word to Hazel's ledger confirming the same number, not considering the restock finished until both agree. It costs him a few minutes he could be using to serve someone, every single time he restocks, but his shelf and Hazel's ledger are never caught disagreeing.

A customer orders something odd — double chili, no venison, extra mustard — a combination nobody's likely to ask for again before the day's out. Ferron sends word straight to Hazel's ledger and leaves his own shelf alone entirely. There's no reason to spend shelf space holding a combination that probably won't come up a second time; if it ever does, the next order misses the cache layers and eventually checks the ledger.

At the height of the lunch rush, Ferron updates his own shelf the instant he preps something new, so the line in front of his cart never stops moving — word to Hazel's ledger can wait for a quieter minute between orders. That quieter minute doesn't come. The fairground's one shared generator sputters out before he gets to send anything, and whatever he chalked up during that stretch never reaches Hazel's ledger at all. Not late. Gone — because nothing else at the fair knew to tell her either.

NAPKIN — Tech translation

Story: All three answer the same question differently — when Ferron writes something new, does his shelf get it first, does Hazel's ledger get it first, or do both get it at the same moment?

Python: Write-through: cache and origin updated together, synchronously — safest, costs latency on every write. Write-around: origin only; the cache only picks the value up later, on a read that misses. Write-back (write-behind): cache first, origin deferred — fastest at the call site, but anything written in that deferred window is only as durable as the cache, until the deferred write actually lands.

Where the new value lands first, for each write strategy Write-through updates the shelf and the ledger at the same time. Write-around updates only the ledger, leaving the shelf untouched. Write-back updates the shelf immediately and the ledger later, and that deferred ledger update can be lost entirely if something fails before it happens. Write-through shelf ledger — both at once Write-around shelf — untouched ledger — updated immediately Write-back shelf, now ✕ ledger, deferred — lost if the generator fails first
Only write-back leaves a window where the shelf and the ledger can disagree — and where the ledger's half of that disagreement can vanish for good.

Putting it together: a shelf that can actually hear a recall

Here's roughly what Ferron's shelf looked like before the gotcha scene — fast, but with exactly one way for an entry to go away: its own clock running out.

import time

class ShelfCache:
    def __init__(self):
        self._entries = {}

    def get(self, key):
        entry = self._entries.get(key)
        if entry is None:
            return None
        value, expires_at = entry
        if time.monotonic() > expires_at:
            del self._entries[key]
            return None
        return value

    def set(self, key, value, ttl_seconds):
        self._entries[key] = (value, time.monotonic() + ttl_seconds)

There's no path here for anything outside to reach in and say "this one's wrong, right now" — a recall, a correction at the larder, nothing. The only exit is the clock. Warden Olwen's recall needs a second path that doesn't wait on that clock at all:

class ShelfCache:
    def __init__(self):
        self._entries = {}

    def get(self, key):
        entry = self._entries.get(key)
        if entry is None:
            return None
        value, expires_at = entry
        if time.monotonic() > expires_at:
            del self._entries[key]
            return None
        return value

    def set(self, key, value, ttl_seconds):
        self._entries[key] = (value, time.monotonic() + ttl_seconds)

    def invalidate(self, key):
        self._entries.pop(key, None)

The recall becomes a single call — shelf_cache.invalidate("sauce_batch_17") — fired the moment Olwen's message reaches Ferron's cart, not whenever the label's countdown happens to finish. The TTL is still underneath it, catching anything nobody ever explicitly corrects; the invalidate() call is what actually closes the gap the gotcha scene dramatized.

And here's what the shared cart from earlier actually bought the fairground, computed honestly rather than asserted. Say thirty carts each need one fresh jar of chili flakes restocked once during the fair. Without any shared cart, each of those thirty restocks is its own round trip to Oakhollow: 30 × 720 minutes = 21,600 minutes of riding, spread across the fair. With one shared cart doing a single ride and everyone else's runner just walking over to it: one 720-minute ride to stock the shared cart, plus twenty-nine roughly one-minute trips to the shared cart itself — 720 + 29 ≈ 749 minutes total. That's about 29 times less riding, for the exact same thirty restocks.

Three carts riding separately versus three carts sharing one cart Three carts each riding to Oakhollow on their own cost 720 minutes apiece. The same three carts sharing one cart cost a single 720-minute ride to stock it, plus two roughly one-minute trips to the shared cart afterward. Without a shared cart Cart 1 720 min Cart 2 720 min Cart 3 720 min With one shared cart Cart 1 stocks it 720 min Cart 2 draws from it ~1 min (widened to be visible) Cart 3 draws from it ~1 min (widened to be visible)
The one-minute bars are drawn wider than real so they're visible at this scale — the honest ratio is the one in the numbers above, not the one in the picture.

Closing distinction: invalidation, or just eviction?

Not every time an entry disappears from a cache is the gotcha scene's kind of problem. If Ferron's shelf fills up and the oldest jar nobody's touched in hours gets pushed off to make room for something new, nothing about that jar was wrong — it was simply time for something to go, and the shelf picked the least-used thing. That's eviction: routine housekeeping under capacity pressure, with no claim that the evicted entry was incorrect.

Invalidation is a different claim entirely: the entry is sitting right there, with plenty of room to spare, and it's still wrong, because whatever it's a copy of changed at the origin. Olwen's recall doesn't care how full or empty the shelf is; it cares that the sauce is bad. In code terms, cache.evict_lru() and cache.invalidate(key) are triggered by two unrelated conditions — one by how much room is left, the other by whether the origin has moved on without telling the cache yet — and conflating them is how a correctness problem quietly gets treated as a capacity problem, or the other way around.