Product scenarios¶
Documentation › Concepts › Use cases
These scenarios define what the product must support. They intentionally avoid HTTP paths and physical tables.
| Group | Scenarios |
|---|---|
| Producer / intake | UC-1, UC-8 |
| Worker / execution | UC-2 … UC-7 |
| Operators | UC-9 … UC-13 |
UC-1 Application without a database enqueues work¶
- Producer chooses a named queue and a stable idempotency key.
- It sends an opaque payload with
priority(default0, optional-32768…32767) and an optional one-shotavailable_at(aware RFC 3339 / SDKdatetime). - Omitted/null/past/current
available_at→ immediate (ready) by workhold store time; aware future withinQUEUE_SCHEDULE_HORIZON_SECONDS(default/max 86400, range 0..86400) →delayeduntil the time is reached. - Naive timestamp, a future beyond the horizon, or
priorityoutside the range / not integer →validation_failed, not silent ignore. - workhold commits the task before acknowledgement success.
- Retry with the same key and the same request returns the original task.
- Reuse key with a different request is rejected.
The application does not create its own business DB only for workhold: the queue store already belongs to the service. This is a one-shot delay, not cron, calendar recurrence, or per-task retry override.
UC-2 Many replicas compete for tasks¶
- Worker replicas subscribe to one or more named queues they can process.
- workhold issues one active lease for each claimed task.
- workhold records
claimed_atas workhold store time and the claimingworker_id. - The claim response returns this metadata for logs and task diagnostics.
- Long work heartbeats until the lease expires.
- A crashed or partitioned worker loses the lease; another replica may claim the task.
- A stale worker cannot heartbeat or finish workhold state with the old token.
The business handler stays idempotent: external work may already have happened before the lease was lost.
UC-3 A successful worker spawns more work¶
- The worker finishes the claimed task.
- In one workhold transaction the source task becomes succeeded and zero or more follow-up tasks are created in named queues.
- A repeat complete with the same claim returns the same tasks.
- There is no partial state in which the source succeeded and the spawns were lost.
Spawn is a Work Queue operation, not a Delivery Outbox publication. What a follow-up is in plain words — 05-follow-up.md.
UC-4 A successful worker writes outbound events¶
- The worker completes the task with zero or more outbound events.
- The source transition, spawns, and Delivery Outbox records commit together.
- The relay publishes events after commit and records successful delivery.
- If publication succeeded and the acknowledgement state was lost, the event may be published again.
- Downstream consumers deduplicate by the stable event ID.
UC-5 Retryable processing failure¶
- The worker reports a stable machine-readable
failure_codeand an optional diagnostic detail, or its lease expires. - workhold records the attempt outcome and moves the task to
delayedwithavailable_at = workhold store now + retry_delay_secondsaccording to the named queue retry policy. - The task is not claimable until
available_at <= transaction_timestamp(); after it is due, claim movesdelayeddirectly toleasedwithout a promotion job. - Attempts are limited; exhausted work becomes a dead letter.
The retry policy belongs to the named queue configuration, not the task payload. It is versioned and configures enabled, max_attempts, and backoff. The initial policy supports fixed delay. The task snapshots the active policy version at enqueue.
If retry is disabled, the first worker failure or lease expiry dead-letters the task. workhold still records the failed attempt; the work does not disappear silently.
UC-6 Non-retryable failure and dead letter¶
- The worker reports a non-retryable failure, or the retry policy is exhausted.
- workhold records a terminal dead-letter outcome and the failure code.
- Operators can view counters and the saved diagnostic details.
- Replay, if supported, creates a new auditable attempt/task and does not quietly rewrite history.
UC-7 Cooperative cancellation¶
- The producer requests cancellation of a delayed, ready, or leased task.
- A delayed or ready task becomes terminal immediately and is never claimed.
- A leased task shows the cancellation to the worker on heartbeat/checkpoints.
- The current worker confirms cooperative cancellation with an idempotent
ack_cancel; lease expiry also finalizes a pending cancellation. - Complete and cancellation compete by one documented winner rule.
- A cancelled task does not create spawns or events after cancellation wins.
UC-8 Application with a business database¶
- The application transaction changes business state and inserts an app-local outbox row.
- The bridge reads that row after commit and enqueues into the named queue.
- The app-outbox row ID produces the workhold idempotency key.
- The bridge marks the row delivered only after acknowledgement of the durable enqueue from workhold.
- Crashes and retries produce at most one workhold task for that outbox row.
Delivery is eventual; a distributed transaction is not implied.
UC-9 Operators observe and recover¶
Operators can determine:
- depth ready, delayed, leased, and dead-letter by named queue;
- the age of the oldest ready task;
- throughput enqueue, claim, retry, success, and dead-letter;
- distributions of wait and processing latency;
- the number of pending events and the oldest lag of delivery-relay;
- the active version, schema readiness, and unhealthy dependencies.
Statistics have an as_of time and documented freshness. They are not arbitrary queries over payload fields.
UC-10 Safe deploy and upgrade¶
- One-shot migration role updates the workhold-owned schema.
- API replicas become ready only against a compatible schema.
- Rolling upgrade API does not require sticky sessions.
- Shutdown stops new claims, drains limited in-flight, and lets abandoned leases expire.
- PostgreSQL recovery can produce safe redelivery or republish events, but not a silent loss of acknowledgement inside the documented recovery point.
UC-11 An operator controls the queue runtime¶
- Admin explicitly creates a named queue and its initial immutable policy.
- Pause stops new claims, while producers may continue to enqueue.
- Drain rejects new external enqueue, while claims and internal task chains finish.
- Policy/state changes use expected config version and write audit atomically.
- Delivery Outbox publication proceeds independently of Work Queue state.
UC-12 workhold protects PostgreSQL¶
- Oversized payload/fan-out is rejected before the write transaction.
- Active-depth admission uses transactional counters, not hot-table scans.
- Idempotent replay succeeds even if the queue is currently full or draining.
- On overload, enqueue is throttled, while claims continue to drain the backlog.
- A dependency failure returns explicit retryability and never local success.
UC-13 A producer and an operator inspect work¶
- Producer finds its task by task ID or scoped idempotency key.
- The operator views state, the current claim summary, attempts, and the dead-letter reason.
- Full claim tokens are visible only to the worker that holds them.
- workhold returns spawn/event lineage, but does not store the application's business result.
- Replay dead-letter creates a new auditable task, keeps source
priority, and lineage source.
← Product boundary · Guarantees →