Home > OS >  How to handle many to many relationship in microservices?
How to handle many to many relationship in microservices?

Time:11-24

i'm learning microservices and i'm not sure how to solve problem when it's many to many relationship. This is my entities:

Movie
private long movieId;
private long name;
private Date releaseDate;

Genre
private long genreId;
private long name;

I am using schema per service pattern and currently they are separated microservices and don't have any relationship between them. For me two things come to mind:

  1. Create third microservices which will be used as a junction and provide communication between microservices.
  2. Put Movie and Genre microservices into one microservice.

What is best way to solve this problem?

CodePudding user response:

Movie and Genre are so tightly coupled concepts that trying to abstract them in two different microservices does not seem the best option. Do not focus too much on the "micro" part of microservices. Microservices need to tackle specific business use cases and provide meaningful features. They are not intended to completely break your business model and use cases in very tiny parts.

Having said that, consider using a single microservice instead.

  • Related