← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

At-Least-Once Delivery

messaging Intermediate

TL;DR

At-least-once delivery guarantees a message is delivered to at least one consumer, possibly multiple times — consumers must be idempotent to handle duplicates safely.

Explanation

Three delivery guarantees: at-most-once (may lose), at-least-once (may duplicate), exactly-once (ideal, expensive). At-least-once: broker retries unacknowledged messages. Consumer crashes after processing but before ack → redeliver → process twice. Handling duplicates (idempotency): deduplication table (message ID + status), natural idempotency (UPDATE SET status = 'sent' WHERE status = 'pending'), INSERT IGNORE. Kafka: at-least-once by default (manual offset commit after processing). RabbitMQ: at-least-once with manual ack. SQS: at-least-once by design. Message IDs: always include unique ID to detect duplicates.

Common Misconception

At-least-once delivery is a bug — it's a deliberate trade-off. Exactly-once is extremely expensive to implement correctly; at-least-once with idempotent consumers is the practical standard.

Why It Matters

Understanding delivery guarantees is essential for designing correct message consumers — assuming exactly-once when the broker provides at-least-once causes data duplication.

Common Mistakes

  • Non-idempotent consumer with at-least-once broker — double charges, double emails.
  • Not including message ID for deduplication.
  • Using exactly-once where at-least-once + idempotency suffices — unnecessary complexity.

Code Examples

✗ Vulnerable
// Non-idempotent consumer — charges customer twice on redeliver:
function handlePayment($msg) {
    charge($msg['amount']); // No idempotency check
    ack($msg);
}
✓ Fixed
// Idempotent with deduplication:
function handlePayment($msg) {
    $processed = DB::table('processed_payments')
        ->where('message_id', $msg['id'])->exists();
    if ($processed) return ack($msg); // Already done — skip

    DB::transaction(function() use ($msg) {
        charge($msg['amount']);
        DB::table('processed_payments')->insert(['message_id' => $msg['id']]);
    });
    ack($msg);
}

Added 23 Mar 2026
Views 31
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings W 1 ping T 0 pings F 0 pings S 3 pings S 2 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 3 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 2 pings S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S 1 ping S 0 pings M 0 pings T 1 ping W 0 pings T
No pings yet today
Amazonbot 8 Perplexity 8 Unknown AI 4 Google 2 Ahrefs 2 SEMrush 2 ChatGPT 1
crawler 25 crawler_json 1 pre-tracking 1
DEV INTEL Tools & Severity
🟠 High ⚙ Fix effort: Medium
⚡ Quick Fix
Make all message consumers idempotent. Include message ID in every message. Store processed message IDs in a deduplication table. Use DB transactions for process + record.
📦 Applies To
cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
ack|acknowledge|commit
Auto-detectable: ✗ No
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: Medium Context: File Tests: Update

✓ schema.org compliant