Skip to content

Support singleton deploy role for services like Celery Beat #26

Closed

Description

@wadewilliams

Problem

Services like Celery Beat are singletons — only one instance should run at a time. The current deploy roles don't fit well:

  • app — rolling deploy scales to 2 temporarily, causing duplicate scheduling
  • accessory — never restarted, so it runs stale code after deploy

Current workaround

Using deploy.role=app with deploy.drain=1 to minimize the overlap window. Tasks are assumed idempotent, so brief duplicate scheduling is tolerable.

Proposal

A third deploy role (e.g. singleton or sequential) that does stop-before-start instead of rolling:

  1. Send SIGTERM to the old container, wait for graceful shutdown
  2. Start the new container
  3. Health check the new container

This would be useful for any service where exactly-one-at-a-time semantics matter: beat schedulers, cron runners, lock holders, single-consumer queues.

Alternatives considered

  • celery-redbeat: Distributed lock scheduler that makes beat safe for rolling deploys. Works but adds a dependency to solve a deploy-tool gap.
  • deploy.drain=1: Minimizes overlap but doesn't eliminate it.

Activity

  1. wadewilliams commented on Oct 11, 2026

    @wadewilliams
    MemberAuthor

    #31 solves the underlying problem, though not as a new role. A singleton like Celery Beat gets stop-before-start with no overlap by labelling it:

    services:
      beat:
        labels:
          deploy.role: app
          deploy.strategy: drain-first
          deploy.drain: "30"   # how long it may take to stop gracefully

    A drain-first service is stopped with docker stop --time <deploy.drain> (SIGTERM, then SIGKILL when the drain runs out) and removed. It's then started on the new tag and must pass its health check. Old and new never run at the same time, and unlike an accessory, it's restarted on every deploy.

    How this differs from the proposal, and why:

    • A strategy, not a role. deploy.role stays "does flow-deploy manage this service" (app) and deploy.strategy (rolling, the default, or drain-first) says how. A singleton keeps everything apps get: deploy.order, health checks, --service, and revert on failure.
    • Ordering across the deploy, not just within the service. Drain-first services stop first (in reverse deploy.order), rolling services roll, then drain-first services start (in deploy.order). So an old scheduler never runs beside new web code (say, after a migration), and a new one never starts before the services it depends on. The cost is that the singleton is down for the whole rolling phase rather than only its own restart. Beat or a queue consumer simply waits; the broker holds the work.
    • Failure handling. If anything fails, including the singleton's own start, every service goes back to the image it ran, the singleton included, at its previous replica count.
    • Replicas. A drain-first service comes back at the replica count it had (at least 1). flow-deploy doesn't enforce exactly one; a singleton should just be configured with one replica.

    Where it's covered:

    • Commits: 50b42e6 (drain-first strategy), 4e04647 (drain in reverse order, revert cleanly), b81c865 / 74e01e4 (failure paths), e2a6479 (a signal mid-drain finishes the drain, then reverts).
    • Unit: tests/test_drain_first.py, e.g. test_happy_path_drains_in_reverse_rolls_then_starts_in_order, which also asserts the worker never runs old and new together.
    • Integration, on real Docker: tests/integration/test_deploys.py::test_happy_path, test_first_deploy_of_a_new_drain_first_service, test_drain_that_hits_its_timeout_is_killed_and_the_deploy_continues, test_signal_mid_drain_reverts.

    Possible follow-up (not in #31): the proposal's in-place form, stopping and starting the singleton back-to-back in its own turn, would mean less downtime than holding it down through the rolling phase. If that matters for some service, it could be a third strategy (e.g. deploy.strategy: recreate). We haven't needed it so far.

    Closing with #31.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions