Search code examples
javaspring-bootmicroservicesone-to-manymany-to-one

Is it necesary to use ManyToOne/OneToMany annotations on microservice arquitecture projects with Spring boot?


I'm creating this project were i have to create views using different entities from different schemes, as microservices do. It is my first microservice project. Is it necessary to use those relations annotations, even when i have to cross info manually with the rest controllers?


Solution

  • I think the best answer is it depends. And there is no right or wrong answer.

    Basically a microservice encapsulates the business logic specific to a domain (order, email, user, etc).

    Generally speaking it is a good idea to have a separate database for each microservice in order to have better decoupling.

    If that database, for a clear reason, is a relational database (it can be any database) and the JPA is becoming helpful (defining relations, having transactions, etc.) then you should definitely use them. An alternative could be to use directly the JDBC.

    In a microservice architecture you basically lose the transactionability and to achieve a something similar is by far more difficult.

    Keep in mind that microservices add a lot more complexity to your projects, in all aspects.

    With this context in mind, coming back to your question, you should use it if you need it.