Skip to main content

One post tagged with "Java"

View All Tags

How to Detect and Fix N+1 Queries in Spring Boot Before Production

· 10 min read
Evgenii Frolikov
Senior Java Architect | Expert in High-Load Systems & JVM Internals

How to Detect and Fix N+1 Queries in Spring Boot Before Production

TL;DR: The hardest part of an N+1 bug is not fixing it. The hardest part is noticing it before production. A Spring Boot endpoint can return the correct JSON, pass unit tests, and still execute 243 SQL queries instead of 1. This post shows how to detect N+1 patterns from real traces, choose the right fix in Spring Data JPA, and verify that the optimization did not change the API output.