Search code examples
spring-boothibernatespring-data-jpamicroservices

Running Hibernate in clustered mode


I am planning to use Spring Data JPA along with Spring Boot with MySQL server. What are the challenges, considerations and best practices when considering running multiple instances of Spring Boot applications connecting to the DB.

As I understand from my knowledge, Hibernate should be considered when it completely owns the DB which is good in case of building monolith applications, but in case of running multiple instances (Microservices), how will each instance manage, update the state. Please guide me.


Solution

  • Hibernate can be used for Microservices when there is no local state maintained in any of the service in the application. The state could be using a hibernate second-level cache. When you want to go for a second-level cache make sure it is centralized and available for all the services in the application.

    In fact this is a shared database pattern and using this pattern in Microservices architecture is absolutely fine. This is discussed in Microservices architecture patterns https://microservices.io/patterns/data/shared-database.html