โ Backend Performance & Scaling learning pathBackend Performance & Scaling ยท Module 3 of 8
Database query performance
Most slow backends are slow databases.
๐ Key ideas
- An index lets the database find rows without scanning the whole table, like a book's index.
- Use EXPLAIN (or the query plan) to see whether a query uses an index or scans the table.
- The N+1 problem: one query for a list plus one query per item; fetch in one joined or batched query instead.
- Select only the columns you need and paginate large results.
- Use a connection pool; opening a new database connection for every request is slow.
๐ก Real-life example: Searching a table without an index is like finding one student's marks by reading every page of the register instead of using the roll-number index.
IndexStructure that speeds up finding rows
Query planHow the database will run a query
N+1 problemOne query plus one more query per item
Connection poolReused set of open database connections