Idempotent notifications with an outbox: separate detection from sending, re-check before send

TL;DR AI
2 min readKey summary
A Cloudflare Workers and D1 notification system uses the outbox pattern to deliver alerts without duplicates.
Detection writes only a deduplicated outbox row instead of sending immediately.
At send time, the system rechecks current data and decides to deliver, drop, or retry.
A state machine tracks pending, sending, sent, dropped, retry, and failed states.
The last_notified baseline is updated only after a successful send, preventing stale alerts.
