Back to blog
Engineering1 min read

Zero-downtime deploys with health checks

The new container starts, answers its health check, and only then takes the traffic. This is how the switch works.

A deploy should never be the reason your site is down. Here is how Deplo moves traffic from the old container to the new one.

The sequence

  1. The new container starts next to the old one.
  2. Deplo calls its health check until it answers, or until the timeout runs out.
  3. Traefik starts sending requests to the new container.
  4. The old container finishes the requests it already has, then stops.

If step 2 fails, nothing else happens: the old version keeps serving and the deploy is marked as failed, with the logs of the container that did not start.

Writing a useful health check

A health check should answer quickly and fail when the app cannot do its job:

TypeScript
export async function GET() {
  const database = await db.query("select 1").then(() => true, () => false);
  return Response.json({ database }, { status: database ? 200 : 503 });
}

Settings worth knowing

  • Path: the URL Deplo calls, such as /api/health.
  • Interval and timeout: how often it asks and how long it waits.
  • Retries: how many failures in a row before the new version is given up on.

Rolling back

Every successful deploy keeps its image. Rolling back starts the previous one with the same checks, so going back is as safe as going forward.

Ten minutes from now,
it's live.

Answer three questions and pick a host, or install Deplo on a server you already have. It's free, and leaving is as easy as arriving. What you do with the money you save is your business.

Zero-downtime deploys with health checks - Deplo