Q19: What is the N+1 problem in GraphQL?
The N+1 problem occurs when a query fetches a list of $N$ items, and for each item, an independent database call is executed to fetch a related field. This results in 1 initial query plus $N$ sub-queries ($1 + N$), crippling server performance.
N+1 Execution Flaw
Key Takeaways
- Naïve resolver execution results in $1+N$ database queries for nested lists.
- It is the primary performance challenge in backend GraphQL implementations.
Knowledge Check
If a query fetches 50 authors and their books, how many total DB queries occur in a naïve N+1 scenario?