Code RoomServerless cache cold starts
MediumPrep Room Coding #4615

Serverless cache cold starts

Vibe & agenticAlgorithms & data structuresMid–Senior~18 min

You ask an AI to add caching to a TypeScript function that fetches a user's feature flags from an API. It wraps it in a module-level `Map` cache keyed by userId — fast, but now flags never update until redeploy, and in your serverless runtime each cold invocation has an empty cache so the hit rate is ~0 anyway. You re-prompt 'add cache expiry'; it adds a 1-hour TTL, which fixes staleness but not the cold-start miss or a thundering herd on expiry. How do you re-steer?

Implement
plan_cache_reads(request_times: list[int], fresh_ttl: int, stale_window: int) → list[str]
Examples
in[[0,10,30,95,200],60,30]out["fetch","hit","hit","fetch","fetch"]
in[[0,70,70,75],60,30]out["fetch","stale_revalidate","hit","hit"]
in[[],60,30]out[]
What a strong answer looks like

Treat the AI’s output as a draft to verify, not an answer to trust. Name the specific flaw and the input that triggers it, say how you’d catch it (tests, edge cases, reading critically), and how you’d re-prompt or decompose to get it right.

0:00 of about 18 min

Vibe & agentic: describe the solution in plain language (or narrate it) and the coach grades your approach.

Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.