Skip to content
Open sourceMIT

Workhold

Durable background work for applications that run on many replicas

  • idempotent enqueue
  • fenced leases
  • bounded retries
  • atomic spawn[]
  • PostgreSQL 18
  • Python 3.13+

Why Workhold

Built for work that must not get lost

Reliable background execution without building queue correctness from scratch or adopting a shared, platform-wide message bus.

01

Keep work through crashes

A successful enqueue is committed to Workhold's PostgreSQL before it is acknowledged.

02

Scale workers safely

Replicas compete for tasks under fenced, renewable leases. Stale workers cannot mutate queue state.

03

Finish work atomically

Completion and spawn[] follow-up tasks commit together, so the next step is not lost.

Capabilities

What you get

One versioned image is deployed beside each application with independent api, migrate, maintain, relay, and apply roles. An application business database is optional.

  • Durable intake


    • Named queues inside one service instance
    • Idempotent enqueue with request fingerprint validation
    • Priority ordering and one-shot future scheduling
    • Admission control before unsafe work reaches PostgreSQL
  • Safe execution across replicas


    • Atomic claim with a rotating secret token and lease generation
    • Heartbeats for long-running handlers
    • At-least-once recovery when a worker crashes or loses its lease
    • Bounded long polling and cooperative cancellation
  • Predictable failure handling


    • Versioned retry policies per named queue
    • Structured failure codes, delayed retries, and dead-letter state
    • Idempotent terminal commands
    • Attempt history and task lineage for diagnosis
  • Atomic continuation


    • complete + spawn[] in one database transaction
    • Follow-up tasks can target other named queues
    • Delivery Outbox and relay for outbound events, capability-gated in the public completion API
  • Production control


    • Explicit queue creation and immutable policy versions
    • Pause and drain modes
    • Task, attempt, queue-depth, and dead-letter inspection
    • Migration, maintenance, retention, readiness, metrics, and audited recovery
  • Separate access planes


    • Producer, worker, observer, admin, and break-glass principals
    • Role-split Python clients: each process installs only what it needs
    • OpenAPI 3.1 is the authoritative wire contract

Lifecycle

How it works

A producer enqueues idempotently, a worker replica claims under a fenced lease, and completion can atomically spawn the next step.

flowchart LR
  producer["Producer"] -->|"idempotent enqueue"| queue["Named Work Queue"]
  queue -->|"fenced claim"| worker["Worker replica"]
  worker -->|"heartbeat"| queue
  worker -->|"complete / fail / cancel"| queue
  queue -->|"atomic spawn[]"| queue
  queue -.->|"capability-gated events[]"| outbox["Delivery Outbox"]
  outbox --> relay["Delivery Relay"]
  relay --> destination["HTTP destination"]

At-least-once, by design

Workers process tasks at least once. If a lease is lost, another worker may receive the task, so handlers and external effects must be idempotent. Workhold does not claim exactly-once execution or distributed transactions with an application's database. Read the guarantee matrix before integrating.

End-to-end lifecycle Product boundary

Run it

Quick start

Start the service locally, or install the role-specific Python clients.

Run the service, migrations, and PostgreSQL locally:

git clone https://github.com/KoninMikhail/workhold-durable-work-queue.git
cd workhold-durable-work-queue
docker compose -f docker-compose.dev.yml up --build

The public API is available on http://localhost:8080.

Python 3.13 and uv are required:

uv sync --group dev
uv run workhold --help
uv run pytest

Install only the role used by each process:

pip install workhold-producer   # enqueue, inspect, cancel, and bridge
pip install workhold-consumer   # claim, heartbeat, complete, fail, and supervise
pip install workhold-admin      # observe, administer, and break-glass operations

The packages share a coordinated version and depend on workhold-client-core. Async support ships as the async extra.

See the local setup guide for configuration, migrations, Docker profiles, and client development.

Fit

Common use cases

Use case How Workhold helps
CPU- or I/O-heavy background jobs Distribute work across replicas, renew long leases, and safely retry after crashes
Multi-stage processing Complete one task and atomically spawn the next stage into another named queue
Scheduled work Make a task claimable at a bounded future available_at time without a promotion job
Reliable handoff from a business transaction Use an app-local transactional outbox and a deterministic idempotency key to bridge into Workhold
Applications without a database Enqueue directly; Workhold already owns the durable store
Controlled operational recovery Inspect attempts, diagnose failure codes, replay dead letters, and pause or drain queues

More in Product use cases and Examples.

Boundaries

When to choose something else

Workhold is a Work Queue, not a universal messaging system.

If you need… Use…
Pub/sub, fan-out, or event-log replay A message broker or event log
DAGs, joins, compensation, or human tasks A workflow orchestrator
Exactly-once external effects Application-level idempotency, inboxes, or natural uniqueness
A shared multi-tenant platform bus A platform messaging service

RabbitMQ or Kafka can complement Workhold as a downstream delivery channel. See Why Workhold for the detailed comparison.

Documentation

Explore the docs