7 ms·
Spring Boot Done Right: Lessons from a 400-Module Codebase
- sidcool 6mo agoHacker news likes to dunk on Spring Boot, but its usage in enterprises is very very high.
- fiftyacorn 6mo agoit saves a lot of reinventing the wheel
- rockyj 6mo agoAnd at the same time, gives you a dozen of footguns. This is just a list for the gotchas in the "@Transactional" annotation - https://dev.to/closeup1202/8-spring-transactional-pitfalls-that-break-production-and-how-to-catch-them-all-258f https://dev.to/closeup1202/8-spring-transactional-pitfalls-t... Now read up on all the dozen of annotations. But yeah, we did not want to "re-invent the wheel".
- fiftyacorn 6mo agoIm comparing against node equivalent ORMs and find spring consistently better. Yeah ive got to read up on annotations - but when it comes to transactions its always worth revisiting them to check for changes
- tracker1 6mo agoMeh... await using cn = await pool.connect(); const records = await cn.query<MyType>` SELECT ... FROM ... WHERE ... `; for await (const record of records) { ... } Oh, spring is so much better...
- throwawey1234 6mo agoSpring version: var records = jdbcClient .sql("select * from posts") .query(Post.class) .toList(); records.forEach(p -> ...);
- tracker1 5mo agoI'm not seeing a RecordsRequestFactoryHandlerProviderFactory in there... maybe it's not as bad as I remember.
- throwawey1234 6mo agoHalf of those are not really an issue with the annotation and seem a bit contrived. Thankfully the company that wrote the article has a linter/warning product to help avoid those pitfalls.
- tonyedgecombe 6mo agoYes but enterprise software is some of the worst software you will encounter.
- geodel 6mo agoHuh, Enterprise usage of Blackberry was very very high and then it was not. And at one point SOA, SOAP/WSDL/XML usage was very very high and now I am told in my very enterprise job I'd be fired if I dared bring those names up. Usage being high doesn't say anything about quality or suitability of a product specially in enterprise settings.
- sidcool 6mo agoHonestly, it does. Enterprise software does need high reliability.
- nilamo 6mo agoI'm not that deep into Java, but I was under the impression that things like Quarkus were starting to replace Spring in enterprise use...
- theflyinghorse 6mo agoIt will take some time for Quarkus to become a significant enough presence in the market share. In my experience, for the majority of Java shops Spring Boot does just fine because it worked before and it will probably work in the future.
- nogridbag 6mo agoWe have a medium sized Quarkus app (~200kLOC) and Quarkus has been fantastic. Startup in JVM mode for our app is around 10 secs. Not blazing fast - but likely much faster than a typical Java enterprise app. I'm sure a few of those secs are spent doing things like pulling authz policies from github or due to having several thousand hibernate entities.
- sidcool 6mo agoQuarkus, Micronaut etc. are doing well. But Spring Boot is the giant of Java ecosystem.
- dukeyukey 6mo agoEven in startups, lots of places are on Spring Boot (albeit more often using Kotlin over Java).
- bberrry 6mo agoMy favorite stack, Kotlin with Spring Boot. A real delight to work with
- dzonga 6mo agoit doesn't mean that usage of something being very high is a clever idea. lots of people take meth - so are you gonna take meth too. ```@EnableConfigurationProperties(CasConfigurationProperties.class) @EnableScheduling @ConditionalOnFeatureEnabled(feature = CasFeatureModule.FeatureCatalog.SimpleMFA) @AutoConfiguration @Import({ CasSimpleMultifactorAuthenticationComponentSerializationConfiguration.class, CasSimpleMultifactorAuthenticationConfiguration.class, CasSimpleMultifactorAuthenticationEventExecutionPlanConfiguration.class, CasSimpleMultifactorAuthenticationMultifactorProviderBypassConfiguration.class, CasSimpleMultifactorAuthenticationRestConfiguration.class, CasSimpleMultifactorAuthenticationTicketCatalogConfiguration.class, CasSimpleMultifactorAuthenticationWebflowConfiguration.class }) public class CasSimpleMultifactorAuthenticationAutoConfiguration { }``` this is what we mean by "JavaCulture" - java | JVM really wonderful things but the culture is what sets these things back someone can't just go in and understand things - they have to understand a bunch of notations too. then if you work at a place and try do things differently the same people will tell you to revise your PR cz it ain't software engineering (or it won't scale)
- mindcrime 6mo agoThat's a ridiculously extreme example, IME. Having been working with Java for 25+ years, I've never seen anything like that in code written by a shop I worked at, FWIW. And as a corollary I'm about 100% certain that you could find some equivalent extreme case to use as an example to dunk on any language/platform. this is what we mean by "JavaCulture" - java | JVM really wonderful things but the culture is what sets these things back Maybe there are still some Java shops out there living like this. But to me, this is a 20 year old outdated notion. shrug
- theflyinghorse 6mo agoYou have worked at some outstanding java shops then! In my experience the article is precisely representative of Java culture even today
- mindcrime 6mo ago
- the_gipsy 6mo agoCuisine Magazine likes to dunk on McDonalds, but its the most popular choice of dining.
- smrtinsert 6mo agoAnd startups not in the SV echo chamber. They happily exist and make money without worrying about supply chain attacks and js engine of the week.
- robmccoll 6mo agoDoes this app take 5 minutes to start? That's so much dynamic Spring magic. Also, how do you keep track of control flow when anything at anytime could have been overridden by something else? It seems like tracing and debugging this thing would be like exploring someone else's codebase every time.
- switchbak 6mo agoThe class loading magic means you need to be exceptionally careful about things that would otherwise be very innocuous. It’s the rule, not the exception - that your average spring boot app will be doing tons of expensive stuff at startup. Most of which is unnecessary and was not even intended. The JVM doesn’t need this kind of thing either, and it gets a bad wrap from the J(2)EE days, and the “simple” replacement that Spring was supposed to be. No doubt there’s some benefits to be had, but I don’t think the trade-offs are worth it, especially at larger scales.
- smrtinsert 6mo agoThe article talks about a specific solution they came up with. No way is this a representative example, they discard a typical pattern way at the top.
- krzyk 6mo agoWho cares about startup times if apps is started only when new version is deployed? And 5 minutes is a bit long, maybe someone is doing some database operations during start?
- robmccoll 6mo agoI care because every second of that startup time is lost productivity and focus. For me and any developer on my team. Hot reload only works if no class or method has changed so that's not a solution. I've worked on codebases of similar size and complexity in many languages, and the developer experience of a compile and restart that takes less than five seconds is game changing.
- 6mo ago
- faangguyindia 6mo agoI recently inherited java code base. Just rewrote it in Go. Now we are using a server which consumes 30% of ram what the existing one used to and the latency and throughput have all improved. Don't use these stupid java backend like sprinboot.
- ludovicianul 6mo agoI wouldn’t reduce it to don't use Java/Spring Boot. Rewrites often (not always) look great because they remove years of accumulated complexity, not because the original stack was inherently bad. Just rewrite it in X doesn't "just work" for complex systems. It ignores risk, and the fact that design usually matters more than language.
- faangguyindia 6mo agoi made 1 to 1 copy, not sliming anything.
- iririririr 6mo agousually what you say is correct. but in case of entreprise java, just look at the article. you have no way of knowing or controlling which essential class your application will be running because some intern merged a similarly named class two hundred levels down in the codebase and now that is handling all your db queries. and it's not a bug but a highly praised feature. it's useless abstractions for the sake of useless abstractions. java was designed so that american architecs could write a few interfaces and cheap workforce overseas could implement the actual code. and the EE stuff evolved in a way that features could be shipped just by adding a new component that would inject itself in the right places. java "engineers" have no idea how http or cookies work, but they know where to load the spring-auth bean in a 2mb maven config. so, any rewrite from java is an exception to the rewrites are only good because you cleaned up old features rule.
- stackskipton 6mo agoOps person here who has supported Java/SpringBoot applications. I think most of dislike of Java apps comes not from language or framework BUT from fact that most Java using workspaces are filled with mediocracy. They tend to be businesses with products that have extreme moats and thus quality of software barely matters. I imagine most people who would even read this medium article are dreaming of better than that.
- ecshafer 6mo agoI 100% agree. I have seen enterprise spring applications that throw away all of the speed through huge amounts of hot path object creation, nested loops, absurd amounts of factories, etc. After going through enough AbstractFactoryFactory calls to make object in an n^3 loop, the framework doesn't matter.
- switchbak 6mo agoThere really is an unlimited potential for crappy code in the enterprise. I imagine the volume will increase drastically in the age of AI.
- the_arun 6mo agoUsually languages are not the issue. It is the code that we write. As long as languages help us to find/debug a problem caused by crappy code - we should be good. Coding is kinda creative work. There is no standard to measure creativity or pitfalls of using wrong patterns. The incidents & RCAs usually find these. But most of the times it is already too late to fix core problem.
- tracker1 6mo agoNot sure that I agree... I think some of the worst AI code I've had to deal with and the most problematic are when dealing with Java or C#... I've found TS/JS relatively nice and Rust in particular has been very nice in terms of getting output that "works" as long as function/testing is well defined in advance.
- e7h4nz 6mo agoI worked on a core Spring Boot project for five or six years at a very large enterprise. In my opinion, the most dangerous thing about this framework is that it makes its core users feel far too self-assured. When looking at problems, your mind becomes consumed with how to force everything into design patterns—like architectural separation, DI, or interface / implementation split. This causes developers to lose sight of the actual essence of the problem because they are obsessed with conforming to the framework. Because the ecosystem and toolchain surrounding Spring Boot and Java are so mature and well-supported, it is very easy to find community tools that make you feel like you are doing things the "right way." I only realized these issues after I left Spring Boot and Java development behind. Now, I much prefer using TypeScript or Python to write code (for example, web servers). I also prefer using various SaaS solutions to handle authentication and user registration rather than rebuilding it all myself with Spring Boot Security. I honestly never want to go back to the days of writing Java again.
- ecshafer 6mo agoI like Java fine. I would probably prefer Ruby, Rust or LISP given the chance. But I can't disagree with anything you say. So many Java enterprise shops have absurd inheritance and "design pattern" abuse that makes it harder to actually work with the code, and slows things down.
- e7h4nz 6mo ago[dead]
- tracker1 6mo agoSimilar for C# in practice... I actually really like a lot of modern C#, though I use FastEndpoints as an (imo) upgrade to minimal API surface, generally with Dapper and as few layers as possible in a feature oriented structure (single project as long as possible). I had to split off some logic into a separate shared library and worker service app from the api app on the server. Client is a React SPA.
- cogman10 6mo agoSpring is such a massive framework and it definitely has parts that aren't, frankly, well done. More than once Spring has ultimately been the source of performance issues for us with the solution being to ditch spring and do things with just the JDK. A lot of those cases have been fixed, however, even in the best case spring will take something that could have been a single function call and turn it into a maze of 20 different function calls because it's handling all sorts of weird edge and corner cases that aren't applicable to your code. It also doesn't help that some things are simply bolted in which makes it even harder to understand what is going on under the covers. It also doesn't help that it's really easy to end up bringing in the entire framework for what you assumed were single function portions of the framework. That said, it's the framework you probably want to use if you are doing Java. Just not if you are doing fast java.
- moondowner 6mo agoSwitched from Spring Boot to Ruby on Rails 3 years ago. I expected to see some new Spring 'tricks' in this post, but it's pretty much regular things that people might do in larger codebases.
- fpauser 6mo agoBodyless classes only for carrying annotations... too much magic for my taste.
- dknj 6mo agoThat's fair - it does look odd in isolation. But the alternative is mixing "should this load?" conditional logic with "what should load?" bean definitions in the same class. When you're debugging why a feature didn't activate across 272 entry points, having one place to look at - just the annotations on an empty wrapper - beats scanning through 200 lines of bean definitions hunting for the one @Conditional that blocked everything. It's not magic, it's separation of concerns applied to auto-configuration. Looks weird, works well.
- jillesvangurp 6mo ago- Swap out Java for Kotlin. The Spring guys won't officially drop support for Java; but a lot of their recent releases are becoming very Kotlin centered. Seriously, it's much nicer to use from Kotlin. I've done both. - Go for declarative Kotlin DSLs over annotation magic for most things. Much easier to debug. It's just function calls. And DSLs are nice in IDEs with autocomplete. - Keep it simple. It's a huge framework. But you probably don't need most of it. - Don't go Spring everything, a lot of stuff in Spring is a bit experimental (Spring AI/MCP stuff) or a bit bare bones (Spring Data, it's a limited and extra level of indirection you mostly shouldn't need) or flat out misguided/over-engineered (Spring Batch, good alternatives are available for that). - Decide on synchronous or asynchronous IO. The former is a lot more scalable now that Java has green threads. The latter is relatively painless from Kotlin but an absolute PITA from Java. They are very different internally and both have their pros/cons. If you need async, Kotlin co-routines is the easier path to do that. Either way, it's one of the bigger decisions to take. - Don't copy their way of deeply nested inheritance hierarchies. Very much in fashion 20 years ago; a bit of an anti pattern now. Internal code complexity is the part I like least about Spring. And it has some really byzantine stuff in there with 5-6 levels of inheritance or worse.
- exabrial 6mo ago> What makes the CAS codebase impressive is the discipline of applying all of them consistently, across 400 modules, for years. I think this is the main point. You can write good code in any language following this concept.
- dknj 6mo agoThat's really the whole thesis. None of the patterns in the article are clever or novel - @ConditionalOnMissingBean has been in the Spring Boot docs since day one. What's hard is getting a team to apply it on every single bean, in every single module, for years, without anyone cutting corners. Discipline scales. Cleverness doesn't.
- exabrial 6mo ago100%
- mergeshield 6mo ago[flagged]
- EricRiese 6mo agoI wonder how many of these rules can be enforced with static analysis and ArchUnit.
- dknj 6mo agoGood question - quite a few actually. @ConditionalOnMissingBean on every public @Bean method, proxyBeanMethods = false on every @Configuration class, the thin wrapper pattern (auto-config classes must have empty bodies) - those are all structurally checkable. CAS doesn't use ArchUnit specifically, but the consistency you see in the codebase didn't happen by accident. The patterns that can't be easily enforced statically are the harder ones - like making sure every module contributes to shared capabilities through the configurer pattern instead of direct coupling. That's where code review discipline fills the gap.
- swisniewski 6mo agoThere is no right way to do Spring Boot.The entire idea is broken. Dependency injection is good. It makes it possible to test stuff. Automagic wiring of dependencies based on annotations is bad and horrible. If you want to do dependency injection, you should do it the way Go programs do it. Create the types you need in your main method and pass them into the constructors that need them. When you write tests and you want to inject something else, then create something else and pass that in. But the idea that you create magic containers and then decorate packages or classes or methods or fields somewhere and then stuff suddenly gets wired into something else via reflection magic is a maintenance nightmare. This is particularly true when some bean is missing, and the one guy who knows which random package out of hundreds has that bean in it is on vacation and the poor schmucks on his team have no clue why their stuff doesn't work. "I added Spring Boot to our messy Java project." "Now you have 3 problems."
- andor 6mo agoManual dependency injection is fine, but it doesn't scale. Especially when you start refactoring things and dependencies need to be moved around. The other issue is dynamic configuration. How do you handle replacing certain dependencies, e.g. for testing, or different runtime profiles? You could try to implement your own solution, but the more features you add, the closer you'd get to a custom DI framework. And then you'd have an actual mess, a naive non-standard solution for a solved problem, because you didn't want to read the manual for the standard implementation. By the way, Spring dependency injection is mainly based on types. Annotations are not strictly necessary, you can interact with the Spring context in a procedural/functional manner, if you think that makes it better. You can also configure MVC (synchronous Servlet-based web) or Webflux (async web) routes functionally. When a bean is missing, the app will fail to start, and you will get an error message explaning what's missing and which class depends on it. The easiest way to ensure this doesn't happen is to keep the empty @SpringBootTest test case that comes with the template. It doesn't have any assertions, but it will spin up a full Spring context, and fail if there is a configuration problem. The only complicated part about Spring Boot is how the framework itself can be reconfigured through dependency injection. When you provide a certain "bean", this can affect the auto-configuration, so that other beans, which you might expect, are no longer automatically created. To debug this behavior, check out the relevant AutoConfiguration class (in your IDE, use the "go to class" shortcut and type something like FooAutoConfi..., e.g. JdbcAutoConfiguration). In a good codebase, the configuration itself would be tested. For instance, if you did something a bit more complicated like connecting two JDBC databases at the same time, you would test that it read the configuration from the right sources and provides the expected beans.
- allador 6mo agoKeep in mind that a big part of the configuration complexity of CAS is because of how it's used and customized in the real world. These kinds of infrastructure systems its very common to replace a bunch of the built in functionality with your own classes, and so there's alot of effort put into supporting that use case. I helped build a large open source enterprise financial systems, and most of the deploying orgs used CAS for authN. Both CAS and the financial system was built with similar approach to extensibility.
- dknj 6mo ago[dead]
- dlandis 6mo agoThere's a lot of good ideas in Spring and there have been some outstanding engineers working on that framework over the past ~25 years. But it has accumulated so much baggage and relies on and perpetuates so many patterns that simply don't make sense anymore... I would love to see what the team would do with a fresh start. I wonder if they have or are considering doing a complete rewrite or starting something totally new for the next generation that will take us through the next 25 years of Java.