Reputation: 12910
I have two microservices "frontend" and "/users". They communicate with REST API When client makes a request to "frontend", it internally requests "/users" microservice.
What kind of status code should return frontend service in case when /users answers with 500-error?
Upvotes: 1
Views: 2781
Reputation: 2151
Well, it depends!! A microservice should adhere to it's Bounded Context and should be independent and loosely coupled from other services. An excerpt from Chris Richardson's Microservices site:
Microservices - also known as the microservice architecture - is an architectural style that structures an application as a collection of services that are.
- Highly maintainable and testable
- Loosely coupled
- Independently deployable
- Organized around business capabilities
- Owned by a small team
In your context, you should try answer what's the expected outcome from the Frontend service's bounded context when the underlying communicated User service fails (not just 500, but can be other failures too). Can you still return a meaningful response? Is it acceptable that you return semi hydrated data (for instance, returning data without unavailability of data from the Users service, assuming that Frontend service aggregates some data from itself too). If yes then probably you should handle the 500 response from User service and return the semi-hydrated data with a 2xx response(depending upon what the request was for). If the answer is No, then probably it's better to bubble up the 5xx error from Frontend service too, as already answered above by Eugene.
Upvotes: 0
Reputation: 773
500 Internal Error is good here: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#5xx_server_errors
If you don't know what to do in such situation (if your service can't work without underlying service), 500 is dedicated for that.
Upvotes: 1