HTTP 500 Internal Server Error vs 503 Service Unavailable
Both 500 and 503 signal server failures, but 503 specifically indicates a temporary condition. A 500 is a generic catch-all for unexpected errors, while a 503 tells clients the service is temporarily unavailable and they should retry later.
描述
The server encountered an unexpected condition that prevented it from fulfilling the request. A generic catch-all for server-side errors.
何时出现
When an unhandled exception occurs, a database connection fails, or server code has a bug.
如何修复
Check server logs for the stack trace. Common causes: unhandled exceptions, database errors, misconfigurations.
描述
The server is temporarily unable to handle the request due to maintenance or overload. Should include a Retry-After header.
何时出现
During maintenance windows, server overload, or when the application pool is exhausted.
如何修复
Wait and retry. Check the Retry-After header. Scale up servers if it's a capacity issue.
主要区别
500 is a generic server error with no guarantee of recovery — it may be a bug, a crash, or a permanent issue.
503 explicitly signals a temporary condition — the server expects to recover (maintenance, overload, rate limiting).
503 should include a Retry-After header to tell clients when to try again.
500 suggests a developer needs to investigate and fix a bug; 503 suggests waiting is the correct response.
Load balancers and CDNs may handle 503 specially, routing traffic to healthy instances or serving cached content.
何时使用哪个
Return 500 for unexpected errors like unhandled exceptions, corrupted state, or programming bugs. Return 503 when the server is intentionally unavailable: during scheduled maintenance, when a dependency is down, or when capacity limits are reached. Always include a Retry-After header with 503.