At-Least-Once Delivery

At-least-once delivery means a queued job is retried until the system considers it successfully handled, so the same job can reach a consumer more than once. Consumers therefore need duplicate-safe processing, usually through idempotency or deduplication.

A queue using at-least-once delivery prioritizes avoiding lost jobs. If a worker receives a job but fails before acknowledging completion, the queue may make that job available again. The retry can happen even when the first attempt actually performed the intended side effect.

The central challenge is the gap between performing work and recording that the work succeeded. For example, a worker might charge a customer and then crash before acknowledging the message. The queue cannot safely assume the charge did not happen, so it can deliver the job again.

Consumers should make processing idempotent where possible: repeating the same operation should leave the intended result unchanged. A common approach is to attach a unique operation ID to each job and store which IDs have already been completed, often together with the business-side effect in the same transactional boundary.

Retries should also account for transient failures, visibility or acknowledgment timeouts, and poison jobs. Backoff, retry limits, dead-letter queues, and appropriate observability help prevent one repeatedly failing job from consuming worker capacity indefinitely.

Key points

Interview questions

What should happen when a job keeps failing?

Retries should generally use backoff so transient failures do not create a tight retry loop. A retry limit or suitable policy can prevent a poison job from consuming resources indefinitely. After the limit, the job can be moved to a dead-letter queue for inspection or later recovery. Metrics and logs should make repeated failures and retry volume visible.

What does at-least-once delivery guarantee?

It means the system attempts to ensure that a job is not lost before successful processing is recorded. A job may be delivered more than once when acknowledgment is missing or a retry occurs. Therefore, consumers must be prepared for duplicate deliveries. It does not mean the business operation itself happens exactly once.

Why can a worker process the same job twice even if the first attempt succeeded?

The worker can complete the business action and then fail before acknowledging the queue. From the queue's perspective, successful completion was never confirmed, so it can retry the job. This creates a failure window between the side effect and the acknowledgment. The second delivery can therefore repeat the side effect unless processing is idempotent or deduplicated.

How would you design an idempotent background-job consumer in Python?

I would give each logical operation a stable unique identifier and persist its processing state in durable storage. Before applying a non-repeatable effect, the consumer would check or atomically claim that identifier. The state change and the relevant business update should be coordinated transactionally when they share a database. For external systems, I would use an idempotency key or another mechanism supported by that system rather than relying only on local memory.

How would you explain the difference between at-least-once delivery and exactly-once semantics?

At-least-once delivery permits the same message to reach a consumer multiple times, so the consumer must tolerate duplicates. Exactly-once semantics are stronger because they concern the observable processing result rather than merely message delivery. Achieving exactly-once effects across independent systems is difficult because failures can occur between those systems. In practice, systems often combine at-least-once delivery with idempotent operations, deduplication, and transactional coordination.