A background job can run more than once even when the business expects one result. A worker may crash after sending a request, a queue may redeliver a message, or an operator may retry a job whose outcome is unclear. Without deliberate handling, a recovery mechanism can create duplicate orders, notifications, or charges.

Design the operation around its business identity and side effects. Understand the actual delivery and acknowledgement guarantees of the queue and worker library in use. Do not assume that a successful local function call proves a remote action happened once and only once.

Define the identity of the business operation

Choose a stable reference that identifies the intended action, such as exporting a particular approved report version or processing a provider event. Keep the identity separate from an individual execution attempt. A retried attempt should be recognizable as work toward the same result.

Decide what counts as a duplicate and what should happen when the underlying record has changed. A repeated request to send the same confirmed receipt is different from a new receipt after an approved correction. The identity rule must reflect the business meaning, not just whichever random identifier the worker creates at startup.

Trace side effects and commit boundaries

List each effect the job performs: update local data, call a provider, create a file, send a message, and acknowledge the queue item. Examine the gap between each step. A crash after a provider accepts work but before the local completion record is stored creates an uncertain outcome.

Use the storage and provider facilities appropriate to the design, such as a reviewed unique-operation record, a transaction boundary, or a provider-supported idempotency mechanism. These techniques have limits and must be implemented consistently under concurrency. A check followed by an unprotected write may still race with another worker.

Test the gaps between effects, not only a clean first execution.
Interruption pointRiskExpected recovery decision
Before any effectWork remains incompleteRetry within the allowed policy
After local change but before acknowledgementThe queue may deliver the action againRecognize completed or resumable work
After remote acceptance but before confirmationThe remote outcome is uncertainReconcile or use provider-supported duplicate handling
After repeated invalid input failuresRetries cannot repair the recordRoute to an accountable correction process

Bound attempts and classify failures

Separate transient failures from permanent input, permission, and business-rule failures. Apply a finite retry policy with appropriate delay and provider limits. Unbounded immediate retries can overload a failing service and make recovery more difficult.

Keep the total time and attempt count visible. When the allowed attempts are exhausted, move the item to a reviewable exception state. Do not silently drop it or leave it looking pending forever. An operator should know the supported next step and whether replay can repeat an external side effect.

A Node.js worker queue status and JavaScript code on a laptop at a parcel dispatch station

Make job state useful to operators

Record the operation reference, attempt reference, relevant status, timing, and safe failure category. Avoid placing credentials or entire sensitive payloads into routine logs. Link the job to the business record through an authorized interface when investigation requires more detail.

Show the distinction between waiting, running, completed, rejected, and needing review. A job queue depth alone does not reveal whether a critical transaction is stuck. Alert on meaningful conditions such as aging pending work or repeated provider failures, with a named owner for responding.

Verify replay and outage recovery

Test repeated delivery, concurrent attempts, worker termination, provider timeout, and restart after an outage. Inspect the actual local and remote results. A test that merely confirms a retry occurred cannot establish that the business action was performed safely.

Document the authorized replay procedure and its limitations. Use a controlled recovery test before relying on an operator to improvise during an incident. A dependable background workflow makes completion and uncertainty explicit, limits retry pressure, and preserves a way to reconcile the final state.

Frequently asked questions

Can a queue guarantee that every business action happens exactly once?

Do not assume that from the queue alone. Local writes, remote calls, worker crashes, and acknowledgements cross different boundaries. Verify the actual guarantees and design duplicate handling for the full operation.

Should an operator freely replay every failed job?

No. A failed attempt may already have produced an external effect. Provide a reviewed replay or reconciliation procedure appropriate to the operation.

Sources and further reading

Make the next step concrete

Discuss your current process, constraints, and intended outcome with GhairMulki. We can help define a focused first release and the checks needed to evaluate it.

Discuss your project