Skip to content
Preptima

Top 4 N plus one Interview Questions

Browse 4 real-world technical and behavioral interview questions about N plus one. Review scenarios, edge cases, and architectural best practices.

A Spring Data repository method looks like one clean line, but the endpoint issues several hundred queries per request. How do you diagnose the N+1, and what would you actually change?

The repository call fetches parents in one query; the extra queries come later, when something touches a lazy association - usually the JSON serialiser, with open-session-in-view keeping the context alive so it succeeds silently. Diagnose by counting statements per request, then fix with a join fetch or entity graph, batch fetching, or a DTO projection.

hardscenario

A list endpoint that returns fifty orders issues more than a hundred queries, and rewriting it as an async endpoint made it slower. Explain both.

An N+1 happens when the ORM follows a relation lazily once per row; select_related fixes forward foreign keys with a SQL join, prefetch_related issues one extra query per relation and joins in Python. An async endpoint gets slower when it contains a blocking call, because that stalls the whole event loop.

hardscenario

This endpoint logs one query per row. Why are you seeing N+1 queries, and how do you fix them?

You get N+1 when one query loads N rows and something later dereferences a lazy association on each of them, firing a select apiece. Fix it per call site with join fetch, an entity graph, or batch fetching - not by changing mappings to EAGER.

mediumconcept

This EF Core query is slow. How do you work out why, and what does change tracking have to do with it?

EF Core query performance starts with the generated SQL, then checks N+1 queries, cartesian Include joins, over-fetching and change tracking. Use projections and AsNoTracking when the result is read-only.

mediumconcept