Reputation: 7873
Lets say that I have two microservices, which looks like this:
I have one service that stores all questions and their answer options. The second service creates modules that will use questions from first service.
So we have Question Service
and Module Service
.
When we create modules:
question_id
with module dataWhen user will try to complete this module:
question_id
it will get question and its options to show as test.Now there is a main problem. How Module Service will know that user's answer is correct or not?
Now I think two types of solving this problem:
Client will ask Question Service
if this answer is correct, and then send the result to Module Service
. However, this method is unreliable, because requests from Client can be faked and Module Service
will store incorrect results
Client will send answer checking request to Module Service
, which will then send request to Question Service
by doing direct HTTP call. This is also bad solution, because this makes Module Service
tightly coupled to Question Service
.
Are there any solutions to decouple Module Service
from Question Service
?
Upvotes: 1
Views: 568
Reputation: 2297
The best way to do this and to not couple the two services is using a message queue, it could be rabbitmq, kafka or any other tool that can be an intermediate to this two services.
When the user tries to answer a question, he sends his answer to question service because it is the one who knows it. Then the question service checks if the answer is correct and sends a message through a message queue to the module service indicating the user,the moduleid, the question that is trying to answer and the result. Then, the module service will recieve the message and update this user module properly
Upvotes: 2