Capacity planning

Capacity planning is making sure the cluster can hold what the services need, including after losing a node (N+1), and telling the scheduler what each task needs so that it places them accordingly.

How it works

Measure real usage (p95 per container), declare deploy.resources.reservations (what the scheduler counts) a little above it and limits (what the kernel enforces) above that. Keep part of each node for the system. Then check N+1: the cluster without its biggest node must still hold every reservation, otherwise replicas will stay Pending during an incident. Capacity also has a price: headroom is what you pay for the promise.

What breaks

Without reservations, Swarm spreads tasks by count: a small node gets as many replicas as a big one, swaps, and the kernel kills the largest process when memory and swap run out. Reservations equal to usage still overcommit nodes, because the system's own memory is not in the node's budget. A cluster sized for normal days loses replicas, or swaps, the day a node fails.

In compose.yaml

services:
  search:
    deploy:
      replicas: 4
      resources:
        reservations:
          memory: 1600M
        limits:
          memory: 2G

See it break, then fix it

Write the Dockerfile or the compose file, type the docker commands, and watch a simulated server run them through reboots, upgrades and traffic. Free to start.