r/SpringBoot • • Oct 19 '25

Question Production incident: Bean was not stateless

60 Upvotes

Hello everyone, I'm recovering from a major production headache caused by a classic Spring anti-pattern that was hiding in one of our service layers. The culprit was a singleton bean (@Bean / default scope) designed to abstract over our search instance. It unexpectedly contained an ArrayList instance field used internally by one of its methods. Unfortunately, neither tests nor code review pinpointed the issue.

Do you have any recommendations on tools, or other practices to avoid such issue? I think it is a pretty basic issue with Spring beans, yet I cannot easily find a way to automatically find it.

Thanks!


r/SpringBoot • • Aug 24 '26

How-To/Tutorial How I eliminated N+1 queries and scaled throughput by 20% on a production E-Commerce app

59 Upvotes

Just wanted to share a recent architecture win that might help someone dealing with latency spikes.

I was dealing with a severe bottleneck in a production E-Commerce platform. During peak traffic, the database was choking, and MTTR was creeping up.

The Culprit: Classic Hibernate N+1 query problems hidden deep inside the inventory/catalog mapping, combined with un-indexed foreign key lookups.

The Fix:

  1. Ripped out the lazy-loading proxy faults and replaced them with explicit JOIN FETCH queries for the critical read paths.

  2. Layered in Redis via Spring Cache (@Cacheable) specifically targeting the high-read/low-write catalog endpoints.

  3. Configured request batching and API rate limiting on the gateway layer to prevent thundering herd problems during flash sales.

Result: We dropped sub-100ms latency across the board and prevented database lockups entirely.

If you're building in Spring Boot and relying entirely on default JPA repositories—run a SQL profiler right now. You probably have an N+1 hiding somewhere.


r/SpringBoot • • Mar 07 '26

How-To/Tutorial Are people still using H2 for Spring Boot integration tests in 2026?

59 Upvotes

I've been seeing something repeatedly in Spring Boot services.

Integration tests run against H2 or some mocked dependencies. Everything is green locally and in CI.

Then the first real deployment runs Flyway migrations against PostgreSQL and suddenly things break. Constraint differences, SQL dialect issues, index behavior, etc.

The tests passed, but they were validating a different system.

Lately I've been leaning toward running integration tests against real infrastructure using Testcontainers instead of H2. The feedback loop is slightly slower but the confidence is much higher.

Example pattern I've been using:

- Start a PostgreSQL container via Testcontainers
- Run real Flyway migrations
- Validate schema with Hibernate
- Share the container across test classes via a base integration test

The container starts once and the Spring context is reused, so the performance cost is actually manageable.

Curious how others are approaching this.

Are teams still using H2 for integration tests, or has Testcontainers become the default?

For context, I wrote a deeper breakdown of the approach here:

https://medium.com/@ximanta.sarma/stop-lying-to-your-tests-real-infrastructure-testing-with-testcontainers-spring-boot-4-b3a37e7166b9?sk=532a9b6fb35261c3d1374b1102ece607


r/SpringBoot • • Mar 01 '25

Question Struggling to understand company code as a junior dev—Is this normal?

59 Upvotes

I recently joined as a junior backend developer at a company. During university, I built several projects using Spring Boot and felt fairly confident. But after just a week on the job, I’m completely overwhelmed by the sheer amount of code and files. It’s starting to feel like I don’t even know Spring or Java at all. Is this normal? How did you guys deal with this phase?


r/SpringBoot • • Feb 24 '25

Question How to understand Spring Security

58 Upvotes

Greetings!

This morning I had a backend interview for a company I really liked but I failed miserably to implement a session based authentication service using Spring Security as a first task of the interview. I spent the last week trying to learn and understand Spring Security docs but for the love of god I couldn't manage...

Do you guys have any recommendations of books, videos, courses, articles... to actually understand spring security and be able to implement different implementations (JWT, session based, oauth2...) after that? I find that the docs are quite hard to follow and that most resources online are from a few years ago and everything is deprecated...

I would really appreciate your help!

Best!


r/SpringBoot • • May 06 '26

News Spring Idempotency Kit [1.0.0]

57 Upvotes

