Most Spring Boot apps I've reviewed in production don't fail because of bad logic. They fail because of 𝗹𝗮𝘇𝘆 𝗱𝗲𝗳𝗮𝘂𝗹𝘁 𝗰𝗼𝗻𝗳𝗶𝗴𝘂𝗿𝗮𝘁𝗶𝗼𝗻𝘀 that nobody questioned. Here's what I wish someone told me earlier. Stop returning entity objects directly from your controllers. It seems convenient until you accidentally expose sensitive fields or break your API contract when the schema changes. Always map to a dedicated response DTO. Your future self will thank you when a database column rename doesn't trigger a client-side outage. Use constructor injection instead of `@Autowired` on fields. It makes your dependencies explicit, simplifies testing, and lets the compiler catch missing beans before runtime does. Spring actually recommends this approach. Java @RestController public class OrderController { private final OrderService orderService; public OrderController(OrderService orderService) { this.orderService = orderService; } } Configure 𝘀𝗲𝗽𝗮𝗿𝗮𝘁𝗲 𝗽𝗿𝗼𝗳𝗶𝗹𝗲𝘀 for each environment from day one. Hardcoding values in `application.properties` and "fixing it later" is technical debt that compounds fast. Use `application-dev.yml`, `application-prod.yml`, and externalize secrets through environment variables or a vault. One more thing people overlook: 𝗮𝗹𝘄𝗮𝘆𝘀 𝘀𝗲𝘁 𝗲𝘅𝗽𝗹𝗶𝗰𝗶𝘁 𝘁𝗿𝗮𝗻𝘀𝗮𝗰𝘁𝗶𝗼𝗻 𝗯𝗼𝘂𝗻𝗱𝗮𝗿𝗶𝗲𝘀 with `@Transactional` on your service layer, not your repository layer. It gives you control over rollback behavior when multiple repositories are involved. What's one Spring Boot default you learned the hard way should have been overridden? #SpringBoot #Java #BackendDevelopment #SoftwareEngineering #CleanCode
Spring Boot Defaults to Override for Better Code
More Relevant Posts
-
Thread Pools to Virtual Threads. 🧵 OutOfMemoryError it is a nightmare that has always haunted Java developers. We're always been stuck with Platform Threads (heavyweight wrappers around OS threads). Since each one cost about 1MB of memory, handling 10,000 concurrent requests meant you either needed a massive, expensive server or had to write complex reactive code that nobody actually wants to debug. Enter Project Loom (Java 21+). I’ve been diving into Virtual Threads, and the "blocking" game has completely changed. Here’s why this matters for the modern backend: Cheap as Chips: Virtual threads are managed by the JVM, not the OS. They only cost a few hundred bytes. You can literally spawn one million threads on a standard laptop without breaking a sweat. The "Thread-per-Request" Revival: We can go back to writing simple, readable, synchronous code. No more "Callback Hell" or complex Mono/Flux chains just to keep the CPU busy while waiting for a database response. Massive Throughput: In I/O-heavy applications (which most Spring Boot apps are), Virtual Threads allow the CPU to switch to other tasks instantly while one thread waits for a slow API or SQL query. How to use it in Spring Boot 3.2+? It’s literally one line in your application.properties: spring.threads.virtual.enabled=true By flipping this switch, Tomcat/Undertow starts using Virtual Threads to handle web requests. It’s a complete paradigm shift that lets us build more scalable systems with less infrastructure cost. The takeaway for teams: We no longer have to choose between "easy-to-read code" and "high-performance code." With Java 21, we get both. #Java #SpringBoot #BackendDevelopment #ProjectLoom #SoftwareEngineering #Scalability #JVM
To view or add a comment, sign in
-
-
Spring Boot Bean Scope — Not just Singleton 🤯 Most developers only know this: 👉 Default scope = Singleton But there’s more 👇 ✅ Prototype → New instance every time ✅ Request → Per HTTP request ✅ Session → Per user session 💡 Why it matters: ✔ Memory optimization ✔ Better state handling ⚠️ Mistake: Using singleton for stateful data ❌ 👉 Leads to concurrency issues 🔥 Real lesson: Choose scope based on use case, not default Backend bugs often start here 🚨 #SpringBoot #Java #Architecture
To view or add a comment, sign in
-
#Java #Spring #Bean 🌱 Spring Bean Lifecycle 👉 In Spring Framework, bean lifecycle has 5 simple steps: 🔄 Lifecycle Steps 1️⃣ Instantiate ➡️ Spring creates object 2️⃣ Inject Dependencies 💉 ➡️ Dependencies added (@Autowired) 3️⃣ Initialize ⚙️ ➡️ Setup using @PostConstruct 4️⃣ Use Bean 🚀 ➡️ Business logic runs 5️⃣ Destroy 🧨 ➡️ Cleanup using @PreDestroy 🧠 One-Line 👉 Spring Bean Lifecycle = Create → Inject → Initialize → Use → Destroy (managed by Spring Container)
To view or add a comment, sign in
-
Your Spring Boot app has 200 users waiting. Your CPU is at 10%. No errors. No crashes. The culprit? 20 threads — all blocked, all doing nothing. I built a benchmark project to see exactly what happens inside the JVM when a classic thread pool hits this wall, and what changes when Java 21 virtual threads take over. Same app. Same business logic. One executor swap. Results with 200 concurrent users over 30 seconds: → Throughput: 1.95 req/s (classic) vs 252.89 req/s (loom) → p(95) latency: 56 seconds (classic) vs 0.81 seconds (loom) → Requests completed: 117 (classic) vs 7,784 (loom) → 140 users never got a response in classic mode. In Loom, all 200 finished cleanly with zero interruptions. What surprised me most was not the throughput number. It was looking inside the JVM mid-load and seeing 1,846 virtual threads active while the OS thread count barely moved. Loom does not add OS threads — it parks tasks as objects on the heap and frees the carrier thread instantly. One non-obvious gotcha for anyone adopting this in production: Thread.getAllStackTraces() intentionally excludes virtual threads in Java 21. Your existing monitoring tools may already be blind to them. Full benchmark with thread snapshots, heap data, GC numbers, and code walkthrough in the article below. #Java #Java21 #ProjectLoom #SpringBoot #BackendDevelopment #SoftwareEngineering #Programming
To view or add a comment, sign in
-
thanks a lot Ragasudha R really fantastic work on Performance benchmarking for Classic Platform / OS Threads vs Virtual Threads loved reading this blog working as a Performance Engineer
Advanced Software Engineer at Gartner | Java | Spring Boot | AWS Certified | Certified Kubernetes Application Developer
Your Spring Boot app has 200 users waiting. Your CPU is at 10%. No errors. No crashes. The culprit? 20 threads — all blocked, all doing nothing. I built a benchmark project to see exactly what happens inside the JVM when a classic thread pool hits this wall, and what changes when Java 21 virtual threads take over. Same app. Same business logic. One executor swap. Results with 200 concurrent users over 30 seconds: → Throughput: 1.95 req/s (classic) vs 252.89 req/s (loom) → p(95) latency: 56 seconds (classic) vs 0.81 seconds (loom) → Requests completed: 117 (classic) vs 7,784 (loom) → 140 users never got a response in classic mode. In Loom, all 200 finished cleanly with zero interruptions. What surprised me most was not the throughput number. It was looking inside the JVM mid-load and seeing 1,846 virtual threads active while the OS thread count barely moved. Loom does not add OS threads — it parks tasks as objects on the heap and frees the carrier thread instantly. One non-obvious gotcha for anyone adopting this in production: Thread.getAllStackTraces() intentionally excludes virtual threads in Java 21. Your existing monitoring tools may already be blind to them. Full benchmark with thread snapshots, heap data, GC numbers, and code walkthrough in the article below. #Java #Java21 #ProjectLoom #SpringBoot #BackendDevelopment #SoftwareEngineering #Programming
To view or add a comment, sign in
-
File Uploads and Retrieval in Spring Boot Master file management in modern web applications by exploring File Uploads and Retrieval in Spring Boot. Handling binary data is a core requirement for enterprise systems, and this guide provides a deep dive into building a robust solution using REST controllers and the MultipartFile interface. Following a "core-to-shell" approach, you’ll learn to integrate foundational Java NIO operations with high-level Spring APIs to create a seamless bridge between raw disk storage and your frontend. Discover how to implement secure uploads and efficient file fetching while maintaining a clean, scalable microservices architecture. => Multipart Management: Efficiently process file streams with Spring Boot. => Java NIO Mastery: Use modern I/O for high-performance file handling. => RESTful Fetch: Implement endpoints for secure content retrieval. https://lnkd.in/gyQvP5QA #SpringBoot #spring #springframework #springbootdeveloper #Maven #Java #java #JAVAFullStack #RESTAPI #Microservices #BackendDev #JavaNIO #FileUpload #WebDevelopment #CodingTutorial #codechallenge #programming #CODE #Coding #code #programmingtips
To view or add a comment, sign in
-
Is FetchType.EAGER silently killing your performance? 🚨 One mistake I’ve seen repeatedly in Spring Boot applications is overusing EAGER fetching. Looks harmless… until it hits production. The problem 👇 Every time you fetch a parent entity, Hibernate also loads the entire child collection. Now imagine: → A user with 5,000 orders → A department with 50,000 employees Your “simple query” just became a massive memory load. This doesn’t just slow things down… it stresses your entire JVM. What I follow instead 👇 ✔ Default to LAZY ✔ Use JOIN FETCH when needed ✔ Use @EntityGraph for controlled fetching Your entity design is not just structure. It’s a performance decision. Better to write 1 extra query… than load 10,000 unnecessary records. Curious to hear from other devs 👇 Do you treat FetchType.EAGER as a bad practice? Or still use it in some cases? #Java #SpringBoot #JPA #Hibernate #BackendDevelopment #SoftwareEngineering #Performance #TechDiscussion
To view or add a comment, sign in
-
-
🚀 Mastering Spring Boot – Step by Step (Day 2) Still using "new" in Spring? ❌ 👉 Then you’re missing the core idea of Spring 💡 What is a Spring Bean? A Bean is: 👉 Any object managed by the Spring IoC container Instead of: UserService service = new UserService(); Spring does: ✔ Create objects ✔ Manage lifecycle ✔ Connect components 💡 What is IoC (Inversion of Control)? 👉 You don’t control object creation anymore 👉 Spring does it for you This leads to: ✔ Cleaner code ✔ Loose coupling ✔ Better scalability 💡 Simple way to think: You: "I will create objects" ❌ Spring: "I will handle everything" ✅ 👉 This is the foundation of Spring Next → Dependency Injection (real magic begins) 🔥 #Spring #SpringBoot #Java #Backend #LearningInPublic
To view or add a comment, sign in
-
JVM Architecture - what actually runs your Java code ⚙️ While working with Java and Spring Boot, I realized something: We spend a lot of time writing code, but not enough time understanding what executes it. That’s where the JVM (Java Virtual Machine) comes in. A simple breakdown: • Class Loader Loads compiled `.class` files into memory. • Runtime Data Areas * Heap → stores objects (shared across threads) 🧠 * Stack → stores method calls and local variables (per thread) * Method Area → stores class metadata and constants * PC Register → tracks current instruction * Native Method Stack → handles native calls • Execution Engine * Interpreter - runs bytecode line by line * JIT Compiler - optimizes frequently used code into native machine code ⚡ • Garbage Collector Automatically removes unused objects from memory --- Why this matters: Understanding JVM helps in: * Debugging memory issues (like OutOfMemoryError) * Improving performance * Writing more efficient backend systems --- The more I learn, the more I see this pattern: Good developers write code. Better developers understand how it runs. #Java #JVM #BackendDevelopment #SpringBoot #SystemDesign
To view or add a comment, sign in
-
🧬 Spring Boot – Understanding API Responses Today I explored how Spring Boot sends data from backend to frontend. 🧠 Key Learnings: ✔️ Returning a Java object automatically converts it to JSON ✔️ Spring Boot uses Jackson internally for this conversion ✔️ "@ResponseBody" ensures data is sent directly as response 💡 Best Practice: 👉 Using "@RestController" simplifies everything (Combination of @Controller + @ResponseBody) ✔️ Explored different return types: • Object • List • String • ResponseEntity (for better control over status & response) 🔁 API Flow: Request → Controller → Service → Return Object → JSON Response → Client 💻DSA Practice: • Even/Odd check using modulus • Sum of first N numbers (optimized using formula) ✨ Understanding how backend responses work is key to building real-world REST APIs. #SpringBoot #Java #BackendDevelopment #RESTAPI #WebDevelopment #DSA #LearningInPublic #SoftwareEngineering
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