N+1 query
In an N+1 pattern, a list query is followed by another fetch for each result. The structure matters, not merely a high call count.
An N+1 query occurs when an application first loads a list and then performs another query for each entry. The number of accesses therefore grows with the number of entries.
A small calculation
In a hypothetical portal, a list of 10 orders is followed by individual fetches of their delivery addresses. Together these are 11 database calls. Depending on the need, related data could also be loaded together within appropriate limits.
Many queries alone do not prove this pattern. The relationship to iteration over the results must be visible. Nor is an arbitrarily large combined query automatically better. Required data volume, permissions and actual execution cost remain part of the investigation.
Sources
Related terms
- Database queryA database query requests data under defined conditions. Selection, result scope and ordering should fit the work being done.
- Response timeResponse time needs a defined start and end. Fetching an API response and reaching a usable view measure different sections.
- Legacy systemAn existing system still in use, with technical and business dependencies accumulated over time.
- Multi-tenancyMulti-tenancy supports separate customer or group scopes in one solution. A tenant is not automatically one person or one database.
- Browser cacheThe browser cache stores suitable HTTP responses for later use. Reuse and revalidation follow the applicable rules.
- Cache invalidationCache invalidation ends reuse of a stored copy under defined rules. The source record remains a separate concern.
Articles on this topic








Software Development with ASES
Custom software, web and mobile apps



