Why Exactly-Once Is Hard in Notifications
You'll learn: Why guaranteeing exactly-once delivery in distributed notification systems is fundamentally challenging despite being highly desirable.
The Distributed Coordination Problem
Exactly-once delivery requires perfect coordination between multiple independent components: your notification service, message queues, third-party providers (like Twilio for SMS or FCM for push), and the recipient's device. Each hop introduces failure points where state can become inconsistent.
Consider this scenario: Your worker sends a push notification to FCM successfully, but crashes before marking it "delivered" in your database. When the worker restarts, it sees the notification as "pending" and sends it again—creating a duplicate.
Three Hard Problems Combined
1. Network Uncertainty
When a request times out, you don't know if it failed or succeeded slowly. Did FCM receive your notification? You can't be certain, so you must choose: risk duplicates (retry) or risk loss (don't retry).
2. Distributed State
Your database says "not sent," but the provider's system says "delivered." Without atomic distributed transactions across system boundaries (which don't exist with third-party APIs), these states can diverge.
3. Two-Phase Commit Is Impractical
You can't make external providers participate in distributed transactions. SMS gateways and push services don't support prepare/commit protocols—they process requests immediately.
Real-World Compromise
Most systems accept at-least-once delivery with idempotency on the recipient side. You include a unique notification_id in every message, and clients deduplicate using that identifier. This shifts the burden from impossible distributed coordination to manageable local deduplication.
Key Takeaway:
Exactly-once delivery in notifications requires perfect coordination across network boundaries and independent systems—something fundamentally impossible in distributed computing. Production systems use at-least-once delivery with idempotent recipients instead.