Repository navigation
Bounce methods
A bounce replaces a Service's replicas with ones running the new spec. bounce_method picks the shape. All four use the same planner loop; they differ in how many extra replicas may exist (surge), how many of the N may be missing (unavailable), and whether health gates the change.
bounce_method |
Surge | Unavailable | Health gates draining | Kubernetes equivalent |
|---|---|---|---|---|
crossover (default) |
ceil(N × overprovision) |
floor(N × (1 − margin)) |
yes | RollingUpdate |
upthendown |
N |
0 |
yes, all N new first | none |
downthenup |
0 |
N |
no (old go first) | Recreate |
brutal |
N |
N |
no | RollingUpdate with maxUnavailable: 100%
|
The animations below replace three v1 replicas with three v2 ones. Each is generated from the real planner (bounce.Plan) against a simulated world.
Shown with bounce_overprovision_factor: 0.33 (surge 1): each new replica joins before an old one leaves, so three replicas always serve and at most four exist.
New replicas start while the surge allows; an old replica drains whenever enough new ones are happy (healthy for min_task_uptime) that capacity stays at or above N − unavailable. Choose it for production services: it is the default, never drops below the margin you set, and the two factors trade speed for extra containers.
All N new replicas start and must all be happy before any old one drains; then the old ones drain one at a time. Up to 2N replicas exist. Choose it when the host has room for twice the Service and you want the whole old version serving until the whole new one is proven.
Every old replica is drained (with the configured drain method) and removed first, one at a time; only then do new ones start. Requests fail from the moment the last old replica leaves until a new one is healthy. At most N replicas exist. Choose it when two versions must never run side by side (an exclusive lock on a file or port, an incompatible migration) or the host has no room for even one extra replica.
All N new replicas are created (up to 2N exist); as soon as they are running, the old ones are taken off Envoy's list and stopped without a drain wait. Health is not checked: "running" counts as healthy, min_task_uptime and the drain method are ignored, and up can return before Envoy has seen a new replica pass its health check. Requests fail until a new replica is healthy. The stop itself still honours each container's stop_grace_period. Use it for development loops only.
For crossover, with N = deploy.replicas:
surge = ceil(N × bounce_overprovision_factor)
unavailable = floor(N × (1 − bounce_margin_factor))
if surge == 0 and unavailable == 0: surge = 1
- A tolerance of 1e-9 is applied before rounding so floating-point error does not change the result:
10 × (1 − 0.9)counts as1, not0.999…, and3 × 0.33(0.99) still rounds up to1. - The surge-1 guard exists because with no room to add and no room to remove, a crossover could never make progress.
-
upthendown,downthenupandbrutalignore both factors.
Each pass of the loop, after the health-deadline, dead-replica and list checks described in How it works:
-
Drain the next old replica (old replicas that serve nothing first, then oldest first) if
happy(new) + live(old) − 1 ≥ N − unavailable. Draining a replica that is not serving costs nothing, so the− 1is dropped for it. - Otherwise start one new replica if fewer than N new ones exist and the total is below
N + surge. - Otherwise wait for a Docker event or one second, and look again.
happy(new) counts new replicas healthy in Envoy (and Docker, if they have a healthcheck) for at least min_task_uptime; live(old) counts old replicas that are running and healthy in Envoy.
| Settings | Surge | Unavailable | Most replicas | What happens |
|---|---|---|---|---|
| defaults (margin 0.95, overprovision 1.0) | 3 | 0 | 6 | All three new start at once; each old one drains as a new one becomes happy |
| overprovision 0.33 | 1 | 0 | 4 | One new starts; once happy, one old drains; repeat (the animation) |
| overprovision 0, margin 1.0 | 0 → 1 | 0 | 4 | Same as above via the surge-1 guard |
| overprovision 0, margin 0.5 | 0 | 1 | 3 | One old drains first (2 serve), then one new starts; once happy, the next old drains |
| margin 0.9, overprovision 0 | 0 → 1 | 0 | 4 |
floor(0.3) = 0, so the guard applies |
| Settings | Surge | Unavailable | Most replicas | What happens |
|---|---|---|---|---|
| defaults | 10 | 0 | 20 | All ten new start; old drain one by one as new become happy |
| margin 0.9, overprovision 0 | 0 | 1 | 10 | Drain one old (9 serve), start one new, wait until happy, drain the next |
| margin 0.9, overprovision 0.2 | 2 | 1 | 12 | One old drains right away, then three new start (12 exist); each happy new releases another old; capacity never below 9 |
| overprovision 0.33 | 4 | 0 | 14 | Four new start; each happy one releases an old one, which makes room for the next new |
| margin 0.5, overprovision 0.5 | 5 | 5 | 15 | Five old drain first (5 serve), then all ten new start (15 exist); fast, at half capacity |
With the defaults, unavailable stays 0 until N reaches 20 (floor(20 × 0.05) = 1), so a default crossover never drops below N healthy replicas.
A new replica that is not healthy by its bounce_health_timeout fails the bounce: every new replica that is not healthy is removed, healthy new ones stay, and up exits 1. Old replicas are drained only as new ones become happy, so the old version keeps serving. With N > 1 a failed crossover can leave a mix of happy new and remaining old replicas serving together, so keep schema changes expand/contract. Undo is explicit: docker bouncer undo, or up with the previous file. See Operations.
The SVGs in docs/bounce-<method>.svg are generated from the real planner; regenerate them after changing it:
go run ./docs/animationsThe generator only writes those four files; docs/how-it-works.svg is hand-made and left alone.