Engineering notes

Prevent Overselling Across Your Store and Marketplaces

Design stock reservations, order states and reconciliation so two sales channels cannot quietly promise the same unit to different customers.

Bitcave6 min readUpdated

A store can display a plausible stock number and still sell an item it cannot ship. The difficult moment is not a routine stock refresh: it is two buyers checking out while a marketplace update is delayed. This guide uses a hypothetical retailer to explain where stock authority belongs, how reservations expire and what the operations team needs when systems disagree. The examples are design scenarios, not reported client results.

Define what available actually means

Start with a small inventory vocabulary. On-hand is what physically exists; reserved is what a live order holds; unavailable covers damaged goods, quarantine and other exclusions. Available-to-promise is a business rule built from these quantities, not the last number returned by a channel API. Decide whether stock is shared across warehouses and whether a paid but unpicked order can be reassigned. A product variant needs a stable internal identifier and an explicit mapping to each marketplace listing.

In the example retailer, customer support can see physical stock, active reservations and the last successful channel update together. It cannot edit a single unexplained total. Every adjustment has a reason, an actor and a reference to the stock movement that caused it. This makes a stock discrepancy an investigable event rather than a recurring spreadsheet argument.

Conceptual warehouse illustration with two sales channels passing through one stock reservation gate

Generated editorial illustration; not a record of a live system.

Reserve atomically at the point of commitment

A read followed by a separate write leaves a race: two requests can both read one remaining unit. The reservation decision and stock change need one database transaction. Depending on the model, use a conditional update that succeeds only when sufficient stock remains, or acquire the relevant row lock before checking and changing the quantity. Keep the transaction short; never wait for a marketplace or payment API while holding it.

This protects the authority you control. It does not magically serialize an independent marketplace checkout. For channels that cannot reserve against your authority, allocate channel quotas or maintain a safety buffer, then document the residual risk. If stock spans several rows, lock them in a consistent order and define how deadlocks are retried. The PostgreSQL locking documentation explains the mechanism; the allocation rule remains a product decision.

Treat order state as a business contract

A reservation should have an identifier, quantity, expiry and explicit states such as active, consumed and released. Repeated delivery of the same external order must find the same reservation rather than subtract stock again. A unique channel-plus-order identifier gives the handler a durable deduplication boundary.

Expiry needs coordination with payment. A payment confirmation that arrives after release must enter a visible exception path: re-reserve if stock remains, otherwise follow the agreed customer-resolution process. Do not silently turn every late event into success. Keep an audit history of the transition and separate warehouse dispatch from payment confirmation, because those are different commitments.

Synchronize changes and reconcile independently

Write the stock change and an integration event in the same local transaction, then let a worker publish channel updates. That avoids a successful local commit disappearing because an API call failed afterward. Workers need bounded retries, a last-error record and a way to pause a failing channel without stopping local order processing.

Reconciliation is a second control, not a substitute for correct writes. Compare channel quantities and order identifiers with the authoritative ledger on a schedule appropriate to the sales rate. A mismatch needs an owner, an age and a resolution status. If the marketplace cannot guarantee fresh reads, label the observation time rather than pretending the comparison is instantaneous.

Test the exceptions before increasing traffic

Exercise two simultaneous checkouts for the final unit, duplicate orders, an update timeout after the remote side succeeded, cancellation after picking and payment after reservation expiry. Restart the worker between the local commit and the channel acknowledgement. The expected outcome should be written down for each case, including which team intervenes.

Useful operating signals include oversell exceptions, reservation age, oldest unpublished event and reconciliation backlog. Measure them from actual events and keep test data out of production reporting. A controlled rollout can begin with one warehouse and one channel, then expand after the team can explain every discrepancy. Success means stock promises are traceable and exceptions are actionable; no numerical improvement is implied without a measured baseline.

Where to start

Map one SKU from receiving through reservation, payment, dispatch and return. Mark the system that owns each transition and the identifier crossing every boundary. If two systems both claim to own available stock, settle that responsibility before adding another synchronization job. For a broader view of asynchronous delivery, read the related event-driven architecture note; for implementation scope, review the systems integration service.

Worked example and implementation boundary

Consider a fictional SKU with one available unit. Two checkouts arrive together. The reservation transaction for order A succeeds and records its unique order reference; order B receives an explicit unavailable result. Replaying A returns its existing reservation. If A expires before a late payment arrives, the payment handler checks whether a new reservation can be made and otherwise opens a customer-resolution case. This example assumes the checkout uses the authoritative stock service; an independent marketplace still needs an allocation policy.

Illustrative PostgreSQL fragment, not a complete reservation endpoint. No returned row means the requested quantity was not reserved. The same transaction must enforce the unique order-operation identity and create its reservation record; a conflict must roll back the stock change. Validate a positive quantity, scope the tenant from authorization, and keep external API calls outside this transaction.

-- PostgreSQL: one guarded step inside the reservation transaction.
-- Bind tenant, SKU and a validated positive quantity on the server.
UPDATE inventory
SET reserved = reserved + $3
WHERE tenant_id = $1
  AND sku = $2
  AND on_hand - reserved >= $3
RETURNING on_hand - reserved AS remaining;

Trade-offs and limitations

A channel quota reduces simultaneous competition but can leave units idle on one channel while another runs out. A shared reservation authority improves coordination only where every commitment can reach it. Choose the policy against the cost of an oversell, channel API limits and tolerance for temporarily unavailable stock.

Common pitfalls

Do not hold a database lock while calling a payment provider, identify duplicate orders by amount alone, or treat a late payment as proof that inventory is still reserved. A periodic count comparison cannot repair an undefined ownership model.

Key takeaways

Define available-to-promise, commit reservations atomically, give repeated orders a durable identity and make late events reviewable. Before adding a channel, demonstrate the final-unit race and explain the recovery owner.

References and further reading

Primary technical documentation

Related reading and implementation support

Systems Integration and Workflow Automation

Payment Webhooks: Handle Duplicates and Late Events

Related content

Systems Integration and Business Workflow Automation

Connect your applications and automate repeatable processes with clear rules, visible status and a defined way to handle exceptions.

Payment Webhooks: Handle Duplicates and Late Events

Keep payment events from creating duplicate orders. A practical design for signature checks, durable inboxes, retries and visible exceptions.

Define the implementation boundary

Discuss inventory synchronization in the context of your current systems, decision owners and exception paths, then define a bounded first step.

Discuss your project