You unsubscribed. The campaign was already queued.
transcript
You switch off marketing notifications. Then a promo buzzes anyway. Nobody ignored your choice. The message was already in the queue.
A campaign is queued. At that moment, the user still wants marketing. Check passed. While the message waits, the user opts out. The worker sends what it was handed. The opt-out only counted for future sends. That's the bug.
So the worker checks again, at delivery time. First, does the user still exist? Deleted while queued? Don't send. Then re-fetch the preferences. Opted out meanwhile? Skip it. Then claim the dedup key, set only if it doesn't exist. Check and claim in one atomic step. Only then, deliver.
But here's the catch. The send fails, and the dedup key is still set. So the retry looks like a duplicate. It's skipped. Never sent at all. The fix: when delivery fails, release the claim. Then the retry goes through.
On the phone, marketing goes off, after the campaign was queued. And nothing arrives. To the user, the opt-out simply worked. The lesson's worst case has the same shape. An email changed mid-send. Same cure.
The world keeps moving while messages wait in a queue. So check at queue time. Then check again at send time.
Full breakdown in the lecture.