Web / Caddy Server Interview questions
How is load balancing configured in Caddy's reverse_proxy?
Listing multiple upstreams in a reverse_proxy block turns it into a load balancer, and the lb_policy subdirective controls how requests are distributed among them.
example.com { reverse_proxy backend1:8080 backend2:8080 backend3:8080 { lb_policy least_conn health_uri /healthz health_interval 10s health_timeout 3s } }
| lb_policy | Behavior |
| round_robin (default) | Cycles through upstreams in order. |
| least_conn | Sends requests to the upstream with the fewest active connections. |
| ip_hash | Routes a given client IP to the same upstream consistently. |
| random / first | Picks a random upstream, or the first available one. |
health_uri and the related settings enable active health checks, so Caddy stops routing traffic to an upstream that fails its health check until it recovers.
More Related questions...