---
title: "Discussion on \"N+1 query problem: Why it happens and How  to fix it\" | Hashnode"
description: "Discussion on \"N+1 query problem: Why it happens and How  to fix it\". n-1-query-problem-why-it-happens-and-how-to-fix-it"
url: "https://hashnode.com/posts/n-1-query-problem-why-it-happens-and-how-to-fix-it/6aa540f801eefd960bd19bb5"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [N+1 query problem: Why it happens and How to fix it](https://ayusharma.hashnode.dev/n-1-query-problem-why-it-happens-and-how-to-fix-it?utm_source=hashnode&utm_medium=feed)

n-1-query-problem-why-it-happens-and-how-to-fix-it

Sep 12 · 10 min read · ayusharma.hashnode.dev  
Updated Sep 15  
Read the article

-   [#n-plus-1](https://hashnode.com/tag/n-plus-1)
-   [#springboot](https://hashnode.com/tag/springboot)

## Written by

[Ayush Sharma](https://hashnode.com/@ayusharma)

@ayusharma · Pune, India

  
[View profile](https://hashnode.com/@ayusharma)

Java Full Stack Developer

## Responses 1

Markdown supported · ⌘↵ to post

[Adam Lewis](https://hashnode.com/@nark3d)

[Sep 16](https://hashnode.com/posts/n-1-query-problem-why-it-happens-and-how-to-fix-it/6aa540f801eefd960bd19bb5/comment/6aaa47f69c92057f278f6385)

I've kept one model per bounded context inside a monolith and it buys most of what the microservice diagram promises without the operational cost, but I still don't have a good answer for that one. When the collection comes back from the first query, an eager fetch that's genuinely needed is one whose parent entity is loaded as part of the same use case that consumes the collection, while an eager fetch that has merely moved the N+1 is one whose parent entity is loaded for a different reason and whose collection is then traversed somewhere else entirely. The fetch strategy hides the query count from the person reading the entity, so the next change adds a lazy path back in and the extra queries surface only when a page loads slow. What would you check first?
