Clever CloudExplanationFor adminsApplies from 4.2.3
Redeploys
Cette page en françaisThis page on the GitHub wiki
On Clever Cloud a deploy (or a push, or clever restart) starts the new instance while the old one still serves. The
Studio Server is built for that overlap: no write is lost, but writes are slow or refused for about a minute. This page
says why, what was measured, and how to deploy so that members are not surprised.
Why
Spike S measured it on 17 October 2026: during clever restart --without-cache, the new instance started while the
old one still answered, and the old one never logged a SIGTERM. Two instances writing the same game at once would
corrupt its history, and waiting for a signal that does not come would stall the switch. So:
- The instances share a service lease in PostgreSQL: one holds it and serves writes. It lasts 30 s and is renewed every 10 s on the database's clock; an instance that cannot renew stops writing by its own clock before the 30 s can pass.
- The new instance starts, answers
/startz(Clever's health check,CC_HEALTH_CHECK_PATH=/startz), then waits:/readyzis 503 ("writes":"waiting") and its writes are 503 withRetry-After: 2("this instance does not serve writes yet; try again"). - The handoff (since 4.2.3). Once it listens, the new instance asks for the lease; the holder gives it back at its
next renewal (10 s at most) and logs
{"event":"lease-lost",…}; the new one logs{"event":"lease-taken",…}. An older instance never takes the lease back from a newer one. - A client retries a refused write with the same operation id (
X-Studio-Op) and it is applied once. The journal's own fenced lease still keeps two instances from writing over the same head.
What was measured
Clever Cloud keeps the old instance STOPPING for about two minutes, still receiving requests until the deploy ends,
and it logs no stopping line.
In all, about a minute of slow or refused writes per deploy, none lost.
While both instances run they hold twice the connections: on the PostgreSQL DEV plan (5) background work fails with "too many connections" during each deploy, and an older version's write could fail with it (a 500). Take a larger plan for a deployment people use (Apps and add-ons).
Deploying without surprising the team
Verified on: 19 October 2026 (the measures above; engine commits before the 4.2.3 tag, package.json 4.2.2). This page's text itself is not verified on a live installation.
- Tell the members, or pick a quiet moment: about a minute of slow writes; about two and a half minutes of refused writes for the first deploy onto 4.2.3 or later from an older version.
-
Deploy from your machine, in the engine repository, the worker first when both change:
# on your machine, in the engine repository clever deploy --alias my-game-worker clever deploy --alias my-game-studio
-
Watch
/readyzcome back to 200 and thelease-takenline (itsinstanceis the new one):# on your machine until curl -sf https://studio.example.fr/readyz; do sleep 2; done
- Make one write (a note) and see it saved, at the next revision.
Alternatives set aside
- Relying on SIGTERM to hand the lease over: Clever never delivered it observably (spike S, the reference deployment).
- Stopping the old instance first (
clever stop, then deploy): a minute or more with no Studio at all. Kept for one case only, a migration that changes what the old version reads (Upgrading the server). - Several instances serving at once: the journal needs one writer per game.
Trade-offs
The handoff shortens the refused window from minutes to seconds, but Clever's routing to the old instance until the
deploy ends keeps 10 to 16 s of 503. A /readyz alert must tolerate that (Monitoring).
Decisions and ADRs
- The lease:
studio-server/src/server/service-lease.ts(master plan §4, P8); ADR 0025. - The measures:
docs/dev/SPIKE-4.2.1-CLEVER.md§2,docs/dev/QUALIF-4.2.3-REFERENCE.md§5 and §5 bis. - A 503 seen by a member: Troubleshooting.