ARCHIVED from builddistributedsystem.com on 2026-04-28 — URL: https://builddistributedsystem.com/tracks/queues/tasks/task-15-3-at-least-once
TASK

Implementation

Guarantee at-least-once delivery:

  1. Consumer receives message (not removed from queue)
  2. Message marked as "in-flight" with timestamp
  3. Consumer processes and sends acknowledgment
  4. Queue removes message on ack
  5. If no ack within timeout, redeliver message

Consumer must be idempotent to handle potential duplicates.

Sample Test Cases

Redeliver on timeoutTimeout: 5000ms
Input
{"src":"c0","dest":"queue","body":{"type":"init","msg_id":1,"node_id":"queue","node_ids":["queue"]}}
{"src":"producer","dest":"queue","body":{"type":"enqueue","msg_id":2,"message_id":"m1","value":"hello"}}
{"src":"consumer","dest":"queue","body":{"type":"dequeue","msg_id":3,"ack_timeout":1000}}
Expected Output
(no output)

Hints

Hint 1
Do not remove until acknowledged
Hint 2
Redeliver after timeout
Hint 3
Track in-flight messages
OVERVIEW

Theoretical Hub

At-Least-Once Delivery

At-least-once means every message is delivered at least once, possibly more. If an ack is lost, the message is redelivered. This requires idempotent consumers that handle duplicates gracefully.

Visibility Timeout

When a consumer receives a message, it becomes invisible to others for a timeout period. If not acknowledged, it reappears. This prevents multiple consumers processing the same message simultaneously.

Key Concepts

at-least-onceacknowledgmentredelivery
main.py
python
Implement At-Least-Once Delivery - Queues | Build Distributed Systems