Error Encyclopedia
503

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

1

Server under heavy load (traffic spike, DDoS attack)

2

Scheduled maintenance or deployment in progress

3

Database connection pool exhausted

4

Memory or CPU resource limits reached

5

Web server (Nginx, Apache) worker processes exhausted

6

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:

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.