BE10: Capstone: three backend projects for TiffinBox

Lesson 3 of 5 · reading 15–25 minutes; practice and project time is on the module page

Project 2: a fast, fresh menu

🎯You'll be able to

Make a slow, popular read route fast with one query, an index and a cache, without ever showing an old price after a change.

🏠The everyday picture

A busy café writes the day's menu on a board instead of reading the recipe book to every customer. When the price of chai changes, they rub it out and rewrite it straight away, and if the board falls down, they read from the book until it's back up.

📘What it really is

📝A worked example

Measured in our test environment on 1 November 2026 (a 4-core practice machine; your numbers will differ), using npm run load -- http://localhost:4000/v1/kitchens/7/menu 300 10:

Version Database queries per cold request Requests per second p95
Starter 62 about 7 about 1.5 s
Finished 2, then 0 while cached about 1,000 about 12 to 14 ms

The finished version also answers correctly with Redis stopped (X-Cache: BYPASS), within the 1.5 s the test allows.

🌍Where it's used

📝Case scenario

A learner's cache made the menu fast, but test 7 failed: after a price change, the next request still showed the old price. They had set a 5-minute time-to-live and expected that to be enough. Deleting the key right after the database update, in the change route, fixed it, and the time-to-live stayed as a safety net.

🖱️Try it

Fix api/menu.js and add your index migration until npm run test:cache shows 9 of 9 passing. Record the load test before and after.

⚠️Common mistakes

🛠️For your project

Project 2: fix api/menu.js and add db/migrations/002_...sql until the 9 tests in tests/cache.test.js pass.

✅Quick check

Why fix the N+1 queries before adding a cache?

Show the answer

Cold requests and cache misses still run the query; a slow query makes misses and stampedes slow.

How does the menu stay fresh after a price change?

Show the answer

The change route deletes the cached key right after the database update, so the next request loads fresh data.

← PreviousProject 1: a secure orders API
ProLearners Assist