Service Unavailable (503)
The server is temporarily unable to handle requests due to overload or maintenance.
Explanation
Service Unavailable (503) indicates that the server is temporarily unable to handle the request, usually due to being overwhelmed with traffic or undergoing maintenance. Unlike a 500 error which indicates an application bug, 503 is typically a capacity or infrastructure issue. The server may be undergoing scheduled maintenance, may have crashed and is restarting, or may be overwhelmed by traffic. Many load balancers return 503 when all backend servers are unavailable or unhealthy.
Common Causes
- Server overload from traffic
- Scheduled maintenance
- Backend server crashed
- Resource exhaustion
- Load balancer routing failure
Solution
Check if the server is undergoing scheduled maintenance. Monitor server resource usage (CPU, memory, disk). Scale up or add more backend servers to handle traffic. Implement health checks so load balancers can route around unhealthy servers. Set up proper maintenance windows with advance notice. Configure auto-scaling based on traffic patterns. Check application logs for errors. Implement circuit breaker patterns for downstream service dependencies. Use a CDN to cache responses and reduce origin server load.
Code Example
// Laravel maintenance mode
php artisan down # enable maintenance mode
php artisan down --message="Upgrading" --retry=60
// Custom maintenance mode response
app()->maintenanceMode()->shouldReceive('isDown')
->andReturn(true);
// Health check endpoint
Route::get('/health', function () {
try {
DB::connection()->getPdo();
return response()->json(['status' => 'healthy'], 200);
} catch (Exception $e) {
return response()->json(['status' => 'unhealthy'], 503);
}
});
// Nginx upstream health check
upstream backend {
server 127.0.0.1:3000 max_fails=3 fail_timeout=30s;
server 127.0.0.1:3001 max_fails=3 fail_timeout=30s;
}
// Circuit breaker pattern
const CircuitBreaker = require('opossum');
const breaker = new CircuitBreaker(callExternalAPI, {
timeout: 5000,
errorThresholdPercentage: 50,
resetTimeout: 30000
});
Error Information
Language
php
Framework
laravel
Difficulty
Intermediate
Views
15
Related Errors
PHP
Headers Already Sent
The code tries to send HTTP headers after output has already been sent to the browser.
405
Laravel
MethodNotAllowedHttpException (405)
The HTTP method used is not allowed for the requested route.
DevOps
Kubernetes OOMKilled
A container was killed by Kubernetes because it exceeded its memory limit.
CrashLoopBackOff
DevOps
Kubernetes CrashLoopBackOff
A container is repeatedly crashing and restarting in Kubernetes.