Prevent duplicate queue jobs: durable admission and payment webhook recovery
Prevent duplicate queue jobs with durable operation identity, atomic admission and verified recovery rather than relying only on queue IDs, locks or a successful webhook response.
5 min read

In this article
A webhook arrives twice and a job is retried after a network timeout. The queue accepts only one current job ID, but the payment provider already completed an earlier attempt whose response was lost.
To prevent duplicate queue jobs from producing duplicate business effects, define durable operation identity and recovery behavior. This guide focuses on the admission-to-processing protocol that connects verified webhooks, database records and a queue.
Our Laravel payment and webhook guide covers provider-specific handling. Here the emphasis is the operating gap between accepting an event and completing its side effect.

Step 1: Separate the three identities to prevent duplicate queue jobs
A delivery attempt, provider event and business operation are not always the same identity. Several delivery attempts can carry one event, and distinct related events can describe the same payment or order transition.
| Identity | Intended purpose |
|---|---|
| Delivery attempt | Observe transport retries and receipt |
| Provider event | Recognize a repeated verified event |
| Business operation | Enforce one intended side effect or transition |
Scope identities to the relevant provider account, environment and tenant or business resource. Do not let an arbitrary caller choose a key that suppresses another customer's legitimate operation.
Validate webhook authenticity before treating a claimed event ID as trustworthy. Preserve the raw-body requirements of the provider's signature verifier and keep secrets in protected server configuration.
Step 2: Make admission atomic and durable
Use the existing database transaction owner to record a verified event with a reviewed unique constraint. A read-then-insert application check alone can race when two deliveries arrive concurrently.
Store a bounded payload or protected reference according to retention needs, not a public log of payment details. Record admission and processing status separately so a received event is not mistaken for completed work.
If the same identity arrives with an incompatible canonical request, reject or flag the conflict according to the operation contract. Do not silently reuse a result for different instructions.
Keep the inbound handler fast, but define success acknowledgment against durable retention. If a broker is unavailable and no database record retains the work, returning success can lose the event.
Step 3: Close the dispatch gap with an outbox
Database commit and broker enqueue are separate actions. A process can commit admission and crash before dispatching; it can also enqueue before a transaction commits if the integration is wrong.
An outbox design records an owned dispatch intent in the same database transaction as admission. A publisher retries delivery using stable operation identity, and the consumer tolerates repeated messages.
verify inbound authenticity
begin database transaction
insert or locate durable event admission
record eligible dispatch intent once
commit database transaction
acknowledge durable receipt
outbox publisher retries dispatch
consumer checks durable business state
consumer applies and records the verified outcome
This is a protocol outline, not executable payment code. The application must implement locking, unique constraints, authorization and failure handling through its existing owners.
Laravel after-commit dispatch avoids a worker seeing uncommitted records. It does not make the database and broker one atomic system or remove every post-commit crash window.

Step 4: Treat queue-level deduplication as one layer
Laravel unique jobs and overlap controls serve different purposes: dispatch uniqueness and concurrent execution are not identical guarantees. Verify the lock store and lifecycle used by the deployed application.
BullMQ job IDs prevent adding another job with the same retained ID in that queue. When a job record is removed, that retained deduplication boundary changes. It is not a permanent payment ledger.
Keep business idempotency in durable state with an explicit retention policy. Queue records and short-lived locks can support execution efficiency without becoming the only evidence that an external action already happened.
Step 5: Coordinate the business transition
Use an atomic state transition, unique business-operation constraint or appropriate transactional locking. Keep transactions bounded and avoid waiting on a slow external provider while holding unrelated rows locked.
For external requests, use the provider's supported idempotency mechanism with a stable operation key. Understand its retention and parameter-conflict behavior rather than assuming keys remain effective forever.
Our idempotent AI job guide applies the same principle to costly external calls: a retry is safe only within a defined operation contract.
Step 6: Reconcile ambiguous and unordered outcomes
Webhook order is not a reliable business-state sequence. Apply eligible transitions according to current authoritative state and retrieve provider state where the integration requires it.
A timeout can happen after an external action succeeds. Preserve the operation reference and inspect provider state before issuing another action with a different identity.
| Failure rehearsal | Required behavior |
|---|---|
| Same event delivered concurrently | One durable admission, no duplicate effect |
| Crash after commit before dispatch | Outbox eventually delivers the retained intent |
| Repeated consumer execution | Final business state remains correct |
| External timeout after acceptance | Reconciliation avoids a second effect |
| Events arrive out of order | Valid state transitions remain consistent |

Step 7: Verify the complete protocol
Use provider test environments and isolated application fixtures. Record the actual event, dispatch and business outcome counts without exposing real payment data.
Monitor retained admissions awaiting dispatch, operations stuck in an intermediate state and reconciliation failures. A low queue count can conceal work that never reached the broker.
For queue reliability and safe webhook processing fitted to your application, discuss the project with Cloudsoft Zone.
Featured image: Cloudsoft Zone technical layout with laravel artwork by Laravel (Public domain). Product mark resized proportionally for identification; no endorsement implied. Layout: CC BY-SA 4.0.
Frequently asked questions
Does a unique queue job ID guarantee exactly-once business effects?
No. Queue retention can remove the deduplication record, and retries can occur after an external effect. Enforce durable business-state idempotency separately.
Does after-commit dispatch make the database and broker one transaction?
No. It avoids exposing uncommitted data to the worker, but the database commit and broker delivery can still fail independently. A durable outbox addresses that gap.
Should a webhook handler acknowledge an event before retaining it?
Define acknowledgment against durable admission. If nothing durable retains the event when dispatch fails, returning success can cause lost work. Keep the handler fast and bounded without silently discarding events.
Sources
- Stripe duplicate and unordered webhook delivery — Stripe
- Stripe idempotent request behavior — Stripe
- BullMQ job-ID retention boundary — BullMQ
- BullMQ idempotent job design — BullMQ
- Laravel unique jobs and transaction dispatch — Laravel
- Laravel transactional row locking — Laravel
Read next

ComparisonDevOps5 min read
MySQL vs PostgreSQL for SaaS hosting: operational differences small teams should evaluate
Compare MySQL vs PostgreSQL through maintenance, connections, recovery, migration compatibility and team experience rather than unsupported universal performance rankings.
New tools, once a week
One short email listing what joined the directory.
Comments
No comments yet. Be the first to join the conversation.
Leave a comment
Every comment is read by a moderator before it appears. Your email address is never published; it is used only to contact you about this comment.
More from Cloudsoft Zone

TutorialDevOps5 min read
MySQL production configuration for Laravel applications: a safe operating baseline
Review MySQL production configuration for Laravel using measured memory and connection budgets, explicit durability, protected access and verified restore procedures.
By Nilesh Kushvaha

Troubleshooting guideDevOps5 min read
Database connection pool exhaustion: causes, symptoms and safe fixes
Diagnose database connection pool exhaustion by separating application acquisition waits, server limits, leaked clients and slow transactions before increasing capacity.
By Nilesh Kushvaha

TutorialDevOps5 min read
Production stack monitoring: nginx, PHP-FPM, MySQL, Redis and queue workers
Build production stack monitoring with private nginx and PHP-FPM status, MySQL connection signals, Redis memory context and queue progress instead of process-only checks.
By Nilesh Kushvaha