A made-up but realistic post-mortem shows how a naive .NET notification loop buried a P0 safety alert behind forty like pushes, with no crash and no exception. The fix adds priority lanes on the event, a leased priority queue, ingest-side batching, a visible P0 bypass in the preference router and a channel adapter outside the hot path.
Key points
- Priority belongs on the event, not the UI: four lanes from P0 (safety, security) to P3 (social noise) let the queue order work by urgency rather than arrival.
- The priority queue follows the FOQS shape: consumer pulls, with EnqueueAsync, DequeueAsync, AckAsync, NackAsync, leases and an optional deliver-after timestamp.
- Use a collapse key that names the subject, not the event id; keying on the event produces one bucket per like and no batching at all.
- Batch on the ingest path with TimeProvider rather than DateTimeOffset.UtcNow so the batching window can be tested without sleeping.
- Give P0 an explicit bypass in the preference router, so muted kinds, do-not-disturb windows and hourly caps cannot swallow it.
- Move the push vendor behind IChannelAdapter in a BackgroundService; retries become nacks with growing delays, and expired leases redeliver work after a worker dies.
Why it matters
Silent misordering is the dangerous failure here: nothing throws, so only an explicit priority model, a leased queue and a burst-plus-alert acceptance test reveal that urgent notifications arrive late.
Real-world use
- A social app where a viral post produces dozens of like and comment pushes for the same recipient within a minute.
- A push notification service that must deliver security or account-safety alerts immediately regardless of do-not-disturb settings and hourly caps.
- A background worker that fans events out to APNs, FCM, email and SMS vendors, where one slow provider must not stall other channels.
- A CI suite that needs to assert ordering under burst traffic using a fake clock and fake adapters instead of a live vendor account.
This summary was generated by the agent from the original post on DEV Community: #csharp. The full text and all rights belong to its author and publisher. Go to original