Your API is slow. But your code looks fine. Common Spring Boot issue: N+1 queries. 1 query for parent • N queries for children Suddenly: • More DB calls • Higher latency • Poor performance Fix: • Use JOIN FETCH • Use DTO projections • Monitor queries Spring Boot didn’t slow your app. Your data access did. #SpringBoot #Java #Performance #Backend #SystemDesign #Debugging
Spring Boot N+1 Query Issue: Fix with JOIN FETCH and DTO Projections
More Relevant Posts
-
🚀 Day 17/100: Spring Boot From Zero to Production Topic: Activating Profiles in Spring Boot -> Why Activation Matters Creating profiles isn’t enough You need to activate them to use their config Otherwise, Spring Boot falls back to the default profile. -> Method 1: JVM Argument Pass this when running your app: -Dspring.profiles.active=dev Common for: Local development Switching configs quickly Loads application-dev.yaml -> Method 2: Environment Variable Set: SPRING_PROFILES_ACTIVE=dev Best for: Production environments CI/CD pipelines -> Default Behavior No active profile? default gets loaded Others are ignored Quick Insight Profiles = Config separation Activation = Making them work Simple concept. Powerful impact. This might sound simple but stay consistent. We’re building production mindset step by step. #Java #SpringBoot #SoftwareDevelopment #100DaysOfCode #Backend
To view or add a comment, sign in
-
-
Your Spring Boot app has 200 threads. Only 20 are doing real work. Here's what those 200 threads are actually doing: → 30 waiting for a DB connection. HikariCP pool = 10. 20 threads just standing in line. → 40 waiting for an external API. No read timeout set. Threads stuck in TIMED_WAITING. → 20 held by @Transactional. Method calls external service + sends email while holding a DB connection for 5+ seconds. → 10 blocked on synchronized code. One thread has the lock. 9 waiting. → 80 idle. No requests. Just consuming 1MB stack each = 80MB doing nothing. → 20 actually working. 200 threads. 20 working. 100 waiting. 80 idle. How to see this yourself: → jstack <pid> > thread-dump.txt → Or /actuator/threaddump → RUNNABLE = doing work. WAITING = stuck. BLOCKED = waiting for lock. → If WAITING > RUNNABLE — your app isn't slow because it lacks threads. It's slow because most threads are waiting. The fix: → Match HikariCP pool size to actual concurrency → Set read timeout on ALL HTTP clients → Keep @Transactional short — DB only, external calls outside → Consider Virtual Threads (Java 21) — waiting becomes cheap More threads won't fix a thread utilization problem. It'll just give you more threads doing nothing. #threads
To view or add a comment, sign in
-
🧠 After exploring singleton and prototype, I discovered a very practical Spring Boot scope today 👀 Request Scope 🌐 Here’s the simple idea 👇 ✅ A new bean object is created for every HTTP request ✅ Different requests never share the same object ✅ Perfect for request-specific processing This makes it super useful for 👇 🔹 request tracing IDs 🔹 temporary request metadata 🔹 audit logging helpers 🔹 request-level user context The cleanest way to use it 👇 @RequestScope 💡 My takeaway: Scope is not just about memory — it directly shapes how safely your web app handles request data ⚡ #Java #SpringBoot #RequestScope #BackendDevelopment #LearningInPublic
To view or add a comment, sign in
-
-
Spring Boot app has 200 threads. Only 20 are doing real work. Here's what those 200 threads are actually doing: → 30 waiting for a DB connection. HikariCP pool = 10. 20 threads just standing in line. → 40 waiting for an external API. No read timeout set. Threads stuck in TIMED_WAITING. → 20 held by @Transactional. Method calls external service + sends email while holding a DB connection for 5+ seconds. → 10 blocked on synchronized code. One thread has the lock. 9 waiting. → 80 idle. No requests. Just consuming 1MB stack each = 80MB doing nothing. → 20 actually working. 200 threads. 20 working. 100 waiting. 80 idle. How to see this yourself: → jstack <pid> > thread-dump.txt → Or /actuator/threaddump → RUNNABLE = doing work. WAITING = stuck. BLOCKED = waiting for lock. → If WAITING > RUNNABLE — your app isn't slow because it lacks threads. It's slow because most threads are waiting. The fix: → Match HikariCP pool size to actual concurrency → Set read timeout on ALL HTTP clients → Keep @Transactional short — DB only, external calls outside → Consider Virtual Threads (Java 21) — waiting becomes cheap More threads won't fix a thread utilization problem. It'll just give you more threads doing nothing. #threads
To view or add a comment, sign in
-
A Spring Boot mistake that silently kills your app performance. Not closing database connections properly. I worked on an app that kept crashing randomly in production. Memory usage would spike. Response times would double. Then the whole thing would freeze. We checked everywhere. Code looked fine. No obvious memory leaks. The problem? We were opening database connections but not releasing them back to the pool. Each request grabbed a connection and never let go. The fix was simple. Use try-with-resources. Let Spring manage the connection lifecycle. Stop manually opening connections without closing them. After the fix, memory usage dropped 40%. No more random crashes. The code looked fine. The logs showed nothing. But the connection pool was slowly choking the entire application. If your Spring Boot app slows down over time and restarts fix it temporarily, check your connection management first. What's a silent performance killer you've found in production? #SpringBoot #Java #Backend #Programming #SoftwareEngineering
To view or add a comment, sign in
-
𝗦𝘁𝗼𝗽 𝘂𝘀𝗶𝗻𝗴 @ComponentScan 𝗳𝗼𝗿 𝘀𝗵𝗮𝗿𝗲𝗱 𝗺𝗼𝗱𝘂𝗹𝗲𝘀.⚡️ Your shared libraries should be 𝗽𝗹𝘂𝗴-𝗮𝗻𝗱-𝗽𝗹𝗮𝘆, not a guessing game of which beans are being scanned. 👉 The fix? 𝗔𝘂𝘁𝗼-𝗰𝗼𝗻𝗳𝗶𝗴𝘂𝗿𝗮𝘁𝗶𝗼𝗻. Clean. Predictable. Zero setup. I wrote a quick guide on how to do it right in Spring Boot 👇 https://lnkd.in/dAu6mrtG #SpringBoot #Beans #Java #Kotlin #SoftwareArchitecture
To view or add a comment, sign in
-
🚀 I built ClusterBench — A Node.js Cluster Performance Visualizer Most Node.js apps run on a single CPU core by default. That means if your server is doing heavy work — everything else waits. So I built a CLI tool that proves exactly why clustering matters. 👇 What it does: → Spins up one worker per CPU core using Node.js cluster module → Fires 1000 concurrent requests at the server → Shows a live terminal dashboard of how load is distributed → Auto-detects and restarts crashed workers What I learned: → How Node.js cluster.isPrimary and cluster.fork() work → Round-robin load balancing across worker processes → IPC (Inter-Process Communication) between master and workers → Graceful worker crash recovery in production Tech Stack: Node.js · cluster module · Express.js · Commander.js · Chalk · cli-table3 🔗 GitHub: https://lnkd.in/gatC_XxT If you're learning Node.js backend — clustering is one of those topics that separates juniors from mid-level developers. Build something with it. #NodeJS #Backend #JavaScript #WebDevelopment
To view or add a comment, sign in
-
Most Spring Boot developers ship to production without knowing if their app is truly healthy. 🩺 You test your endpoints. Your CI passes. You deploy. But the moment something silently breaks, a database connection drops, an external API becomes unreachable, disk space runs out , your application keeps running, no errors, no alerts, just quietly serving failures to your users. That's the problem Health Checks solve. And Spring Boot makes it almost too easy to get right. 🩺 What is a Health Check? A simple mechanism that answers one question on a schedule: "Is this service actually ready to serve traffic?" Not just "is the JVM running?" — but "are all the pieces this app depends on working?" ⚡ Spring Boot Actuator , built-in and ready Add one dependency and you instantly get a /actuator/health endpoint that checks your database, MongoDB, disk space and more, automatically. UP ➡️ all good, serve traffic. DOWN ➡️ something is wrong, alert immediately. No custom code needed to get started. 🔧 But the real power is in custom indicators The default tells you if the app is alive. Custom health indicators tell you if your app is useful. You can write checks for anything: an external payment API, a message queue, a critical cache, if that dependency is down, your health endpoint reflects it, and your infrastructure reacts automatically. 💡 Two checks every production app needs: Liveness ➡️Is the app alive? Should it be restarted? Readiness➡️ Is the app ready to receive traffic? These two signals are especially critical in Kubernetes, they drive automatic restarts and traffic routing without any manual intervention. Are you using custom health indicators in your Spring Boot apps? Or just relying on the defaults? 👇 #Java #SpringBoot #HealthCheck #BackendDevelopment #SoftwareArchitecture #LearningInPublic #Kubernetes #Programming
To view or add a comment, sign in
-
-
Spent 20 minutes wondering why my Spring Boot app was starting slow. Checked everything. Database connections. External APIs. Nothing obvious. Then I found this: @SpringBootApplication @ComponentScan(basePackages = "com") Scanning "com" means Spring scans every package starting with com. Including third party libraries. The fix: @SpringBootApplication @ComponentScan(basePackages = "com.myapp") Be specific. Only scan your packages. Startup time dropped from 45 seconds to 12 seconds. Small change. Big difference. #SpringBoot #Java #Performance #BackendDevelopment #Programming
To view or add a comment, sign in
-
The Spring Boot annotation that can silently crash your server with an OutOfMemoryError. When you need to run a background task—like sending a notification or processing a file—the easiest way to do it is by adding @EnableAsync to your app and slapping @Async on your method. @Async public void processHeavyReport(ReportRequest request) { // 5 minutes of heavy processing } It works beautifully on your local machine. But in production, under heavy load, your server suddenly crashes. The Trap: The Unbounded Queue. By default, Spring Boot auto-configures a ThreadPoolTaskExecutor for your @Async methods. It gives you 8 core threads. But what happens when 1,000 users trigger that report at the same time? Those 8 threads get busy immediately. So, where do the other 992 tasks go? They go into the Thread Pool's Queue. And by default, Spring Boot sets that queue capacity to Integer.MAX_VALUE (over 2 billion). Spring will NEVER reject a task. It will just keep queuing them up in memory until your JVM runs out of RAM and your application dies completely. 💥 The Senior Fix: Cap your queues and handle rejections. Never trust the default thread pool configurations. Always explicitly configure them in your application.yml so you can control how your app behaves under stress. spring: task: execution: pool: core-size: 10 max-size: 50 queue-capacity: 100 # Put a hard limit here! If you get 150 requests, 50 run concurrently, 100 sit in the queue. What happens to request #151? It gets rejected (via RejectedExecutionHandler), throwing an exception that you can catch and gracefully tell the user: "System is busy, please try again later." Graceful degradation is a core pillar of System Design. It is infinitely better to fail 1 request than to crash the server and fail everyone. Have you ever had an app go down because of unbounded queues, or do you always tune your Thread Pools? 👇 If anyone interested check out this channel , we can have discussions there- https://lnkd.in/gKHDWvS5 #Java #SpringBoot #SystemDesign #Microservices #BackendDevelopment #SoftwareEngineering #PerformanceTuning #TechTips #LogicLedaMagic
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development