Is it appropriate to return HTTP 503 in response t

2019-06-24 03:50发布

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.

2条回答
看我几分像从前
2楼-- · 2019-06-24 04:17

I think semantically 409 Conflict is a better alternative - basically if you have a deadlock there's contention for some resource, and so the operation could not be completed.

Now depending on the reason for the deadlock, the request may not succeed if submitted a second time, but that's true for anything.

For a 503, as a client I'd implement some sort of back-away/circuit breaker operation as the system is rate limited, whereas 409 relates to the specific request.

查看更多
手持菜刀,她持情操
3楼-- · 2019-06-24 04:29

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

查看更多
登录 后发表回答