Cache isolation and stampedes
Local baseline: Node.js 22.16.0. Dependency-free application model; no external service execution. No third-party packages or external connections.
Try the local example
const inflight=new Map();let loads=0;function read(tenant,id){const key=JSON.stringify([tenant,id]);if(inflight.has(key))return inflight.get(key);if(inflight.size>=4)return Promise.reject(Error('busy')); const work=Promise.resolve().then(()=>{loads++;return tenant+':'+id;}).finally(()=>inflight.delete(key));inflight.set(key,work);return work;}console.log(JSON.stringify(await Promise.all([read('a','x'),read('a','x'),read('b','x')])));console.log(loads,inflight.size);Run node main.mjs in a disposable directory with the files shown. Expected standard output:
["a:x","a:x","b:x"]2 0How it works
Use unambiguous key encoding rather than joining arbitrary strings with a delimiter. A local in-flight map can coalesce simultaneous loads for the same key within one process. It must remove completed or failed loads, bound the number of unique outstanding keys and enforce deadlines in the underlying loader. Across replicas, local coalescing is insufficient; consider jittered TTL, bounded concurrency or coordinated refresh. Do not serve private data without authorization just because the key contains a tenant. Redis pub/sub is not a durable queue.
Common mistake
Do not use a cache key based only on the item ID for tenant-scoped records. Do not let a rejected in-flight promise permanently poison future refreshes.
Practice
Repeat with different tenant IDs, then inject one rejected load and check that a later request can retry.
Documentation: primary source. Candidate lookup: node-cache-isolation-and-stampedes-lookup. Prerequisite: node-cache-aside-and-invalidation (platform route unverified).
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Cache isolation and stampedes — knowledge check
Apply the lesson’s contracts and identify common boundary mistakes.
Why include tenant in a private cache key?
What does local in-flight coalescing reduce?
Why remove rejected pending work?