A headless storefront talks to a commerce API for catalog, cart, checkout, and inventory. That architecture buys front-end freedom and costs a set of distributed-systems problems that a monolithic platform hid inside one database transaction. Two of them dominate operations: the API’s rate limits, which arrive exactly when traffic spikes, and inventory consistency, which decides whether the last unit is sold once or twice.
The short version: budget requests per page render, cache catalog reads aggressively, and treat inventory as a reservation problem rather than a read-then-write problem.
Count the requests a page actually makes
A product page with variants, recommendations, reviews, and shipping estimates can easily produce fifteen API calls in a naive implementation. Multiply by peak traffic and you meet the rate limit without any unusual load. The first measurement is requests per render, by page type, and the second is the share of those that are cacheable.
Catalog reads are almost always cacheable with a short TTL and a stale-while-revalidate window. Cart and inventory reads are not, which is why the split matters: cache the ninety percent that is public, and keep the personalised calls small and few.
Rate limits are a concurrency problem
Most commerce APIs limit by requests per second per token, and some by burst. A storefront that fans out to the API from the browser spreads the limit across many clients, which helps until a single popular product page hits the same endpoint simultaneously. Server-side rendering concentrates the limit and makes the ceiling visible immediately.
Practical controls: a server-side queue with a concurrency cap, request coalescing so that twenty simultaneous requests for the same product become one upstream call, and a circuit breaker that serves cached or degraded content instead of queueing indefinitely. The breaker matters because a 429 storm during a sale is worse than slightly stale prices.
Inventory: read-then-write is a bug
The classic oversell happens when the storefront reads stock, shows one unit available, and the customer checks out slightly later than another customer who read the same number. The fix is not a shorter cache; it is moving the decision to a single authority. The commerce API’s reservation or checkout endpoint must be the place where stock is decremented, atomically, and the storefront must treat the displayed number as an estimate.
Design the flow as: display an estimate, attempt a reservation at add-to-cart or checkout, and confirm at payment. Reservations need a timeout so that abandoned carts release stock, and they need to be visible to the storefront so the estimate reflects held units rather than free ones.
Consistency across channels
Headless stores usually share inventory with marketplaces, a physical shop, or an ERP. Each channel has its own latency in reporting sales, so a unit sold on a marketplace may still appear available in the storefront for minutes. The oversell risk is a function of reporting delay multiplied by sales velocity.
Mitigate by holding a buffer: publish available stock as physical stock minus a channel-specific safety margin, sized from measured oversell incidents rather than guessed. For fast-moving SKUs, the margin should be several units; for slow ones, one is enough. A buffer is cheaper than a refund process and much cheaper than a customer who ordered a product that does not exist.
Failure behaviour worth designing
When the commerce API is slow or failing, the storefront must decide what to show. Options are: cached catalog with a banner, disabling add-to-cart for affected SKUs, or queueing checkout attempts. Each is defensible; silently showing a checkout button that will fail is not. Write the degradation policy down before the sale, not during it.
The same applies to rate limit responses. A 429 with a Retry-After header should be honoured by the client and translated into a user-facing state that does not lose the cart. Losing a cart during a throttle is a revenue bug disguised as an infrastructure event.
A worked example of a launch-day oversell
A headless store launches a limited drop of five hundred units. The product page reads stock from the catalog API and caches it for sixty seconds at the edge. Ten thousand users land within two minutes, all seeing the cached figure of five hundred. Add-to-cart succeeds for everyone, because the cart API does not check stock; checkout is where the count is decremented.
The drop sells nine hundred and forty orders against five hundred units, and the fulfilment team discovers it four hours later. The rate limits also bite in the same window: the storefront’s server-side rendering fans out twelve catalog calls per page, hits the API ceiling at the peak, and shows a degraded page to a share of visitors.
The corrected design caches the browse figure with an explicit “availability” label, reserves stock at add-to-cart with a five-minute hold, decrements at payment, and coalesces catalog calls so that a page render costs three upstream requests instead of twelve. The drop then sells exactly five hundred, with five percent of carts expiring from abandoned holds.
What to check before you commit
- Measure API requests per page render by page type.
- Cache catalog reads with TTL plus stale-while-revalidate; keep cart and inventory uncached.
- Cap server-side concurrency, coalesce duplicate requests, and add a circuit breaker.
- Make reservations the only place stock is decremented; display estimates, not promises.
- Publish a per-channel safety buffer sized from measured oversells.
- Write the degradation policy for slow and 429 responses before peak season.
Headless commerce is a good architecture with a specific set of hazards. Both hazards here are solved by deciding where the single authoritative answer lives, and by making the storefront honest about which numbers are estimates.
One further measurement is worth building before the next drop: a synthetic load test against the exact page types that will be hit, run at the rate limits the API publishes. It reveals which page type crosses the ceiling first and at what concurrency, and it usually shows that one page type, most often search with facets, is responsible for the majority of upstream calls. Fixing that page type is typically a day’s work and removes the 429 risk from the launch entirely.