Replicas and Health
Run more than one copy of a service and check that each one is healthy.
These settings live under Deploy and Health in the service settings. Changes are staged until you press Deploy.
Replicas
A replica is one running copy of your service. With more than one, traffic is spread across them, and a deployment replaces them one by one so there is no gap.
Set Replicas from 1 to 10. Your app has to be fine with running as several copies: no state in memory or on local disk that other copies need.
A service with a volume always runs 1 replica and its Replicas setting is locked, because replicas can't share a volume.
Databases have no replica setting.
Rollout
Rollout under Deploy in the service settings is how a deployment replaces the running version:
- Rolling, the default: the new version starts next to the old one, and the old one stops once the new one is ready. No gap.
- Stop first: the old version stops before the new one starts, so the two never run at once. Every deployment has a gap of a few seconds. The new image is pulled first, and an image that can't be pulled leaves the running version in place.
Pick Stop first for an app that must never run twice at the same time, not even for a few seconds: a bot that holds one token, a worker that owns a wallet, a job that must not overlap. With more than one replica, all old replicas stop before the new ones start.
A service with a volume always stops first, and the setting is locked.
Stop a service
To turn a service off without deleting it, open the menu on its current deployment and choose Stop. The service runs no replicas until you choose Start from the same menu. Its volumes, domains, variables and settings stay as they are, and it comes back with the replica count it had.
Use it when the app must not run for a while: restoring its database, an upgrade whose migrations must not overlap with the old version, or pausing something that misbehaves. A stopped service shows Stopped, and its domains answer with an error until it starts again.
Databases can't be stopped.
Resource limits
Resource Limits caps the vCPU and memory of each replica. Drag a slider to the end for Unlimited.
- Memory: a replica that goes over its limit is stopped and restarted. If you see
OOMKilledin the deploy logs, raise the limit or fix the leak. - vCPU: a replica that goes over is slowed down, not stopped.
Limits protect the other services on your servers from one that misbehaves. Set them on anything you do not fully trust.
Health checks
A health check tells Unbind whether a replica is working. Without one, a replica counts as healthy as soon as its process starts, even if the app inside is still booting or is stuck.
Pick a Health Check Type:
- Endpoint: Unbind requests a path like
/healthon one of the service's ports. Any successful response counts as healthy. - Command: Unbind runs a command inside the replica, like
test -f /app/ready.txt. Exit code 0 counts as healthy. - None: no checks.
Two checks use it:
| Check | What it does | Defaults |
|---|---|---|
| Startup Check | A new replica gets traffic after its first successful check. If it never passes, it is restarted. | Try every 3 seconds, restart after 30 errors |
| Health Check | Watches running replicas. One that keeps failing stops getting traffic and is restarted. | Check every 10 seconds, restart after 3 errors |
Slow starters, like large Java apps, need a more patient startup check. With the defaults a replica has about 90 seconds to come up.
Keep the endpoint cheap. It should answer quickly and should not depend on other services, or one slow dependency restarts your whole app.
When something is wrong
A deployment that keeps restarting shows CRASHING. One that never came up shows ERROR. Open it and look at Deploy Logs. Unbind puts the reason at the top: OOMKilled or the number of restarts for a crash, and what stopped a replica from starting for an error, such as an image that could not be pulled, a missing variable reference or a server without enough memory.
To restart a healthy service by hand, open the menu on the current deployment and choose Restart.