Replicas

A web service or a worker can run several copies of the same version on its server:

services:
  - name: api
    kind: web
    repo: https://github.com/acme/api
    replicas: 3
  • 1 to 10; without the line it is one. The plan shows the change, for example replicas 1 -> 3; it takes effect at the next deploy.
  • A deploy starts every copy of the new version, and each must pass the health check before any request moves. One failing fails the deploy; the old copies keep serving.
  • Caddy sends requests to the copies in turn. A copy that refuses a connection is skipped for 10 seconds and the request is tried on another, so a crashed copy costs a retry, not an error page.
  • Other services reach the copies by the service’s name. Docker spreads new connections over them, not each request, so a connection kept open (a pool, a socket) stays with one copy.
  • Logs show every copy; metrics add them up, and the graphs’ limit lines are every copy’s limit together. Every copy is watched: copy 2: it keeps restarting is an incident.
  • A service with a volume has one copy: two copies writing one volume would break it (api has a volume; replicas share nothing, so it can have only one copy.).
  • A database or a cron job has one copy.
  • The terminal opens in the first copy. Restart, stop and start act on all of them.