HTTP Status Code for database is down
Asked Answered
R

4

54

I have a page on my web site that reports on the health of the site and sets an HTTP 200 status code is everything is okay. This page is used by an external monitoring program to check that the site is up.

When this page is hit, I make a very lightweight DB proc call to see if the DB is up and okay. If this fails, I want to return a meaningful HTTP error code to the monitor to let it know that all is not well.

From what I can work out there's no HTTP status that says "a third party component that I rely on is down" so what what would you return in this case?

503 Service Unavailable...?

Rechaba answered 16/9, 2009 at 17:15 Comment(0)
H
38

I would suspect that a 500 or 503 would be appropriate. 503 is generally used for overloaded or maintenance conditions, but I don't think it would be unreasonable to use it for your situation.

Hematite answered 16/9, 2009 at 17:18 Comment(1)
i would have to agree that a 500 code would be most useful. there was an error server-side--your db is down. with that, you can still return any markup that you want.Cultivar
L
46

That's exactly what a 503 is.

503 means that the server was relying on connecting some other service, which did not respond in time.

Server Error 5xx

Checked up on Wikipedia and the listing there seems to imply that a 504 would be the one I'm thinking of. Quite possibly the link over is outdated.

So:

504 Gateway Timeout

The server was acting as a gateway or proxy and did not receive a timely request from the downstream server.

Louvain answered 16/9, 2009 at 17:23 Comment(3)
I am opting for 503 because it indicates that this is a temporary issue and the client can't try again after a particular time which can be specified in the header.Madox
504 would be when the server was able to make a connection but didn't get a timely response. So, I feel that 503 is more suitable here because we are not even able to make a connection.Fructify
503 will work, but doesn't scale and is bad for situations when it was unable to determine status at all (e.g. because of some internal problems). If you are certainly know that something is down, then reporting page should return 2xx code and more details in body about what is down. Or 204 for 'All good' and 200 for 'There is some problem for report', etcGalven
H
38

I would suspect that a 500 or 503 would be appropriate. 503 is generally used for overloaded or maintenance conditions, but I don't think it would be unreasonable to use it for your situation.

Hematite answered 16/9, 2009 at 17:18 Comment(1)
i would have to agree that a 500 code would be most useful. there was an error server-side--your db is down. with that, you can still return any markup that you want.Cultivar
G
1

Leave 500 and 503 for situation when you couldn't determine status of service, like syntax error or DB error about credentials, etc. Or maybe for situation when DB is ok but the app is overloaded.

If the page is for monitoring purposes only, I would not use http codes to indicate status of another service. Better return 200 or even 207 and some XML/json with details. If all is good, then 204 may be ok.

Galven answered 29/12, 2022 at 7:8 Comment(0)
L
-1

It sounds like you should base your monitoring on more than just the status return. You're trying to pass more sophisticated information than the HTTP status codes were designed to communicate.

Or, just pick a code, even make one up, and set up your monitoring to treat it as "db down".

Lecompte answered 16/9, 2009 at 17:21 Comment(1)
To me, it sounds like he wants to pass along a meaningful message to clients when the database is down. In that case, making a code isn't a good idea - how are clients supposed to interpret it? You should pick the right status code.Hematite

© 2022 - 2024 — McMap. All rights reserved.