Resilience

Resilience is the ability of a system to absorb failures and disturbances and continue providing acceptable service, or recover quickly when a failure does occur. A resilient system degrades gracefully rather than failing completely.

Resilience is achieved through a combination of patterns: redundancy (multiple instances), fault isolation (failures don’t cascade), retries with exponential backoff (transient failures are retried intelligently), circuit breakers (stop hammering a failing service), timeouts (prevent indefinite blocking), fallbacks (serve cached or degraded content), and graceful degradation (disable non-critical features when dependencies are unavailable).

In PHP, resilience patterns are applied at the HTTP client level (Guzzle retry middleware), the queue level (dead-letter queues, retry policies), the cache level (serve stale on cache miss), and the infrastructure level (load balancing, health checks, auto-scaling).

Resilience is distinct from reliability (never failing) and availability (always being up). A resilient system is not necessarily always available, but it recovers quickly and limits the blast radius of failures.

<?php

// Retry with exponential backoff using Guzzle middleware
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Exception\ConnectException;

$stack = HandlerStack::create();
$stack->push(Middleware::retry(
    decider: function (int $retries, Request $req, ?Response $res, ?\Throwable $e): bool {
        return $retries < 3 && ($e instanceof ConnectException || ($res && $res->getStatusCode() >= 500));
    },
    delay: fn(int $retries): int => (int) (100 * 2 ** $retries), // 100ms, 200ms, 400ms
));

$client = new Client(['handler' => $stack, 'timeout' => 5.0]);

?>

Documentation

See also Wikipedia: Resilience.

Related : Fault Isolation, Circuit Breaker, Distributed Systems, Availability, Retry, Monitoring