Why Detection Design Matters
In Back in Stock systems, delivery failures are visible, but detection failures are more dangerous.
When inventory fluctuates rapidly, weak detection logic causes duplicate sends and poor customer experience.
As you know, these issues are easy to miss until traffic spikes.
This article focuses on building stable detection with minimal false positives.
Think of it as a design baseline you can implement without guesswork.
Trigger Rule: Only 0 -> 1+
Use inventory recovery as the only trigger:
- trigger when
prevStock = 0andcurrentStock > 0 - ignore transitions where stock remains above zero
- evaluate by variant, not product-level aggregate
This one rule removes most duplicate scenarios.
Simple rules tend to be easier to operate and explain.
Core Detection Data Model
Use at least:
stock_snapshots:variantId,stock,observedAtdetection_events:variantId,transitionType,eventId,processedAt
detection_events is key for idempotency.
Store event IDs (or deterministic hashes) and skip already-processed events.
That single safeguard prevents many "why did we send this twice?" incidents.
Event-Driven Plus Polling Backup
Event-driven path
- process inventory webhooks for low-latency detection
Polling path
- periodic reconciliation to recover from webhook loss
- nightly consistency checks to fix drift
Use event-driven as primary and polling as safety net.
Handling Inventory Flapping
Some variants oscillate between 0 and 1 within short windows.
Add debounce before enqueueing notification jobs:
- set
readyAt = detectedAt + 5 minutes - re-check inventory at
readyAt - enqueue only if stock is still positive
Cooldown Policy
Prevent over-notification by variant/channel cooldown:
- key:
variantId + channel - duration: for example 24 hours
- block repeated sends within cooldown window unless manually overridden
Detection Observability
Track:
- detection count (0 -> 1 events)
- enqueue rate
- debounce drop rate
- cooldown suppression rate
- idempotency hit rate
Without these metrics, troubleshooting "too many" or "too few" notifications is guesswork.
And in operations, guesswork gets expensive very quickly.
Summary
A robust Back in Stock system starts with robust detection.
Combining transition-based triggers, idempotency, debounce, and cooldown gives you stable downstream delivery and cleaner operations.