Learning pathsPricingChecking sign-in…
In the Wild

Shopify Inventory Reservations

Shopify’s account describes replacing Redis reservations with MySQL.

Shopify’s account describes replacing Redis reservations with MySQL. It uses a bounded pool of rows representing available units and SKIP LOCKED to avoid waiting on the same locked rows. Keeping reservations and the inventory ledger together permits transactional updates. The post also emphasizes primary-key layout, lock behavior, consistent lock ordering and visibility into connection usage. The central lesson is a migration away from the earlier split-store design. Source publication: 2026-05-12. The walkthrough below is an original interview exercise, not an undocumented claim about the company.

Follow reservation ownership through expiry

This is an independent two-unit exercise, not a claim about Shopify's current implementation. Inventory has quantity 2. H1 reserves one and H2 reserves one, so available quantity is zero. H1 expires and a transaction releases exactly H1; availability becomes one. A later expiry retry must not release H2 or release H1 twice. A late H1 payment confirmation checks the matching hold and enters the declared compensation flow if that hold is no longer valid.

Contract / pseudocode
start: total 2; held 0; available 2
H1,H2 active: held 2; available 0
expire H1 once: held 1; available 1
retry H1 expiry: held 1; available 1
start: total 2; held 0; available 2; H1,H2 active: held 2; available 0; expire H1 once: held 1; available 1; retry H1 expiry: held 1; available 1
Follow reservation ownership through expiry
Read the diagram

start: total 2; held 0; available 2; H1,H2 active: held 2; available 0; expire H1 once: held 1; available 1; retry H1 expiry: held 1; available 1

Open original
Follow reservation ownership through expiry
start: total 2; held 0; available 2; H1,H2 active: held 2; available 0; expire H1 once: held 1; available 1; retry H1 expiry: held 1; available 1

Follow reservation ownership through expiry

Relational inventory/reservation rows can keep the applicable state transition in a transaction. A volatile cached display remains useful, but is not the authority. Bound expiry work and use applicable indexes rather than scanning all historic holds each pass. Payment is a separate effect; a local stock transaction cannot roll it back. Read the linked first-party publication for its stated design and scope, keeping this exercise distinct.

Show answer and explanation

Answer: Expiry identifies H1 and its state/version, not simply “release one unit for this SKU.” Otherwise a stale worker can corrupt a newer owner's stock.

Step-by-step reasoning

1. State the invariant

For an independent stock exercise, start with 100 units and require available + reserved + sold = 100. A reservation transfers units between states; it does not manufacture stock. Record reservation identity so an expiry callback can release each hold at most once.

2. Distinguish lock avoidance from availability

Suppose ten rows exist and another transaction currently locks eight. A SKIP LOCKED query may return only two even though more stock could become available shortly. Decide whether to retry briefly, report temporary contention or use a replenishment protocol. Do not interpret skipped rows as permanent out-of-stock evidence.

3. Bound work inside the transaction

Select a limited number of rows, validate quantity and move them to the reserved state in one short transaction. Lock shared tables in the same order across reserve, release and claim operations. Keep payment network calls outside that transaction; they have independent failure and latency behavior.

4. Measure the actual bottleneck

For this exercise, compare database CPU, lock-wait duration, connection occupancy and transaction time. Low CPU with exhausted connections suggests held connections or slow external work inside transactions. Increasing database size alone may not remove that constraint.

Contracts and state

The following sketch makes the decision boundary concrete. Field names and capacity assumptions are illustrative; adapt them to the stated product contract.

Contract / pseudocode
reservation(id, sku, quantity, state, expires_at)
unit_pool(sku, unit_id, location_id)
SELECT ... FOR UPDATE SKIP LOCKED LIMIT requested_quantity
Validate count; move selected units; commit

Worked example

Original exercise: 20 requests each try to reserve one of 10 units. Allow ten commits and ten explicit unavailable or retry outcomes. Then expire three reservations and replay the same expiry events twice. The final available count must increase by exactly three, and a claimed reservation must never be released by an old expiry event.

Failure walkthrough

Original failure probe: payment succeeds but the response is lost. Persist an uncertain payment outcome and reconcile before releasing or confirming inventory. A conditional transition on reservation ID prevents a delayed expiry worker from undoing a completed sale. Keep a discrepancy report that compares ledger totals and reservation states.

