A .NET 8 pattern for consuming warehouse stock events over Azure Service Bus so that an old or duplicate message can never overwrite the current on-hand number. The real guarantees live in the database, in a conditional update, an inbox table and snapshot reconciliation, not in the broker.
Key points
- Asking the WMS for absolute on-hand plus an increasing Version reduces the rule to one version comparison.
- Service Bus duplicate detection with its default 10-minute window is only a first filter, not a guarantee.
- Using Sku|LocationCode as the SessionId serializes one key while different keys still process in parallel.
- A ProcessedMessage inbox keyed by EventId catches duplicates through a unique constraint violation.
- Version and LastSnapshotAtUtc conditions inside ExecuteUpdateAsync move the check into the database itself.
- Snapshot reconciliation classifies each row as created, corrected, deferred or missingfromsnapshot and records drift.
Real-world use
- A consumer that turns a warehouse system's stock event stream and nightly snapshot into one trusted quantity per SKU and location
- Replays from the dead-letter queue that must not roll back the current stock numbers
- Flows where parallel consumers touch the same SKU and location and ordering per key is critical
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