New: Cookbooks and AI ExplanationsStep-by-Step recipes to solve problems connected to Roadmaps and Cheat Sheets. Need more details? Use AI buttons for structured and simple explanations with concrete examples throughout the whole platform.Take a look
A bot keeps requesting product IDs that don't exist, and every single one of those requests still reaches your database.
What you'll have at the end
A short-lived cache entry for a not-found result, so the same missing id stops reaching Postgres on the next request
You need
A route that already checks a cache before querying Postgres for one row by its id, answering with the real row whenever one exists; what it does today when no row matches is the part this recipe replaces.
Not covered
Protecting against many requests for the same missing id arriving at once before the first miss finishes writing its sentinel; that pile-up is its own problem once this basic negative-caching path is live.
Leans on
Fix a cache that shows old data
the same idea, invalidating on write, but for the positive entries that go stale instead of the not-found ones this recipe writes, is worked through there.
Survive a cache stampede under load
many requests for the same missing id arriving before that first miss finishes writing its sentinel is its own pile-up, handled there rather than here.
Checked 19 Aug 2026
Part of the Backend Caching cookbook