Select available rows → Create hold transactionally → Call payment outside the transaction → Claim the matching active hold → Reconcile an uncertain payment
Shopify Inventory Reservations · scenario walkthrough
Read the diagram

Select available rows → Create hold transactionally → Call payment outside the transaction → Claim the matching active hold → Reconcile an uncertain payment

Open original
Shopify Inventory Reservations · scenario walkthrough
Select available rows → Create hold transactionally → Call payment outside the transaction → Claim the matching active hold → Reconcile an uncertain payment

Shopify Inventory Reservations · scenario walkthrough

Decisions and trade-offs

DecisionUseful whenCost to explain
Adopt the mechanismThe same workload constraint is demonstratedValidate with your own measurements
Keep a simpler designYour scale and guarantees are already metMonitor the trigger for changing it

Check your understanding

Why is a per-unit row pool useful under contention, and what cost does it introduce?

Show answer and explanation

Answer: It offers multiple lockable units instead of one hot quantity row. It also increases row and replenishment work. A bounded pool and measured transaction behavior are necessary; the model is not automatically superior for every inventory workload.

Primary documentation

Read the first-party engineering account or official technical reference. Company engineering posts describe the scope and date of that publication; the interview reconstruction and scenarios here are original teaching examples.

Continue the connection

Study Ticketmaster and explain which guarantee from this lesson carries into that topic.

Decision review: Shopify Inventory Reservations

Shopify Inventory Reservations: What it is

This case studies a published reservation migration. Its documented MySQL boundary is distinct from our generic inventory/payment exercise.

Shopify Inventory Reservations: Why it is needed

Reservations and ledger ownership must agree, while shared connection occupancy can constrain throughput independently of individual query latency.

Shopify Inventory Reservations: When to use it

Use the published case to study measured contention and rollout decisions, not to assume every reservation workload needs its exact implementation.

Shopify Inventory Reservations: How to use it

For the original exercise, give each reservation an identity, enforce eligible ownership transitions and separate an empty executable pool from authoritative stock exhaustion. Bound refill work and observe transaction/connection occupancy.

Shopify Inventory Reservations: Compare an alternative

A single quantity row is simpler at low contention. A bounded unit pool changes contention and refill semantics, so compare under the measured workload before adopting it.

Shopify Inventory Reservations: Published evidence and limits

First-party engineering article — published 2026-05-12.

The post describes moving reservations to MySQL, bounded unit pools and investigation of connection occupancy.

The article describes its particular database and rollout context; our retry/expiry fixture is an original model, and external payment atomicity is not inferred.

Shopify Inventory Reservations: Worked decision exercise

The following inputs and policies are original exercise assumptions; they are not measurements or undisclosed company behavior.

Our fixture starts with ten units and twenty requests. Ten eligible reservations succeed; the rest follow explicit retry/unavailable policy. Three unclaimed holds expire. Replaying those expiry events must release only those three units, not six.

Shopify Inventory Reservations: Exercise: 10 units, 20 competing reservation requests; 10 eligible holds succeed under the ownership rule; 3 unclaimed holds expire once; Replaying expiry still releases 3, not 6
Shopify Inventory Reservations: a concrete state and recovery trace under the exercise assumptions.
Read the diagram

Exercise: 10 units, 20 competing reservation requests; 10 eligible holds succeed under the ownership rule; 3 unclaimed holds expire once; Replaying expiry still releases 3, not 6

Open original
Shopify Inventory Reservations: worked example
Shopify Inventory Reservations: Exercise: 10 units, 20 competing reservation requests; 10 eligible holds succeed under the ownership rule; 3 unclaimed holds expire once; Replaying expiry still releases 3, not 6

Shopify Inventory Reservations: a concrete state and recovery trace under the exercise assumptions.

Does a local transaction make an external payment and stock claim atomic together?

Show answer and explanation

Answer: No. The source’s local reservation/ledger integration must not be extended to an arbitrary provider. Our exercise records uncertain payment separately and conditions expiry/claim on the current reservation. A missed reply cannot justify a second claim or release.

Shopify Inventory Reservations: Check the design

Verify source/date and context for reported measurements. In the exercise, inspect lock wait, connection hold time, refill latency and stale release rejection.

Your study notes