Spring Idempotency Kit is a production-ready library that ensures methods execute exactly once per unique key — preventing duplicate operations in distributed systems.

Problem it solves: Retries, timeouts, and concurrent requests cause duplicate executions. Double charges, repeated orders, webhook duplication. This library eliminates that.

All you do:

@Idempotent(headerName = "Idempotency-Key")
public PaymentResponse processPayment(PaymentRequest request) {
    // Same key = same result, every time
}

The library handles:

  • Redis-backed caching — first request executes, retries return cached result

  • Distributed locking — concurrent duplicates are rejected or wait for the original to finish

  • Failure strategies — fail-open (keep running) or fail-closed (503 if Redis is down)

  • Built-in metrics — cache hits, conflicts, execution timing

  • Zero boilerplate — Spring Boot auto-configuration, just annotate


How It Works

  1. Client sends a unique key (header or derived from request)

  2. Cache hit → return immediately

  3. Cache miss → acquire distributed lock, execute, store result

  4. Retry with same key → returns cached result

Requirements

  • Java 21+

  • Spring Boot 3.4+

  • Redis

Links


Built by Atlancia Labs


r/SpringBoot • • Jan 04 '26

Discussion Built a Spotify-like backend with Spring Boot – Looking for feedback 🚀

57 Upvotes

TL;DR:
Built a Spotify-like backend using Spring Boot + JPA + PostgreSQL with songs, artists, albums, and playlists. Looking for feedback on architecture, service design, and ideas to make it more production-ready. Any suggestions welcome!

Hey everyone 👋

I built a music streaming backend (Spotify-style) using Spring Boot as a learning + portfolio project and would love some feedback.

SoundStream Backend Project

Tech Stack

  • Java 17, Spring Boot

  • Spring Data JPA (Hibernate)

  • PostgreSQL

  • Gradle, Postman

What it does

  • Manage Songs, Artists, Albums, Playlists

  • Many-to-Many & One-to-Many relationships

  • Create playlists, add/remove songs

  • Fetch songs by artist/album/playlist

What I want feedback on

  • Project structure & design

  • Service/repository layer quality

  • Should I switch fully to DTOs?

  • Features worth adding next

  • How to make it more production-ready

This project helped me learn real-world JPA issues (lazy loading, relationships, transactions).

Any suggestions or improvements are welcome. Thanks! 🙌


r/SpringBoot • • Aug 16 '26

Question As java dev , how to get relevant with AI, is spring AI worth it

56 Upvotes

Currently I am a student, my projects are In Java Fullstack

Right now I don't even know what RAG or MCP is , and I think I should have some hands on experience of it, i should be at least aware of it, because it's a trendy topic , not these two terms only, but many things

Now should I start python, for getting into it, is there any need , or I can explore Spring AI


r/SpringBoot • • Sep 13 '26

Question Pagination in Springboot

55 Upvotes

If you're ar working on springboot project in you company/job. How does your team do pagination in your project as they have large datasets. I am currently learning springboot and curious to know how it's done withel large datasets.


r/SpringBoot • • Jul 31 '25

How-To/Tutorial Complete testing strategy for Spring Boot applications (with code examples)

55 Upvotes

Just published a follow-up to my architecture post covering how I test Spring Boot applications at every layer:

What's covered:

  • Unit tests for value objects (fast, no Spring context)

  • Use case tests with in-memory repositories (no mocking needed!)

  • JPA repository tests with Testcontainers (real database confidence)

  • Controller tests with MockMvc (shows both mocked and real approaches)

  • Integration tests with API client pattern (reduces duplication)

  • Architecture tests with ArchUnit (prevents architectural drift)

Key insight: The testing strategy mirrors the DDD-based architecture - each layer has focused responsibilities and clear boundaries.

Real examples throughout using a pet clinic application. Addresses practical challenges like test maintenance and when to use different testing approaches.

The post emphasizes pragmatic trade-offs over dogmatic approaches. For example, when to use mocking vs real implementations in controller tests.

What testing patterns do you use in your Spring Boot projects? Always interested in different approaches to maintaining test quality as applications grow.

https://www.wimdeblauwe.com/blog/2025/07/30/how-i-test-production-ready-spring-boot-applications/


