2

When inter-communicating through http requests between Microservices it is quite easy to reply with error messages to users, you can just catch the error of a different Service and forward it to the user.
But how does Error handling work when communicating through a message queue?
For example, a user makes a request to an Auth Service, that Auth Service publishes a message indicating that a new user needs to be created. The User service consumes this message and tries to create a new User. But what if the User Service throws an error, maybe the Email is already taken. How do we notify the user that his request failed?

My guess would be that it is not possible to respond to the user with this error because the initial request to the Auth Server is already closed after publishing the message to the queue. Might this be a better case for synchronous communication?

Example Flow:

client -> Auth Service                              User Service
                   |                                       ↑  |
                   | create User               create User |  | Fails to create User
                   |                                       |  |
                   ↓                                       |  ↓
           ----------------------Async Queue----------------------
1
  • 1
    What does the auth service response to the client? Because when the auth service does not know whether the user was created or not do you grant the user access to the system or do you respond he has to wait?
    – Darem
    Nov 24, 2021 at 8:09

1 Answer 1

3

In general, you have two options:

The first is sending a message back. The user service knows that the auth service sent the request, so will complete the loop by reporting the error (or success).

The second option is having a common DB next to the message queue. That common DB stores info about jobs including timing, status, and error information.

The first option scales better and tends to be more fault tolerant, but is harder to debug, visualize, and coordinate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.