On this pageFirst, be sure you want to split
Most writing about microservices assumes a Kubernetes cluster and a platform team to run it. Plenty of real systems are smaller: five to twenty services, a team of a few developers, and a handful of servers. At that scale the hard problems are the same, namely packaging, discovery, rollouts, data and visibility, but the tools can be much simpler. This guide is a deployment playbook for that size.
First, be sure you want to split
Microservices trade code complexity for operational complexity. Each service brings its own deploys, versioning, network calls that can fail, and data that can drift. They pay off when separate teams need to release independently, or when parts of the system have very different scaling or reliability needs. For a single small team, a modular monolith, one deployable with clear internal boundaries, usually ships faster and can be split later along the boundaries that turned out to matter.
If you do split, follow one rule from the start: each service owns its data. Two services writing to the same tables are one service with two deploy pipelines.
Package every service the same way
Uniformity is what keeps twenty services manageable:
- One container image per service, built once in CI and tagged with the Git commit (
api:3f9c2e1), never onlylatest. - The same image everywhere. Staging and production run the identical tag; only configuration differs, passed through environment variables and secrets.
- A health endpoint such as
/healthzthat answers only when the service can do real work, including reaching its database. - Graceful shutdown. On SIGTERM, stop accepting new requests, finish the current ones, then exit, within the stop timeout your orchestrator allows.
- Structured logs to stdout, one JSON object per line, with a request ID passed along from service to service.
Choose an orchestrator for your size
| Option | Model | Good for | Limits |
|---|---|---|---|
| Docker Compose per host | Each server runs its own project, deployed by CI over SSH | Two or three servers with a fixed role each | No scheduling or failover across hosts |
| Docker Swarm | Built into Docker Engine; Compose-style stack files across a cluster | Three to ten servers, teams that already know Compose | Smaller ecosystem than Kubernetes; few managed add-ons |
| Nomad | Single-binary scheduler for containers and plain processes | Mixed workloads, teams that like HashiCorp tools | Moved to the Business Source License in 2023; a service mesh needs Consul alongside |
| Kamal | Deploys containers over SSH with a small proxy for zero-downtime switches | Web apps and their workers on a few hosts | No cluster scheduler; you assign roles to hosts |
| k3s | A lightweight Kubernetes distribution you run yourself | Teams that want Kubernetes APIs and tooling | You operate Kubernetes, with its upgrades and its learning curve |
For most teams in the two-to-ten-server range, Swarm is the shortest path: stack files are Compose files with a deploy section, and the rest of this guide uses it as the example.
A Swarm cluster in five commands
Swarm nodes talk on TCP 2377 for cluster management, TCP and UDP 7946 between nodes, and UDP 4789 for overlay network traffic. Those ports must be reachable between nodes and from nowhere else. On servers with only public addresses, the cleanest approach is a WireGuard mesh between the nodes, with Swarm advertising the tunnel addresses:
# on the first manager (10.8.0.1 is its WireGuard address)
docker swarm init --advertise-addr 10.8.0.1
docker swarm join-token manager # prints the join command for more managers
docker swarm join-token worker # and for workers
# shared settings that services read at runtime
printf '%s' "$DB_PASSWORD" | docker secret create shop_db_password -
docker network create --driver overlay --attachable backend
Run three managers, not one or two: Swarm needs a majority of managers to keep making decisions, so three tolerate the loss of one. With WireGuard carrying cluster traffic, a CloudSat cloud firewall attached to every node only has to allow SSH, WireGuard's UDP port from the other nodes' addresses, and the public ports of your edge proxy.
Discovery and traffic
Inside the cluster, services find each other by name: a container on the backend network reaches the orders service at http://orders:8080, and Swarm's built-in DNS and virtual IPs spread requests across healthy replicas. No separate registry is needed at this size.
At the edge, one reverse proxy terminates TLS and routes hostnames and paths to services. Traefik, Caddy and HAProxy all fit; Traefik can read routing rules from service labels, so routing changes deploy with the service. Keep internal services off the edge network entirely: only the proxy and the services it fronts should share a network with the internet-facing side.
Rolling updates that roll back by themselves
The stack file declares how each service updates:
services:
api:
image: registry.example.com/shop/api:${GIT_SHA}
networks: [backend]
secrets: [shop_db_password]
healthcheck:
test: ["CMD", "wget", "-qO-", "http://localhost:8080/healthz"]
interval: 10s
timeout: 3s
retries: 3
deploy:
replicas: 3
update_config:
parallelism: 1
order: start-first
monitor: 30s
failure_action: rollback
restart_policy:
condition: on-failure
stop_grace_period: 30s
networks:
backend:
external: true
secrets:
shop_db_password:
external: true
GIT_SHA=$(git rev-parse --short HEAD) docker stack deploy -c stack.yaml shop
docker service ps shop_api # watch tasks move to the new image
docker service rollback shop_api # manual rollback if you need one
order: start-first starts a new task before stopping an old one, monitor watches each new task for 30 seconds, and failure_action: rollback reverts the service on its own if new tasks fail their health check. The health check runs inside the container, so the image must include the tool it calls, here wget. For riskier changes, run a second copy of the service under a new name and shift a share of traffic to it at the proxy before switching fully.
Data and schema changes
Each service gets its own database, or at least its own schema and credentials, and other services reach that data only through its API or its events. Schema changes then follow the expand and contract pattern, because old and new versions run side by side during every rolling update:
- Expand: add new columns or tables, nullable or with defaults; old code ignores them.
- Deploy the version that writes both shapes and reads the new one.
- Backfill existing rows.
- Contract: remove the old columns in a later release, once nothing reads them.
Never couple a destructive migration to the deploy that needs it.
See what is happening across services
A request that crosses four services needs three kinds of signal. Metrics for each service (request rate, error rate, latency) show which one is unhealthy, and the Prometheus and Grafana guide covers collecting them. Logs with a shared request ID let you follow one request through every service. Traces, produced with OpenTelemetry SDKs and sent to a backend such as Jaeger or Grafana Tempo, show where the time went. Add tracing before the first slow request you cannot explain, not after.
FAQ
When should we move to Kubernetes?
When you need what its ecosystem offers and Swarm or Nomad lacks: autoscaling on custom metrics, operators that manage databases for you, policy engines, or a large catalog of ready-made deployments. Moving from Swarm is mostly translating stack files, because images, health checks and configuration habits carry over.
Do we need a service mesh?
Rarely at this size. A mesh adds mutual TLS, retries and traffic shaping between services, but also a sidecar per service and another system to operate. Encrypt traffic between nodes with WireGuard, set timeouts and retries in your HTTP clients, and revisit the question when you have dozens of services.
How do we keep services compatible with each other?
Version APIs explicitly, add fields without removing old ones, and test each service against the contracts its consumers rely on. Contract testing tools such as Pact automate that check in CI, so a breaking change fails a build instead of a release.
Run it on CloudSat. Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. See plans or deploy a server.




