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
188
Related Errors
PHP
Parse Error: Syntax Error
PHP detected a syntax error in the source code that prevents parsing.
DevOps
Docker Permission Denied
The current user doesn't have permission to run Docker commands.
404
Laravel
NotFoundHttpException
The requested URL does not match any defined route.
404
Laravel
ModelNotFoundException (404)
Thrown when a requested model instance cannot be found in the database.