---
title: "Making Shopify’s Flagship App 20% Faster in 6 Weeks Using a Novel Caching Solution"
description: "Shop's home feed, which aggregated orders and carrier tracking data and accounted for 30% of database load, was moved behind a custom write-through cache in Memcached, cutting database load by 15%, overall GraphQL latency by about 20% and CPU usage by a double-digit percentage."
url: "https://swe.quest/articles/making-shopify-s-flagship-app-20-faster-in-6-weeks-using-a-novel-caching-100f1c4cb3fa31e6"
canonical: "https://shopify.engineering/shop-app-custom-caching-solution"
source: "Shopify Engineering"
published: "2021-09-22"
difficulty: "medium"
kind: "Case study"
reading_minutes: 8
tags: ["caching","ruby","scalability","deployment","performance"]
---

# Making Shopify’s Flagship App 20% Faster in 6 Weeks Using a Novel Caching Solution

A post on [Shopify Engineering](https://swe.quest/sources/shopify.md), published 2021-09-22, 8 min read, Case study. Original: [https://shopify.engineering/shop-app-custom-caching-solution](https://shopify.engineering/shop-app-custom-caching-solution)

## Summary

Shop's home feed, which aggregated orders and carrier tracking data and accounted for 30% of database load, was moved behind a custom write-through cache in Memcached, cutting database load by 15%, overall GraphQL latency by about 20% and CPU usage by a double-digit percentage. To handle concurrent order updates without serving stale data, each user has a pending-writes counter that workers increment before a database write and decrement after it. A short-expiry key detects crashed writers so the cache can be safely rewarmed. The logic was mixed into Active Record models as concerns, so the ORM API was unchanged. Correctness was validated in a shadow rollout that compared cache and database reads before serving from the cache.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Caching](https://swe.quest/tags/caching.md) (Backend & APIs)
- [Ruby](https://swe.quest/tags/ruby.md) (Languages)
- [Scaling](https://swe.quest/tags/scalability.md) (Distributed systems)
- [Deployment](https://swe.quest/tags/deployment.md) (Reliability & operations)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)

## Prerequisites

- cache invalidation basics ([easy posts on Caching](https://swe.quest/tags/caching.md?difficulty=easy))
- Memcached ([easy posts on Caching](https://swe.quest/tags/caching.md?difficulty=easy))
- Rails Active Record ([easy posts on Ruby](https://swe.quest/tags/ruby.md?difficulty=easy))

## Keywords

Memcached, Redis, Shop app, Active Record, Ruby on Rails, GraphQL

## Related posts

- [How we scaled the GitHub API with a sharded, replicated rate limiter in Redis](https://swe.quest/articles/how-we-scaled-the-github-api-with-a-sharded-replicated-rate-limiter-in-redis-c2f9366d9d874889.md): GitHub Engineering · 2021-04-05 · Medium · 9 min read · Caching, Replication, API design, Scaling, Ruby
  GitHub replaced a Memcached-based API rate limiter, which suffered evictions and could not survive a move to per-datacenter caches, with application-sharded Redis clusters (one primary, several read replicas) and atomic Lua scripts, rolled out behind a feature flag.
- [From Event-Driven Chaos to a Blazingly Fast Serving API](https://swe.quest/articles/from-event-driven-chaos-to-a-blazingly-fast-serving-api-515d5b06058dbe2a.md): Zalando Engineering · 2025-03-06 · Medium · 8 min read · Caching, Load balancing, Event-driven architecture, Performance engineering, E-commerce
  Zalando replaced an event-driven pipeline that merged Product, Price and Stock events with a central Product Read API (PRAPI).
- [We replaced Redis with MySQL for inventory reservations—and it scaled](https://swe.quest/articles/we-replaced-redis-with-mysql-for-inventory-reservations-and-it-scaled-2f8fab4ab3565f02.md): Shopify Engineering · 2026-05-12 · Medium · 10 min read · MySQL, E-commerce, Concurrency, Scaling, Performance engineering
  Shopify moved checkout inventory reservations from Redis to MySQL by modeling one row per sellable unit and using SELECT ...
- [Keeping it 100(x) with real-time data at scale](https://swe.quest/articles/keeping-it-100-x-with-real-time-data-at-scale-3b49e279c5a600f2.md): Figma · 2024-05-17 · Medium · 19 min read · Caching, Real-time systems, Scaling, PostgreSQL, System design
  Figma rebuilt LiveGraph, its real-time GraphQL-like subscription service over Postgres, to scale reads and database update load 100x as the database moved from one instance to vertical and horizontal shards.
- [Slack’s Incident on 2-22-22](https://swe.quest/articles/slack-s-incident-on-2-22-22-7a35cde32cfb5fd8.md): Slack Engineering · 2022-04-26 · Medium · 12 min read · Incidents & postmortems, Caching, Resilience, MySQL, Distributed systems
  A Consul agent rolling restart caused Mcrib, Slack's memcached control plane, to replace and flush cache nodes, dropping hit rates during peak traffic.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
