Urgent.News

What's breaking now, across thousands of outlets.

Tech

Shopify replaced Redis with MySQL for inventory reservations–and it scaled

Article URL: https://shopify.engineering/scaling-inventory-reservations Comments URL: https://news.ycombinator.com/item?id=49226536 Points: 225 # Comments: 136

During checkout on Shopify, the system needs to ensure that items selected by buyers are still available. Getting this right is critical—overselling results in angry customers and lost sales, while underselling means missed revenue opportunities. On Black Friday 2025, merchants on Shopify's platform achieved a record $5.1 million in sales per minute at peak. This high volume of transactions involves inventory reservations, which necessitates a reliable system to handle oversell protection.

Previously, Shopify used Redis to handle inventory reservations during payment processing. However, a key challenge arose when the company decided to adopt a unified database strategy. The old system had issues with contention when using a single row with a quantity column. To address this, the team explored MySQL's SKIP LOCKED feature, which allows MySQL to skip locked rows and return available ones, reducing contention.

After implementing MySQL with SKIP LOCKED, the reservations were managed per sellable unit, with one row per unit instead of per item. This change allowed for ACID transactions across the reserve and claim steps, eliminating issues that could occur with Redis, such as payment success without inventory claim, or vice versa.

However, maintaining one row per unit for a large inventory could become problematic. To mitigate this, Shopify implemented a bounded pool of available rows, capped at 1,000 per item and location combination. This cap ensures the table remains compact and the SKIP LOCKED scan remains fast. If the pool is exhausted during a flash sale, a replenishment process is triggered inline to refill it, maintaining system performance without blocking other transactions.

The choice of a composite primary key (shop_id, inventory_item_id, inventory_group_id, id) in the MySQL table also proved beneficial, reducing the number of locks to one per row, which improved throughput. This design change, along with the use of SKIP LOCKED and a bounded pool, allowed Shopify to handle the peak traffic on Black Friday without dropping requests or compromising data consistency.

Written by urgent.news from Hacker News Best's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

This story

This is one outlet's version. Read the fullest account.

Read the original at shopify.engineering →

More in Tech

My server is a phone now

Article URL: https://seg6.space/posts/phone-server/ Comments URL: https://news.ycombinator.com/item?id=49226636 Points: 218 # Comments: 84

More from Saturday 8 August →