Log inBook a Demo
OptimizeSeniorBackendAuto-graded

Stop concurrent cache misses from hammering the backend

Assesses senior judgement under load: noticing that many simultaneous requests duplicate one expensive job, and coordinating them safely.cache.py is a read-through cache wrapping an expensive loader — a database query or an upstream call — returning the cached value and calling the loader only on a miss. Single-threaded it is fine. Under concurrent load it has a stampede: when many requests want the same uncached key at once, they all see the miss and all call the loader before any of them stores a result, so one logical miss becomes a hundred calls. Make concurrent misses for one key collapse into a single load.
40 min
python

You're done when

  • Concurrent requests for the same missing key result in exactly one call to the loader.
  • Every one of those requests still receives the correct value.
  • Different keys are not blocked by each other — a miss on one key does not serialise the others.
  • A key already in the cache is served from it without calling the loader.
  • The cache remains correct once the in-flight load completes and later requests arrive.

What it measures

Performance optimizationRecognising that the cost here is duplicated work under concurrency, not the cache lookup itself.
Resilience engineeringProtecting a backend from a herd of simultaneous misses, which is how caches amplify an outage instead of absorbing it.
Concurrency designCoordinating per key so callers share one in-flight load without introducing a global bottleneck.

Your environment

Terminal + editorA full shell in the browser
Claude CodePre-authenticated, no key setup
Isolated microVMYours alone, wiped afterwards

Start this lab

40 min
Start labYou'll sign in to Anthropos to start. The lab opens in a private cloud workspace with Claude Code ready to use.
AI Labs is part of Anthropos Workforce. Not on your plan yet? Book a demo