Communication between Microservices and cohesion using REST

Viewed 119

This problem has been in my head for a while and I can't seem to understand the logic when I find solutions.

Heres the deal: I'm currently working on a simple application that has been split up into 2 microservices. The application is very similar to the task of managing software Trello. There's a microservice solely used for storing User information (User service) Another microservice is responsible for the Boards (Boards hold lists and lists hold tasks but that's not relevant to my question). Both microservices use their own database. All of this will be hosted on AWS, the code is written in Java and I use Hibernate to generate the databases.

My problem: How do I make use of the User service and have a Board be used by multiple User entities? I understand the practice of using a many-to-many table which stores the BoardId's together with the UserId's, but what would happen if I were to remove a user that's connected to a board. There's no logical connection between the User that's in the user database and the userId that's stored by the board. (A user can be signed to multiple boards and vice-versa)

My questions in short:
How does this look in the database?
How does the Boards service access the User service and save Users to Boards?
What happens when I delete a User on the User microservice?

1 Answers

This seems to be a typical Microservice Communication related problem. As per my knowledge and experience, there is a solution i.e. to introduce a message broker in the architecture which can perform actions on events like say USER_DELETED event can be passed to board microservice which will handle board related db changes.

Implementing this can feel scary for you at the start, but nowadays it is not that difficult with all the very supportive internet communities helping and coming up with new solutions every day. If you are using Java for microservices with spring boot, then there are solutions like Apache Kafka, Hazelcast(quite cost effective). If you are using NodeJS for micorservices, then NATS is one of the libraries which I have used recently.

Related