503 Service Unavailable Error
Learn what 503 Service Unavailable means, how to fix maintenance mode and overload issues, and how to implement proper downtime handling.
What Does This Error Mean?
The 503 Service Unavailable status code means the server is temporarily unable to handle the request, typically due to maintenance, overloading, or temporary resource exhaustion.
Common Causes
Server under heavy load (traffic spike, DDoS attack)
Scheduled maintenance or deployment in progress
Database connection pool exhausted
Memory or CPU resource limits reached
Web server (Nginx, Apache) worker processes exhausted
Cloud auto-scaling hasn't provisioned enough instances yet
How to Fix It
Implement health checks
Set up health check endpoints for load balancers to detect when an instance is unhealthy.
// Simple health check endpoint
app.get("/health", (req, res) => {
const dbOk = await db.$queryRaw`SELECT 1`
const memOk = process.memoryUsage().heapUsed < 500 * 1024 * 1024
res.status(dbOk && memOk ? 200 : 503).json({
status: dbOk && memOk ? "healthy" : "unhealthy"
})
})Add Retry-After header
When returning 503, include a Retry-After header to tell clients when to retry.
app.get("/maintenance", (req, res) => {
res.status(503)
res.set("Retry-After", "3600") // 1 hour
res.json({ error: "Under maintenance, back in ~1 hour" })
})Set up auto-scaling
Use cloud auto-scaling to automatically add instances during traffic spikes.
# AWS CLI: update auto-scaling group aws autoscaling update-auto-scaling-group \ --auto-scaling-group-name myapp-asg \ --min-size 2 --max-size 10 \ --desired-capacity 4
Related Tools
Use these tools to debug and fix this error:
Related Errors
Other common errors in this category:
401 Unauthorized Error
Learn what a 401 Unauthorized error means, common causes, and how to fix authentication failures in your web applications.
403 Forbidden Error
Learn what 403 Forbidden means, how it differs from 401, and how to fix access denied errors in your applications.
404 Not Found Error
Learn what 404 Not Found means, common causes, and how to fix broken links and missing resources on your website or API.
429 Too Many Requests Error
Learn what 429 Too Many Requests means, how rate limiting works, and how to handle or avoid hitting API rate limits.
Frequently Asked Questions
How long does a 503 error last?
503 errors are temporary. They can last seconds (during traffic spikes) to hours (during planned maintenance). The Retry-After header indicates the expected duration.
Is 503 a client or server error?
503 is a 5xx server error. It indicates a problem on the server side, not with the client's request.