awesome-everything RU
↑ Back to the climb

Performance

N+1: multiple-choice review

Crux Multiple-choice synthesis across the N+1 unit — round-trip cost, fix-family choice by cardinality, DataLoader, off-CPU detection, pool exhaustion, and DoS amplification.
Your altitude — climbing toward senior
ZeroJuniorMiddleSenior
You are at senior altitude — in orbit
◷ 13 min

Six questions that cut across the whole unit. Each one mirrors a decision you make in a real incident — not a definition to recite, but a fix to pick when the query log is in front of you and the page is slow.

Goal

Confirm you can connect the round-trip cost model, the four fix families, the detection instruments, and the second-order failures — the synthesis the individual lessons built toward.

Quiz

A list page fires 51 queries at 0.4 ms each but the wall-clock is 765 ms. The DBA insists every query is fast and the indexes are fine. How do you reconcile this?

Quiz

A page loads 50 orders, each with ~20 line items. You fix the N+1 with a JOIN and query count drops 51 → 2, but p99 gets 30% worse. What happened and what is the fix?

Quiz

A GraphQL query me { posts { author { name } } } over 50 posts fires 1 + 50 author lookups. Why can't ORM eager loading (.includes / select_related) fix this, and what can?

Quiz

A REST aggregator calls 8 downstream services serially at 30 ms each (240 ms p99). A SQL N+1 on a list page also costs ~240 ms. Are these the same problem, and do they share a fix?

Quiz

A service with a 25-connection pool starts returning 503s under load. Individual query latency is stable, the DB is healthy, but pool saturation is pinned near 100% and the request queue is growing. Root cause and first fix?

Quiz

A public GraphQL endpoint lets clients control nesting depth and page size. A single crafted request spikes the DB to thousands of queries. How should a senior frame this, and what is the durable guard?

Recap

The through-line of the unit is one decision tree: count the round-trips first (the cost is trip count, not per-query speed), then pick the fix by cardinality — JOIN for one-to-one, IN/selectinload for heavy one-to-many, preload when the shape is known at the query site, DataLoader when lookups are scattered across resolvers, and parallel dispatch when independent services share no backend. Detect it off-CPU via query logs and APM waterfalls, gate it in CI, and remember the second-order failures: JOIN payload bloat, connection-pool exhaustion, query-plan flips, and DoS amplification.

Continue the climb ↑N+1: free-recall review
shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources3
expand
  1. 01
  2. 02
  3. 03

Trademarks belong to their respective owners. Editorial reference only.