Caddy Load Balancing

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up caddy load balancing by listing multiple backend server addresses in your web server settings. Caddy then splits incoming web requests across those upstream servers using your chosen routing rule. Most teams start by pointing a single domain name at two or three app servers. Problems start when engineers log in to those hosts with broad root keys to edit routing files. One bad edit can send live traffic to a broken server or expose internal ports. How caddy load balancing works in p

Load Balancing: the complete guide

Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.

Free white paper. No spam. Unsubscribe anytime.

You set up caddy load balancing by listing multiple backend server addresses in your web server settings. Caddy then splits incoming web requests across those upstream servers using your chosen routing rule. Most teams start by pointing a single domain name at two or three app servers. Problems start when engineers log in to those hosts with broad root keys to edit routing files. One bad edit can send live traffic to a broken server or expose internal ports.

How caddy load balancing works in practice

Caddy acts as a front door for your web apps. It takes incoming user requests and passes them to a pool of backend servers. You define this server pool inside your main text settings file or through the local admin API. When traffic arrives, the server picks one healthy backend target from the list. It then forwards the request and sends the response back to the user.

Teams can pick from several routing rules to match their traffic needs. A random rule picks any server from the pool for each new request. A round-robin rule steps through the server list in order one by one. A least-requests rule sends new work to the server with the fewest open tasks. You can also pin a user to one backend server based on an IP hash or cookie.

How health checks keep backend pools running

Routing traffic is only half of the job for a web server. You also need to know when a backend app crashes or slows down. Caddy handles this with two types of health checks that watch your server pool. Active health checks send test requests to a set path on each backend server on a timer. If a server fails to reply with a good status, Caddy stops sending user traffic to it.

Passive health checks watch live user traffic as it flows through the system. The server counts errors or timeouts from each backend host during real requests. If one host drops too many requests in a short window, Caddy marks it as down. It will try the host again later to see if the app is back up. This keeps users away from broken servers without manual work from your team.

Load Balancing: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native routing solves and what it misses

Native web routing solves the problem of spreading user traffic across many app servers. It handles TLS certificates, keeps web apps online during host failures, and prevents single server overload. For public web traffic, this setup gives teams a clean and fast way to scale out.

Still, a web router only manages network traffic from external users to your apps. It does not control what engineers or scripts do when they log in to manage those servers. Once an admin logs in to a host or database, the web router is out of the picture. It cannot inspect database queries, check shell commands, or mask private data like emails and card numbers. Teams still need a way to govern direct admin work on their backend systems.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.

First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

How does Caddy pick which backend server gets the next request?

It uses a selection rule that you pick in your settings. Common rules include random choice, round-robin order, or picking the host with the fewest active requests.

What is the difference between active and passive health checks?

Active checks send background test pings to your servers on a set schedule. Passive checks watch live user requests and flag servers that return too many errors.

Can Caddy keep a user on the same backend server across requests?

Yes, you can turn on sticky sessions using client IP hashing or cookies. This keeps a user tied to one healthy backend host while their session lasts.

Save the open-source gateway.

hoop is MIT-licensed infrastructure for controlling how AI agents reach production data. Star hoophq/hoop so you can inspect it, deploy it, or share it when your team starts governing agent access.