Surviving on a 2GB VM: Readiness, Blue/Green RAM, and Manual Swap
A single VM can handle production if you understand its limits. 2server's reliability docs lay it out: 2xx readiness, Caddy quarantine after 2 failures, blue/green requiring double RAM, manual swap, and no host HA.
The problem: running production on a 2GB VM
Running production on a single VM makes many builders hesitant, and the operational concerns are very specific: a deployment crashes mid-flight, traffic hits containers that are not ready, or memory exhaustion locks up the host until SSH stops answering.
The 2server reliability documentation makes no sweeping promises. It outlines what 2server handles (process restarts, health-based routing, gated deployments, local storage recovery) and what it does not (host-level HA). This write-up reviews four operational constraints for small VMs, separating what 2server automates from what you must configure yourself.
1. Readiness: Caddy only routes to instances ready for traffic
For web applications, you define a readiness path (the documentation example uses "healthPath": "/readyz"). The path must return 2xx once an instance can handle incoming requests, should remain lightweight, and must avoid performing business writes. Redirects do not count as ready responses.
For non-HTTP background workers, requirements differ: container images must define a HEALTHCHECK. Direct proxy routes configured upfront do not have inferred health checks, so do not assume Caddy will guess health automatically.
If readiness fails at runtime, the instance is removed from Caddy and an HTTP readiness alert is fired. During deployment, the rule is strict: all candidate instances must pass readiness before receiving traffic.
2. Upstream quarantine after two consecutive check failures
The reliability specification details exact thresholds: Caddy checks instances every 5 seconds, quarantines an upstream after two active check failures, and requires two consecutive passes before restoring traffic. Connection errors trigger a 10-second quarantine. Caddy retries upstream selection for up to 3 seconds; once connected, only idempotent GET/HEAD requests are retried.
A critical takeaway for single-replica deployments: the documentation notes explicitly that "a single replica has restart downtime." If you run one replica, quarantine has no secondary instance to absorb incoming requests. While Docker restarts exited processes under the unless-stopped policy, an unhealthy container status alone does not trigger a container restart.
3. Blue/green deployments require double the RAM
During blue/green deployments, the VM temporarily hosts two container generations concurrently. The capacity formula from the docs is: replicas × memoryMb × 2, plus Caddy, active extensions, kernel overhead, and headroom. The documentation states plainly: a 2GB VM may not fit every workload running two replicas alongside extensions.
Two subtle configuration points:
- Container CPU and memory limits provide process isolation, not physical resource reservations. Configuring limits does not guarantee reserved physical RAM.
- Previous instances are drained over
drainSecondsafter Caddy switches traffic. Long-lived requests and WebSockets must handle reconnections. Workers follow the reverse sequence: older instances terminate first, requiring durable queues with bounded leases and safe redelivery.
Calculating peak deployment RAM is your responsibility before triggering a deployment.
4. Swap (1–2GB): 2server does not create it for you
This is the most common operational misunderstanding: 2server does not create swap files. You must provision a 1–2GB swap file manually. The reason is straightforward: without swap space, an out-of-memory kernel event can lock up SSH access rather than terminating a container.
The documentation shares telemetry from an internal reference node: an 8GB RAM host operating with a 2GB swap file consumed roughly 3.1GB total. This illustrates sizing behavior, not a performance guarantee for your workload.
Clear boundary: no host-level high availability
2server is direct about its design boundaries: it does not provide host-level HA. If a VM loses power, corrupts storage, or drops networking, the ingress edge, databases, and monitoring stack fail together. Running Sentinel or a local NATS quorum on that same node cannot alter this failure domain. There is no automated node failover, secondary VM replication, or database auto-promotion provided out of the box.
The primary operational consequence involves monitoring: Prometheus and Alertmanager run on the VM itself, meaning they cannot notify you if the host becomes unreachable. The documentation instructs you to configure an external uptime monitor with alert channels. External webhook deliveries also require an active receiver in monitoring configuration; otherwise, alerts remain strictly local.
Summary of responsibilities
| Area | Handled by 2server | Your responsibility |
|---|---|---|
| Readiness | Checks every 5s, quarantines after 2 failures, restores after 2 passes | Define lightweight healthPath (2xx) or worker HEALTHCHECK |
| Blue/Green | Spawns parallel generation, drains previous containers | Calculate replicas × memoryMb × 2 plus system overhead |
| Swap | Does not provision swap | Manually configure a 1–2GB swap file |
| Host failure | No host-level HA | Configure external uptime checks and notification channels |
Review this checklist before deploying to a small VM, rather than troubleshooting memory constraints under incident pressure.
Full reference: 2server › Reliability
