Short answer: for a small US/EU app, start with a database polling queue when a failed job and its business record need one transaction; use DLQ redrive when retry traffic needs an isolated dispatch boundary, and make either choice idempotent before calling it reliable.
The least complex useful design is not a particular queue. It is a state machine with a stable job identity, a bounded retry policy, and evidence for every state change. A manual polling loop can implement that design, but a SELECT pending query followed by an update is not yet a queue; it has no credible answer for two workers seeing the same row, a process ending after an external effect, or a job whose failures are no longer transient.
For payment-adjacent work, the standard of proof is higher than “the worker ran.” The system must later reconcile the intended business effect with the recorded attempt, even when delivery repeated or an operator initiated a redrive. That is the practical meaning of exactly-once here: the ledger mutation is protected by a unique business key or conditional write, while transport is allowed to retry.
Start with the record.
Should a small app use a database polling queue for failed-job retry and DLQ redrive?
Choose the database queue first when the most important invariant is atomic enqueue. Consider an order transaction that creates a receipt task. If the order and the task row commit together, there is no interval in which the order exists but the job was lost before reaching a separate broker. An indexed table with an atomic claim, a lease expiry, an attempt count, and a terminal state is a valid queue for modest traffic. The database is already an operational dependency, so a small team gains a single backup and access-control boundary.
The catch is shared capacity. Polling, retries, and a backlog all consume the same connections, storage I/O, and maintenance window as customer transactions. It is not suitable when a burst of failed jobs could delay the database path that authorizes an order or records a ledger entry. In that case, a separate queue and a dead-letter queue provide a useful capacity boundary: exhausted work can leave the hot path while an operator investigates it.
A DLQ is a quarantine, not a proof of correctness. Redrive should be a recorded transition with an actor, a reason, an eligibility rule, and a batch limit. Returning every failed message to the main queue merely converts a visible incident into a repeated one. Keep the durable audit record in application-controlled data, because the audit question is broader than message movement: which logical job ran, which idempotency key it used, what external effect was requested, and what disposition was approved?
The US/EU distinction changes the operating constraints without changing this reasoning. Put opaque identifiers rather than sensitive payloads in jobs where possible; define retention for attempts and quarantined items; and have the responsible privacy and compliance owners approve the processing and deletion rules. Queue geography alone does not settle the applicable contractual or regulatory limits.
Build the retry contract before choosing the transport
Every logical job needs an idempotency key that survives retry, lease recovery, and redrive. The worker claims a job for a bounded lease, applies the effect with that same key, then records either success, a scheduled next attempt, or quarantine. A worker can end after the effect succeeds but before it records success, so the next delivery must be safe. This is normal uncertainty, not an exceptional corner case.
The 30-second lease in the sketch below is illustrative, not a universal setting.
Keep the claim and the state transition atomic in the chosen store. For a relational table, that commonly means selecting an eligible row while preventing another worker from claiming it, then persisting the lease owner and expiry in the same transaction. For a broker, the equivalent boundary comes from its receive and acknowledgement model, while application state still records the business outcome. Neither model removes the need for an idempotent handler.
Small details decide the outcome. A retry delay should grow and be capped, rather than immediately reprocessing a dependency that is still unavailable. A lease should be chosen from observed tail latency with margin, rather than from a median. An attempt record should include the old state, new state, time, actor or worker identity, and reason. When sensitive errors are retained, their redaction policy belongs in that contract too. The review should also force an explicit answer to a less obvious question: what happens when the handler has sent a request to an external processor, the processor has accepted it, and the worker loses its chance to persist the local success record? The next attempt cannot infer a negative result from the missing record, because absence is ambiguous. It must present the same idempotency key to the external boundary, receive or reconstruct the prior disposition, and then make the local audit trail converge; if the processor cannot support such a key, the application needs a reconciliation mechanism tied to a stable business identifier before it makes automated redrive available. This is why retry policy, duplicate suppression, and audit retention are one design problem rather than three operational settings.
Here is a deliberately narrow Go boundary. It does not prescribe a database or a broker; it makes the required transitions reviewable.
package retry
import (
"context"
"errors"
"time"
)
type Job struct {
ID string
IdempotencyKey string
Attempt int
Payload []byte
}
type Store interface {
Claim(context.Context, time.Duration) (Job, error)
RecordSuccess(context.Context, Job, time.Time) error
ScheduleRetry(context.Context, Job, time.Time, string) error
Quarantine(context.Context, Job, time.Time, string) error
}
type Effect interface {
ApplyOnce(context.Context, string, []byte) error
}
var ErrNoEligibleJob = errors.New("no eligible job")
func ProcessOne(ctx context.Context, store Store, effect Effect, now time.Time) error {
job, err := store.Claim(ctx, 30*time.Second)
if err != nil {
return err
}
if err := effect.ApplyOnce(ctx, job.IdempotencyKey, job.Payload); err == nil {
return store.RecordSuccess(ctx, job, now)
} else if job.Attempt >= 8 {
return store.Quarantine(ctx, job, now, err.Error())
} else {
delay := time.Minute * time.Duration(1<<min(job.Attempt, 6))
return store.ScheduleRetry(ctx, job, now.Add(delay), err.Error())
}
}
The code leaves policy visible. Claim must recover an expired lease without creating a second logical effect; RecordSuccess must tolerate a repeated call; and ApplyOnce must be backed by a durable uniqueness rule where the business effect is committed. A process-local lock is insufficient across replicas and disappears on restart.
What does the queue comparison actually change in operations?
The comparison is best made against operational obligations, not a claim that one option is universally cheapest. A database polling queue has low incremental infrastructure cost when the database already exists, but its true cost includes indexes, lock behavior, connection pressure, dashboards, retention work, and a recovery procedure the team has rehearsed. A separate queue with a DLQ introduces another administrative and security boundary, while separating dispatch capacity from primary transaction capacity. Neither is free of operator responsibility.
| Design | Strong fit | Required controls | Primary trade-off |
|---|---|---|---|
| Database polling queue | Enqueue and business state need one transaction | Atomic claims, leases, indexed eligibility scans, bounded retry, terminal state | Backlog and customer traffic share database capacity |
| Separate queue with DLQ | Workers need isolation and a deliberate quarantine path | Duplicate-tolerant consumer, acknowledgement policy, attempt record, controlled redrive | A cross-system enqueue gap needs an outbox-style bridge when atomicity matters |
| Scheduled repository workflow | Infrequent, low-stakes maintenance | Run history, rerun procedure, independent verification of effects | It is not a durable transaction dispatch mechanism |
For FIFO queues, the published contract describes ordering within a message group and deduplication behavior. Those properties can reduce a class of transport ambiguity, but they do not make a remote financial effect exactly once; the effect still needs its own idempotency boundary. Scheduled workflows have a different limitation: their scheduling documentation allows delays during high load. They are reasonable for maintenance work with flexible timing, not for an obligation that must be dispatched immediately after a business transaction.
Price should be recorded as a current cost model, not as the decision. Count database capacity, request volume, retained messages, observability, on-call time, and recovery testing. I am not sure any static comparison remains useful for long because workload shape and retention policy change; a quarterly ADR review with queue age, claim contention, terminal count, and redrive outcomes will reveal more than a stale price table.
Roll out the failure path in small, reversible steps
First, give existing jobs a stable idempotency key and append-only attempt history before moving them. Then run the new claim or receive path in observation mode, comparing eligible-job age and completed business keys against the current process. After that comparison is clean, enable a small worker cohort and retain a manual approval step for redrive until its audit records and downstream saturation behavior have been tested.
Test duplicate delivery, lease expiry during slow work, a worker ending after the effect, retry exhaustion, and redrive of an already completed key. Short tests are not enough. The useful acceptance test reconciles the authoritative business rows with the queue's terminal records and explains every difference.
Do not migrate a low-volume database queue merely because a DLQ looks more mature on a diagram. Move when measured contention, isolation needs, or the quarantine workflow justify the additional boundary. Conversely, do not retain polling out of habit when retry traffic can interfere with the transaction system it is meant to protect.
Top comments (0)