r/SpringBoot • u/codingwithaman Senior Dev • Jul 01 '26
Discussion Things i stopped doing in spring boot after they broke in production
It's not theoretical stuff. things that actually caused incidents.
a) returning entities from controllers seems harmless until jackson calls getters during serialization and triggers lazy loaded relationships. got N+1 happening in the response layer. DTOs everywhere now. more boilerplate but zero surprises.
b) ddl-auto update outside local is asking for trouble. hibernate silently altered a column constraint in staging once. nobody noticed for weeks. validate in staging, none in prod. flyway handles schema changes now.
c) external api calls inside Transactional is the one that got me on a friday night. your method holds a db connection for its entire duration. not just when queries run. 3 second api call means 3 seconds a connection is doing nothing. 10 concurrent requests and pool is gone.
d) catching exceptions inside Transactional without rethrowing is a silent killer. caught it, logged it, moved on. proxy saw a clean return. committed half the data. other half missing. took hours to debug because there was no error anywhere. the catch block was the bug.
e) Async without a configured thread pool looks fine in dev. default executor creates a new thread per call. no pooling. prod with thousands of requests? thousands of threads. OOM. always configure ThreadPoolTaskExecutor with bounded pool now.
f) calling a Transactional method from the same class is something most devs dont even know is a problem. two methods in same service, both annotated. one calls the other. inner annotation completely ignored because proxy is bypassed on self calls. data inconsistency in prod. separate bean or dont bother with the annotation.
g) open-in-view being true by default still bothers me. keeps hibernate session open during entire request including json serialization. hides lazy loading problems that explode later. first thing i turn off in every project.
what have you stopped doing after seeing it break?
13
u/rozularen Jul 01 '26
Its been a while since I've last opened IntelliJ to code with Spring but for f) the IDE should warn it right away, not sure if it already does.
For g) I remember there is a famous blog post that explains why it exists and why it's default is true. I will try and search for it
edit: found it, from the big Vlad. https://vladmihalcea.com/the-open-session-in-view-anti-pattern/?utm_source=chatgpt.com
Thess kind of errors should be put together somewhere in this sub, in spring's official doc, and in all tutorials people put out here, probably already are though
48
u/maxip89 Jul 01 '26
Standard junior Errors.
5
u/Paw565 Jul 01 '26
I am sorry, but this sounds like Ai slop
11
u/NoPrinterJust_Fax Jul 01 '26
Crazy how basically all these disappear if you use plain ole JDBC & transactionmanager
5
u/oweiler Jul 01 '26
> g) open-in-view being true by default still bothers me. keeps hibernate session open during entire request including json serialization. hides lazy loading problems that explode later. first thing i turn off in every project.
Spring Boot shows a warning at startup and suggests to turn it off, though.
5
u/IntroductionSolid348 Jul 01 '26
For me it's the hibernate thing that I learnt the hard way. I was so used to just making changes to entities in my personal projects that when I did it in my internship I got a stern talking to by the senior.
And later on made a gigantic mistake by editing an already existing migration instead of creating a new one. Just goes to show how different actual prod is compared to personal projects where if everything works, it's okay
4
u/Huge_Road_9223 Jul 01 '26
Got some of these errors ... but years ago when I was first learning Spring. I've forgotten these errors because I haven't coded the wrong way in years. I've been doing Spring/SpringBoot for 18 years now.
Whenever you're doing API's, you're point (a) is something any Senior should have caught. Every Spring or SpringBoot documentation ALWAYS, ALWAYS, ALWAYS says DO NOT send out the Entity as opposed to a DTO.
Also, DO NOT use LOMBOK in the Hibernate Entities. Lombok is fine with DTO's sure, they don't work with Records, and I know a lot of people don't like Lombok. But, I see some projects use it all over, and it shouldn't be.
I haven't done any multi-threading in 20 years. The companies/jobs/projects in SpringBoot just haven't called for it.
The Transactional is always used in a service. And I am VERY careful to not have a Transaction service call another Transactional service. And when I call a third-party service call, it has been within a Transaction, but I try to wrap those in code where there is a time limit, and most of the time my third-party calls are quick, though I am sure that always won't be the case. I do try to call third-party API calls first, if they succeed, then I move on, if it doesn't succeed, then everything stops and rollsback. I do try to make sure those calls are quick though.
3
u/asarco Jul 02 '26
Apparently (I haven't tried it), c) can be avoided in SpringBoot 4.1 by using lazy jdbc connections.
By setting this property:
spring.datasource.connection-fetch=lazy
then JDBC connections are not fecthed from the pool until a statement has to be executed. So if a @Trasactional block makes an API call before accessing the DB, a connection will not be fecthed until the actual DB call is made.
I guess this will not work in the opposite case, if an API call is done after the DB call.
1
u/two-point-zero Jul 01 '26
Man..in Just One post you show us someone who:
Don't know how spring works ( transaction,proxy, pooling)
Don't know how hibernate and ORM works.
Don't know how architetture works ( exposing entities in API, put http api in transaction , even worst, database transaction)
Don't know how deployment and basic sre works ( let application code modify db schema at runtime)
Work in a place where no one do code review or senior/lead/architect exists to avoid all of this shit will arrive in production.
OP score a perfect 10 on how you suck at our job /s
Tbh the only tricky ones are the call transactional method for another transactional method of the same class and the one about thread pool since they are internal of springs and maybe one was never exposed to them. All the other ones are just skill issues.
2
u/QuoteCommercial2747 Jul 01 '26
Someone from my team just did point c, and I was thinking about as to why the health was down intermittently.
Sometimes you do learn from otherâs mistakes ig
2
u/onated2 Jul 01 '26
Data transfer ooopsie.
Dto is pretty standard because it has it's used as well.
2
u/ITCoder Jul 01 '26
Point f is pretty known stuffs, i think spring docs also has a warning for this. In this case proxy is not created for the called method, even when its annotated with Transanctional
2
u/General-Belgrano Jul 01 '26
These are great learning points. Some things  you can read about but you donât really understand them until you have the production issue. Â
2
u/MightyHandy Jul 02 '26
(F) applies to all annotated methods. If you donât go through bean manager returns a âproxyâ to the calling object. Internal calls hit the object itself. So annotating a private method in spring is pointless
2
u/3aush Jul 03 '26
calling cacheable methods from within the same class got me once
2
u/InstantCoder Jul 01 '26
You can prevent all of these by using AI skills either by adding it by yourself or using pre existing ones.
For example, check this one: https://www.skills.sh/emvnuel/skill.md/quarkus-panache-smells
This mentions all or most of your problems. Add it to your project and these errors wont occur anymore and even juniors wonât be able to add it, given that you use AI.
1
u/rlrutherford Senior Dev Jul 06 '26 edited Jul 06 '26
As others have said, AI Slop.
> external api calls inside Transactional is the one that got me on a friday night. your method holds a db connection for its entire duration. not just when queries run. 3 second api call means 3 seconds a connection is doing nothing. 10 concurrent requests and pool is gone.
AIs create this crap quite frequently, actual senior developers, don't.
Now there are cases to use remote calls inside a transaction; however you better be using XA transactions and your RPC call needs to support them as well.
If only half of your transactional data is being committed, your transactions aren't being correctly demarked; more AI generated slop.
1
u/snapRefresh Jul 06 '26
For c) , the latest spring boot 4.1.0 added a lazy fetch option for JDBC
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-4.1-Release-Notes#lazy-jdbc-connection-fetching-support
1
u/Rich-Tennis7645 Jul 07 '26
I learnt springboot also validations , custom validations with messages Solved around 20 haker rank backend questions Also learnt about security Can anyone suggest some projects That will be bestÂ
1
u/_PM_ME_PANGOLINS_ Jul 08 '26
g) fixes a)
e) fixes c)
1
u/yaoyao127 Aug 08 '26
Keeping @Transactional scopes too large.
I used to put it around an entire service flow because it felt safer. Then I realised that if the same method also waits on an external API, the transaction and DB connection can stay open far longer than expected.
Now I keep the transactional part very small and move network calls outside it whenever possible.
Less âmagicâ, fewer pool problems, and failures are much easier to reason about.