Connected infrastructure

Drain work before stopping

Editorial edition · 16 November 2026

The idea

Stopping a process can interrupt requests, lose unacknowledged work or cause clients to retry a completed action. A graceful shutdown sequence gives the process a bounded opportunity to finish or return ownership of its work before it exits.

Design choice

First stop accepting new work and mark the instance unready. Drain active requests within a deadline, flush necessary state and release leases or queue deliveries that cannot finish. Keep the forced-stop deadline explicit so shutdown does not hang indefinitely.

Worked example

A worker receives a termination signal while processing a batch. It finishes its current committed item, stops claiming new items and releases the remaining lease. Another worker can safely continue the unfinished portion.

Before you ship

  • Test termination during active work.
  • Bound the drain period.
  • Verify that retries do not duplicate side effects.

Examples are illustrative. Adapt the checks to your own environment.

Further reading

HTTP Semantics, RFC 9110

Search the library