Search code examples
restdatabase-deadlockshttp-status-code-503

Is it appropriate to return HTTP 503 in response to a database deadlock?


Is it appropriate for a server to return 503 ("Service Unavailable") when the requested operation resulted in a database deadlock?

Here is my reasoning:

Seeing as:

  • It's easier to ask clients to repeat the operation.
  • They need to be able to handle 503 Service Unavailable anyway.
  • Database deadlocks are rather rare.

I'm leaning towards this solution. What do you think?

UPDATE: I think returning 503 ("Service Unavailable") is still acceptable if you wish it, but I no longer think it is technically required. See https://stackoverflow.com/a/17960047/14731.


Solution

  • I think it's fine so long as the entire transaction is rolled back or if the request is idempotent.