APIs
GraphQL N+1: free-recall review
Retrieval beats re-reading. For each prompt, say or write a full answer from memory before you open the model answer — the effort of recall is what makes the mechanism stick when you next see a 51-query page.
Reconstruct the unit’s spine — why isolation causes N+1, how DataLoader batches and why scope matters, the batch contract, federation, and the query-shape defence layers — without looking back at the lessons.
- 01Why does GraphQL get N+1 when a REST controller over the same data usually does not?
- 02When does DataLoader fire the batch, and why is the tick boundary better than a fixed timer?
- 03Why must a DataLoader be instantiated per request, and what specifically breaks with a module-scope instance?
- 04State the batchLoadFn ordering contract and how you satisfy it, including missing rows.
- 05In a federated graph, what does the router batch for free, and what do you still owe inside the subgraph?
- 06DataLoader is live. List the query-shape defences it cannot replace, and what each stops.
If you reconstructed each answer from memory, you hold the unit’s spine: resolver isolation causes N+1, DataLoader batches at the tick boundary but only safely with per-request scope and a same-order batch contract, federation gives you the network batch while you still owe the DB batch in __resolveReference, and the query-shape defences (depth, multiplicative complexity, trusted documents, alias and batch caps) guard everything DataLoader cannot. DataLoader fixes how many DB trips a query makes; the defence layers decide what shapes may run at all.