DEV Community

Taocarts跨境
Taocarts跨境

Posted on AI-assisted

Keeping Warehouse Inventory in Sync When Suppliers Go Silent

Keeping Warehouse Inventory in Sync When Suppliers Go Silent

Our sourcing platform pulls stock and price data from a handful of upstream marketplaces. Those feeds are not dependable. A supplier can go quiet for an hour, send a partial update, or replay an old event out of order. When that happens, the number we show a buyer and the number actually sitting in the warehouse drift apart — and a wrong inventory count turns into a cancelled order.

We spent the last quarter tightening the sync layer between supplier events and our warehouse records. Here is the approach and the failure modes we hit.

Treat every incoming update as untrusted

The first rule: an event from a supplier is a claim, not a fact. We validate it before it touches inventory — check the shape, check the source, and check that it is not older than the state we already applied. That last check matters more than it sounds.

Early on, we applied events in arrival order. A delayed "back in stock" message could land after a newer "out of stock" one, and suddenly we were selling something that was gone. Now every event carries the provider timestamp, and we store a last_applied_at per SKU. If an incoming event is older, we drop it. Ordering by the producer's clock, not the network's, fixed a whole class of phantom-stock bugs.

Absorb duplicate deliveries at the storage layer

Suppliers retry aggressively when they do not get an ack. That means the same stock update can arrive several times. We give each event a provider-side identifier and put a unique constraint on it in the supplier_events table. A repeated delivery fails the insert quietly and is ignored. This is cheap insurance, and it keeps our counters from being decremented twice for one physical sale.

Put a retry buffer between the feed and the warehouse

When the warehouse service is briefly unavailable, we do not want to lose the update. Incoming events are written to a durable buffer table and marked pending. A worker picks them up, applies them, and marks them done. On failure, the attempt count goes up and the event is scheduled again with exponential backoff and a bit of jitter, so a burst of failures does not come back as a synchronized wave.

After a fixed number of attempts, an event moves to a dead-letter list. That list is not a graveyard — it is how we notice a supplier silently changed a field name. We alert on it, and a small internal tool lets us replay an event once the root cause is fixed. The first week we enabled it, we caught two schema changes we would otherwise have found through customer complaints.

Reconcile, do not just trust the stream

Even with all of this, streams drift. So we run a periodic reconciliation job that compares our recorded counts against a snapshot from the warehouse system and flags mismatches above a threshold. It runs off-peak and writes discrepancies to a report rather than silently "correcting" numbers. A human looks at the report before we adjust anything, because an automatic overwrite can hide a real problem.

The sync layer in our Taocarts platform — a cross-border reverse-shopping system for Taobao/1688 sourcing and consolidation — works this way now. React on the front end, Laravel services behind it, and a warehouse module that treats supplier data as untrusted input. The result is fewer oversells and, honestly, calmer support mornings.

If you integrate third-party inventory feeds, three habits pay off quickly: order by the producer's timestamp, deduplicate at the database, and reconcile on a schedule. Streams lie sometimes; a reconciliation job is the honest second opinion.

Tags: #programming #webdev #ecommerce #automation

Top comments (0)