1

I have an application where we send a request to two applications parallelly. Once I receive both the responses, I consolidate them to form a final response. When one of the systems fails to send a successful response, what should be the overall HTTP status code as it is a partial response?

I tried to use a common HTTP status code (like 503 service unavailable) incase of partial response. I'm new to web API standards and I'm not sure if this is the right approach.

5
  • It’s fairly irrelevant what happens on the server, whether it sends two requests or a hundred or none. What logically is the state of the response? Is it a failure, because not all requests succeeded? Or is it a success because your server performed without problems? Commented Apr 20, 2023 at 5:12
  • 1
    @Evert Huh? The server sends two requests and waits for both responses, then returns its own response. It’s fairly straight forward. Commented Apr 20, 2023 at 5:15
  • @deceze oops i misread the question. I thought 2 requests were sent from a client in parallel to the same server and both had to succeed. Commented Apr 20, 2023 at 5:16
  • 1
    There’s nothing like a “partial success” status really. Either “the request succeeded and here’s your answer,” where the answer may contain more details about partial failures, or “your request couldn’t be handled because another server failed to respond.” Pick which is more logical for your case. Commented Apr 20, 2023 at 5:20
  • 1
    This question is similar to: HTTP status code for a partial successful request. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Sep 3, 2024 at 15:04

1 Answer 1

6

From the perspective of the client calling your service, there's only 2 broad responses you can return: Success and failure. There is no 'partial failure'.

So if one of the upstream requests fails, I would decide the response code this way:

  • Is the 'partial failure' a failure for the application? Return a 500/502/503 and optionally return information about the failure in the body (you can use this to indicate what partially succeeded).
  • Is it somewhat expected for the upstream service to fail and it doesn't matter for your client... then it's probably just 200 OK.

Ultimately distinct HTTP status codes exist to allow clients to make a decision on 'what to do next'. A 5xx error clearly indicates there was an issue and potentially requires a developer's attention. So another way to think about this is... what do you want the client to do in case one of the upstream services failed?

ideally servers never partially process a HTTP request, but I realize this is not always easy.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.