r/SpringBoot • • May 27 '25

Question Is learning spring boot is good in 2025??

55 Upvotes

Please help me , I am already completed some topics in spring boot like security,spring data jpa and done one project using spring boot. Some on tell me whether I need to go deeper in spring boot like spring ai,spring cloud and microservices Or i need to learn new technologies like python,ml. Currently I'm BTech 4 th year student Because I am having doubt regarding spring boot opportunities


r/SpringBoot • • Mar 27 '25

Question Any good unique project ideas for Java spring boot API ???

55 Upvotes

I am a junior java dev and I want to make a switch to another company but for that I need good projects and my old projects are like a student management system.

I want to make something that will help me learn new things and will also look good on my resume.

Please give me your suggestions since I don't have any idea on what should I make.


r/SpringBoot • • Oct 27 '26

Discussion Optimizing Spring Boot on JDK 27: 68% faster startup and 25 MiB less RAM on a 512 MiB VM

54 Upvotes

I've been experimenting with how far I can optimize a conventional Spring Boot application without stripping out useful framework functionality.

The setup: Spring Boot 4.1.1, HotSpot JDK 27, a 512 MiB / 1 vCPU Ubuntu VM with no swap, and MariaDB running on the same VM.

I compared a regular executable JAR against an extracted deployment combining Spring AOT and a trained JDK AOT cache (Leyden).

Results:

  • Startup: 11.91 → 3.79 seconds (68% faster)

  • Application RSS under load: 212 → 187 MiB

  • Minimum host MemAvailable: 25.6 → 66 MiB

  • Request latency: essentially unchanged

Then I explored two ways to reduce memory further:

MyBatis Core instead of Spring JDBC: No meaningful memory savings, but more manual transaction management and lost automatic JDBC monitoring. Not worth the trade-off for this application.

Embedded file-backed H2 instead of MariaDB: Application RSS increased by ~16 MiB, but minimum host MemAvailable improved by another ~39 MiB because the separate database process was gone.

My takeaway: optimizing the deployment can be worthwhile before replacing established Spring infrastructure. And for small, single-instance applications, embedded H2 can be a reasonable architectural choice.

These are single runs with five-minute measured workloads, not a throughput benchmark or proof of long-term stability. The AOT improvements were measured together, not individually.

Full article, methodology, and data:
https://pvrlabs.xyz/articles/spring-boot-jdk27-optimizations.html

Curious whether others are using Spring AOT + JDK AOT cache in deployments, or if the training and cache-management overhead has kept you on regular JARs.

Update (October 28): Following several requests, I also tested Oracle GraalVM Native Image. Application RSS dropped from 187 MiB to 107 MiB, with some interesting build-time and toolchain trade-offs.

I published the results as a separate article: https://pvrlabs.xyz/articles/spring-boot-hotspot-native-image.html


r/SpringBoot • • May 19 '26

Question What is the most common way of implementing JWT?

54 Upvotes

Throughout the internet I see a lot of libraries for everything, and my question to you is - what is your way of implementing JWT authentication?


r/SpringBoot • • Mar 03 '26

Question Is it worth

Post image
54 Upvotes

r/SpringBoot • • Feb 02 '25

Discussion SpringBoot backend project ideas.

54 Upvotes

Hi everyone. I need some great "resume-worthy" project ideas based on spring boot. My resume is not getting shortlisted anywhere, so I guess it's due to my projects. Can anyone share some ideas? Thanks.


r/SpringBoot • • Jan 24 '25

Guide Improve 1% a day

54 Upvotes

I finally decided to take seriously up SpringBoot (bc I do love Java and its robustness) and I decided to do the obvious: watching tutorials. Obviously a CRUD to do list. Then, I realized that instead of watching tutorials all day long, as I do on my daily job (mobile application developer but interested in BE), I will simply make my hands dirty and improve this shitty todo list implementing more features and more styling (React at first) and will explore from there. The aim is not to developer the next Facebook, but to consolidate and strengthen my knowledge. My ideas, so far, are to use obv authentication, RESTful APIs, using different DB and playing with docker&kubernetes and then putting in the cloud.

The pathway is not easy, but all marathons start with the first step.


r/SpringBoot • • Jun 30 '24

