Inventory-to-Feed Integration: A Failure & Recovery Demo
Short answer
This Agent Commerce Optimization demonstration simulates an ERP-to-store-to-product-feed inventory pipeline in your browser. You can inject webhook failures, delays, duplicates, and missed events, then watch exponential-backoff retries, idempotency keys, dead-letter replay, scheduled reconciliation, and checkout revalidation recover the system. It measures simulated freshness lag between a stock change and the feed showing it.
Key takeaways
- Webhooks fail, arrive late, arrive twice, and arrive out of order, so the pipeline has to be safe under all four.
- An idempotency key on every event makes retries and replays harmless, and a version number stops older updates from overwriting newer ones.
- Reconciliation against the source of truth is the only thing that catches changes that never produced an event.
- Checkout must revalidate stock against the source system. A feed is always somewhat behind.
- We ran 16 automated checks on the simulation engine in this session, and all passed.
Can you show inventory reconciliation working?
Yes. The simulator below starts with three synthetic SKUs that agree across the ERP, the store, and the feed. To break sync, arm a fault and trigger a stock change, or choose a guided scenario. Then watch the audit trail as the system recovers. Bulk import to 0 (no event) followed by Run reconciliation shows drift being detected and repaired.
Simulated: synthetic SKUs, virtual clock
A deterministic in-browser simulation of an ERP → store → product-feed pipeline. Times are virtual milliseconds on a simulation clock, not measurements of any real system. No network calls are made, and this is not a client case study.Sim clock00:00.0
Next feed batch in 15.0s · reconciliation in 120.0s| SKU | ERP (truth) | Store | Feed (agents see) | Status |
|---|---|---|---|---|
| JKT-BLU-MRain jacket, blue M | 3 v1 | 3 v1 | 3 v1 | In sync |
| FUEL-230Fuel canister 230 g | 40 v1 | 40 v1 | 40 v1 | In sync |
| PAD-KITPad repair kit | 12 v1 | 12 v1 | 12 v1 | In sync |
- Freshness lag p50 (simulated)
- –
- Freshness lag max (simulated)
- –
- Unpublished changes
- 0
- In-flight deliveries
- 0
- Retries
- 0
- Duplicates ignored
- 0
- Drift repaired
- 0
- Checkouts blocked
- 0
Audit trail (newest first)
- 00:00.0erpSimulation started. ERP, store, and feed agree for all SKUs.
What happens when a product update fails?
Here, the dispatcher retries with exponential backoff. If every attempt fails, the event moves to a dead-letter queue, and the store keeps showing old stock until someone replays it or reconciliation repairs it. Meanwhile, checkout revalidation stops the stale number from turning into an oversold order.
| Scenario | Failure injected | Recovery mechanism | Observed in test | Simulated lag |
|---|---|---|---|---|
| Normal stock change | None | Webhook applies, next feed batch publishes | Feed shows new qty; all systems agree | 15.0 s |
| Webhook fails 3× | HTTP 503 on attempts 1–3 | Retries after 1.03 s, 2.15 s, 4.03 s (backoff + jitter) | 3 retries, delivered once, converged | 15.0 s |
| Webhook delayed 20 s | Delivery latency +20 s | Applied on arrival | Feed caught up on the next batch after arrival | 30.0 s |
| Duplicate delivery | Same event delivered twice | Idempotency key check | Second copy ignored; stock decremented once (40 → 36) | 15.0 s |
| Retries exhausted | All 5 attempts fail | Dead-letter queue → operator replay from outbox | 5 failures, 1 dead letter, replay applied once | 30.0 s |
| Change with no event | Bulk import bypasses the outbox | Reconciliation (ERP vs store) | Drift detected and repaired (40 → 12) | 15.0 s |
| Agent checkout on stale stock | Webhook down; feed shows 3, ERP has 0 | Checkout revalidation against ERP | Order blocked with STALE_STOCK before payment | 30.0 s |
| Out-of-order delivery | Older event arrives after newer | Version check | Older update ignored; final qty is the newest (9) | 15.0 s |
We also checked these properties: a replay that arrives after reconciliation already repaired the SKU is ignored by the version check; all eight scenarios chained together produce an identical log on two runs (deterministic) and converge once the queues drain; and no stock level ever goes negative. The retry behavior is covered in more depth in our guide to inventory sync webhooks and retries.
How do you keep a product feed in sync with inventory?
Treat the source system as the truth, make every change an event with an identity and a version, deliver it in a way that is safe to repeat, and reconcile on a schedule for anything the events miss. This is the design the simulation implements:
ERP (source of truth)
│ stock change → row in OUTBOX (eventId, sku, qty, version) ◄── replay log
▼
Webhook dispatcher
│ attempt 1 … 5 on 5xx: wait base·2^(n−1) + jitter then → DEAD-LETTER
▼
Store webhook handler
│ 1. eventId already processed? → ignore (idempotency)
│ 2. event.version ≤ store.version? → ignore (out-of-order / stale)
│ 3. apply; mark SKU dirty
▼
Feed publisher (batch every 15 s, simulated)
│ dirty SKUs → product feed / agent channel freshness lag = publish − ERP change
▼
Product feed (what AI shopping surfaces read)
Reconciliation job (every 120 s or on demand): ERP vs store → repair drift → mark dirty
Checkout revalidation: agent order reads feed qty → re-check ERP before accepting// Store-side webhook handler: the two checks that make retries and replays safe
function applyToStore(ev: OutboxEvent) {
if (processedKeys.has(ev.eventId)) return 'duplicate_ignored'; // idempotency key
processedKeys.add(ev.eventId);
const current = store[ev.sku];
if (ev.version <= current.version) return 'stale_ignored'; // ordering guard
store[ev.sku] = { qty: ev.qty, version: ev.version };
dirtyForFeed.add(ev.sku);
return 'applied';
}- Outbox
- A table written in the same transaction as the stock change, so an event exists for every committed change. It also serves as the replay log.
- Idempotency key
- A unique id per event. The receiver records keys it has applied, so a retry or duplicate delivery has no further effect.
- Version
- A per-SKU counter that increases with every change. It lets the receiver reject an older update that arrives late.
- Dead-letter queue
- Where events go after their final retry fails. They are kept for inspection and replay instead of being dropped.
- Reconciliation
- A periodic comparison of the source of truth with downstream copies that repairs any difference, including changes that never produced an event.
- Freshness lag
- The time between a change in the source system and the change being visible in the feed that agents read.
Real platforms document the same failure modes. As of 2026-11-29, Shopify's webhook documentation says delivery isn't always guaranteed, recommends ignoring duplicates using the X-Shopify-Webhook-Id header, says ordering isn't guaranteed within a topic, and recommends reconciliation jobs. Stripe's API documentation describes idempotency keys for retrying requests without performing an operation twice. The demo applies those patterns to inventory, and the Next.js agentic commerce architecture guide shows where they sit in a headless stack.
How do you stop an AI agent from selling out-of-stock items?
Revalidate at checkout against the system that holds the real stock, and fail the order before payment if the number has changed. Feeds and caches will always lag a little, so they're fine for discovery but not for committing a sale.
In the Agent checkout on stale stock scenario, the jacket sells out in-store while the webhook is failing. The feed still says 3, so an agent could offer it, and the order would be accepted on the feed's word. Revalidation compares the request to the ERP's 0 and blocks it with STALE_STOCK. The same principle applies to the tool layer in our catalog shopping assistant demo, where prepare_cart re-checks stock rather than trusting earlier reads.
On the feed side, OpenAI's product feed specification (checked 2026-11-29) requires an availability value on every row, says to update it when an item becomes available or sells out, and notes that unknown does not mean in stock. A pipeline that can't confirm freshness should prefer an honest status over a stale "in stock".
What are the lessons for an inventory integration?
- Assume every delivery can repeat. Without idempotency, a retry policy creates double decrements. With it, retries are free.
- Order by version, not by arrival. A delayed update can be the oldest one, and arrival order tells you nothing.
- Write the event with the change. The drift scenario exists because one path (a bulk import) bypassed the outbox. Reconciliation catches it, but late.
- Keep dead letters and make replay a button. A replay needs to be safe to run twice, and the version check makes it safe even after a repair.
- Budget freshness explicitly. In this simulation, the batch interval caused most of the lag, more than the failures did. Measure your own lag before choosing an interval.
- Revalidate at the point of commitment. Discovery can tolerate a slightly stale feed. Checkout can't.
If your inventory lives in an ERP, WMS, or PIM that your storefront or feeds don't read directly, our inventory and pricing API integration service scopes this pipeline for your systems. Where agents need live stock through tools rather than a feed, it connects to MCP server development. See all demonstrations for other working artifacts.
Frequently asked questions
Is this based on a real client's system?
No. It's a simulation with synthetic SKUs and a virtual clock, built to demonstrate the design. No client data, results, or measurements are involved.
Are the freshness numbers real measurements?
They are measured inside the simulation, so they're real for the simulated settings: a 400 ms delivery latency, a 15-second feed batch, and 120-second reconciliation. They are not measurements of any platform. Your actual lag depends on your systems and on each destination's processing time.
Why use both webhooks and reconciliation?
Webhooks are fast but can be lost, delayed, or never produced, as when a bulk import skips the event path. Reconciliation is slower but compares the actual state, so it catches whatever the events missed. Together they give low lag most of the time and correctness eventually.
What does an idempotency key protect against?
It protects against the same event being applied twice, whether the cause is a retry after a timeout, a duplicate delivery from the sender, or an operator replay. The receiver records which keys it has processed and ignores repeats, so stock is decremented exactly once.
How long should retries continue before giving up?
Long enough to ride out typical outages, but bounded, so failures surface in a dead-letter queue that someone watches. The demo uses five attempts with doubling waits and jitter. In production, tune these to your endpoint's behavior and to any limits set by the platform you integrate with.
Does a fresh feed guarantee AI agents will show my products correctly?
No. Freshness only means the feed reflects your stock. Whether and how an AI surface shows a product depends on that platform's eligibility, processing, and ranking, none of which your feed controls.
Is your stock data drifting between systems?
Tell us where inventory and prices live today, which channels and feeds read them, and where they fall out of sync.
Related
- Inventory & pricing API integrationScope this pipeline for your ERP, WMS, or PIM.
- Inventory sync: webhooks and retriesThe patterns in more depth.
- Catalog shopping assistant demoTyped tools that revalidate stock before a cart draft.
- Ecommerce MCP server developmentLive stock through tools instead of a feed.
- Headless commerceWhere the pipeline sits in a headless stack.
- All demonstrationsOther working artifacts.
Sources
- Agent Commerce Optimization: inventory-sync simulation engine and test script (built and run 2026-11-29)
- Shopify Dev Docs: Webhooks — Duplicate deliveries (X-Shopify-Webhook-Id), no ordering guarantee, reconciliation jobs.
- Stripe API reference: Idempotent requests
- OpenAI Commerce: Product feed specification — Required availability field; unknown does not mean in stock.
Platform capabilities, eligibility, and specifications change. Sources were checked on 2026-11-29; confirm the current primary documentation before scoping an implementation. See our editorial policy and methodology.