I'm solving the communications between the microservices with messaging-architecture.
Let's say I have a tradition application, and there're User
, Post
Video
modules.
You can create the posts, videos with it, but before that, I need to convert the username to user ID.
Once I've split the modules to microservice, I cannot chain them together, we visit the microservices directly instead.
And if I want to convert an username to an ID,
I can call the User
service in the Post
service via Messaging, so far so good.
But here's the problem:
How do I receive the converted user ID? Send another message back to the Post
service and continue the next step?
What if I want to do this from the Video
service? I'll need to make another function for it in the User
service?
That will be a lot of the functions if I got more and more services right?
I think this is not how messaging architecture works, but I have no clue how to communicate with the other services without messaging.
(Or should I chain them together in the API Gateway so I don't need the messaging architecture?).
From what I understood, you have 3 services: User, Post, Video. In Post and Video services you need to implement commands that will have username as an argument, but not userId. And because all data in those services correlated by userId, you thinking about calling user service first to ask for related userId.
The answer is: you should save username-userId association in every service that requires this.
In your specific case, both Post and Video services should subscribe to NewUserRegistered event from User service and maintain their own username-userid map. This allows you to avoid an extra call to User service from other services.