Feedback on my Spring boot project (Have around 2 years of experience in Java Backend).

54 Upvotes

I have been working on a Spring boot application for quite a while, and I'm reaching out for some feedback from the community. I haven't had a chance to discuss it with anyone yet, and I'd love to get some fresh perspectives.

What I'm looking for

  • Architecture: How well-organized is the code? Are there any areas for improvement in terms of design patterns or best practices?

  • Missing features: Is there any core functionality that you think is missing from the application?

  • Existing issues: Have you spotted any bugs or potential problems in the code?

  • Interview talking points: What features or functionalities would best showcase my 2 years of experience during a Spring Boot interview?

Open to collaboration!

If anyone is interested in taking a look at the code and potentially collaborating, I'd be happy to chat.
Project Link


r/SpringBoot • • Aug 22 '26

Question How do you handle money and currency in your Spring Boot applications?

53 Upvotes

I’m building my first application using Spring Boot for practice, and I need to record and work with money in different currencies.

What’s the recommended way to handle this, especially when adding or calculating amounts across different currencies? Do you use BigDecimal, integers (like cents), or a money/currency library?

Thank you!


r/SpringBoot • • May 07 '26

How-To/Tutorial Migrating a production SaaS (25k users) from Node.js Serverless to Spring Boot — lessons from week 1

53 Upvotes

I run MoWave One, a productivity SaaS that recently crossed 25,000 users. Built initially on Postgres + Auth + Node.js Serverless Functions.

After 8 months and a growing user base, the serverless functions started feeling cramped — no proper domain modeling, awkward testing, no module boundaries, and one of them was literally a stub that I'd forgotten to finish (yep, our Stripe webhook).

Decided to migrate the backend to Spring Boot 3.4 + Java 21.

Stack:

- Spring Boot 3.4 + Java 21 LTS (Corretto)

- PostgreSQL via JDBC (HikariCP)

- Spring Security 6 validating JWTs via JWKS

- Flyway 10 for schema migrations

- Redis (Valkey) for webhook idempotency

- Modular monolith with Hexagonal Architecture

Some early lessons:

  1. The Stripe API moved current_period_end from Subscription to SubscriptionItem in December 2024. If your Java code worked with stripe-java 28.x and broke with 29.x, this is why.

  2. Pessimistic locking matters for XP/counters at this scale. A double-click on "complete task" can race two transactions. SELECT ... FOR UPDATE on the user row eliminates the issue.

  3. Resist the urge to migrate everything at once. I have a PL/pgSQL function (update_rhythm) that computes a weekly score across 4 tables. Three of those tables aren't migrated yet. So the Spring service calls the SQL function via JdbcTemplate for now. When the underlying modules are migrated, this gets rewritten in pure Java.

  4. Spring Data Redis warns about JPA repositories it can't classify. Solution: explicit u/EnableJpaRepositories(basePackages=...) on your u/SpringBootApplication. Took me a while to find this.

I'm 4 modules into a 16-module migration managed via Maven. Happy to answer questions about the architecture, the migration approach, or anything Spring-related.


r/SpringBoot • • Oct 06 '25

Discussion Java 25: The Ultimate Developer Upgrade (Finally, Java Gets Its Act Together!)

Thumbnail
medium.com
53 Upvotes

r/SpringBoot • • Dec 19 '24

Even after lombok dependency and plugin i cant use get getters from the class

Post image
53 Upvotes

r/SpringBoot • • Aug 22 '26

Question Sorry for being a crybaby but......(F22)

52 Upvotes

I am just lost, I know REST APIs, JPA, Authentication and Authorization, microservices, postgres....I can do something in it (not very confident tho but still)

I just dont know what more to learn for being industry ready, I feel so lost, I am doing DSA(LEETCODE 75) parallely but again I am not seeing any thing for freshers in the domain of spring boot

I mentioned my age because I feel I am lagging behind a lot


r/SpringBoot • • Jun 18 '26

Question Dto Mapping Best Practice

52 Upvotes

Hi, where do you guys map your entities to dtos?
In services or controllers?

To me it seems the services shouldn't expose any database specifics to the outside world, so I usually do my mapping there.

But what is considered best practice and why?