Making Shopify’s Flagship App 20% Faster in 6 Weeks Using a Novel Caching Solution
Article Summary
Shopify's home feed was consuming 30% of their total database load and slowing down their entire app. Off-the-shelf caching solutions wouldn't cut it.
The Shop app serves tens of millions of users tracking orders from checkout to delivery. The engineering team needed a caching solution that could handle concurrent updates to sorted lists without ever serving stale data to users.
Key Takeaways
- Built custom write-through cache using Memcached in just 6 weeks
- Reduced database load by 15% and app latency by 20%
- Used pending writes counter to handle concurrent updates safely
- Tested correctness for weeks before rollout by comparing cache vs database
- Integrated seamlessly via Active Record Concerns with zero API changes
A custom caching solution delivered 20% faster performance and 15% lower database load in 6 weeks, proving that building your own infrastructure can beat off-the-shelf tools when requirements are unique.
About This Article
The Shop app's home feed had to pull together orders from millions of Shopify and non-Shopify merchants while tracking shipments across dozens of carriers. This made the whole operation expensive to run and slow.
Ryan Ehrlich's team built a write-through cache with Memcached. They added a pending writes counter that goes up before database updates and down after, plus an expiring key to catch interrupted processes and stop stale data from being served.
After rolling this out, CPU usage dropped by double digits, GraphQL latency fell by 20%, and database servers handled less load. The team kept serving fresh data to tens of millions of Shop app users with no stale information leaking through.