Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to maintain same Spring Boot version across all microservices?

I am creating one application using microservice architecture. I was wondering if we can manage the same Spring Boot version across all microservices. I just don't want to mention Spring Boot version in pom.xml while creating new microservice. If we can manage Spring Boot version at one location then It will make sure all microservices are using the same Spring Boot version and It will be easy to upgrade it for all microservices.

How to manage it if It is possible?

Is it a good practice?

like image 336
Sarvesh Avatar asked Sep 21 '25 10:09

Sarvesh


2 Answers

If you really wanted to do this, you could use Maven to build your separate applications (microservices), using a parent POM and Maven's Dependency Management feature (Dependency Management is not the same as Depdencies) to control which version of Spring Boot to use.

However, you should not strictly require that all the microservices use the same version of Spring Boot. If you do that, and one of the microservices must use a newer version of Spring Boot (because it has a crucial new feature, for example), you are forcing all the microservices to be updated at the same time. One of the key benefits of microservices is that each microservice can be built, updated and deployments upgraded somewhat separately, so you would be depriving your system of that benefit.

Done properly, however, this can give you the best of both worlds.

  • Old microservices can continue to use an old version of the parent POM.
  • New and updated microservies can use a new version of the parent POM.
  • It is easy to see if a microservice uses a (very) old version of the parent POM and so should be updated.
  • The current version of the parent POM can indicate which versions of dependencies you regard as "best practice" to use.

However, do not be tempted to use a multi-module Maven structure, because then you will force the microservices to use the same Spring Boot version, which introduces too much coupling in the building of each microservice.

like image 67
Raedwald Avatar answered Sep 22 '25 23:09

Raedwald


While it is true that "independence" is an important value in a microservice landscape, this does not mean rampant code duplication is preferred. Choose the lesser of two evils and create a parent project which contains only a pom file (no java code) and let all microservices use this pom as its parent pom. In this parent pom file you can declare all versions of all dependencies using the <dependencyManagement> tag and all versions of the plugins using the <pluginManagement> tag. These tags don't actually add any dependencies or plugins to your actual project, it just declares the versions to use if the project were too actually depend on them.

If you are using the spring-boot-starter pom as your parent already, this can work transitively: your microservices have your parent pom, and your parent pom has the spring boot starter pom as its own parent.

If at some point in the future one microservice needs to diverge from this parent pom for one or more particular dependencies, you can declare new version in that project's pom and those values will be used instead, effectively overwriting what is declared in the parent pom(s), so you don't lose this flexibility.

However, we've been working with the spring boot microservices for two years now and keeping the landscape consistent and easy to upgrade simultaneously has proven to be more valuable to us than having independence.

like image 27
user1884155 Avatar answered Sep 23 '25 01:09

user1884155