Backend Developer · Focus area 2: Databases and caching
BE3: Fast queries
Goal: find out why a request is slow and fix the database side: read query plans, add the indexes that matter, remove the "query per item" pattern, page and pool connections sensibly, and know when one database isn't enough.
You'll need: BE2, Module 57 (transactions and indexes), the TiffinBox kit with its data set up, and psql.
Where this is used: a menu that takes two seconds to load during the lunch rush, a dashboard that times out at month end, or a search that slows down as the business grows. Most backend slowness is a few queries doing far more work than they need to.
How it differs: a frontend developer makes the page feel fast in the browser (FE4). A backend developer makes the server's answer fast, and keeps it fast as data grows from thousands of rows to millions.
Time: reading about 2 hours · practice (the Try it tasks) about 3 hours · assignment about 3 to 4 hours.
Lessons
- 1How the database runs a queryReading 15–25 minutes, plus practice✓
- 2Indexes that earn their keepReading 15–25 minutes, plus practice✓
- 3The query-per-item trapReading 15–25 minutes, plus practice✓
- 4Connections and big result setsReading 15–25 minutes, plus practice✓
- 5When one database isn't enoughReading 15–25 minutes, plus practice✓
🛠️Assignment: A faster TiffinBox menu
This prepares Project 2.
- Record
EXPLAIN ANALYZEfor the starter menu's per-dish queries, and the query count from/_stats. - Write the combined menu query and prove its output matches the starter's for three kitchens.
- Add at least one index as a migration, and show its effect, positive or not, with numbers.
- Run the load test before and after, and explain the change in terms of round trips and pooled connections.
- Write a one-page scaling note: which of replicas, partitioning or sharding TiffinBox might need first, and the trigger.
Self-check before you finish:
- [ ] Every speed claim names how it was measured (tool, data, number of runs).
- [ ] The combined query keeps dishes with no orders or ratings.
- [ ] Each index you added is used by a plan you recorded.
- [ ] You didn't raise the pool size to make the numbers look better.
- [ ] Your scaling note includes a cost for each option.
✅Module check
Explain in a few sentences, in your own words:
How do you make a slow database-backed endpoint fast, and keep it fast as data grows?
Show a good answer
A good answer mentions: measuring first with EXPLAIN ANALYZE on realistic data and counting queries per request; indexes chosen from
real filters, joins and sorts, in the right column order, including foreign keys, and checked for use; replacing N+1 loops with one
set-based query using joins, aggregates and LEFT JOIN; small connection pools, short use of connections and paging or streaming large
results; and replicas, partitioning and sharding as later steps for measured needs, with their costs such as replication lag and
cross-shard queries.
📚Official references
Official documentation and guidance for this module's topics, chosen on 2 November 2026. Tools, laws and standards change, so check the current version before you rely on a detail. If a link has moved, search the same site.
📝Module quiz
10 questions · 10 marks each · 100 marks in all · pass mark 70% · retry as often as you like ·
