Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Shopify Engineering 8 min read Case study mediumAdept

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

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.

Related posts

  • How we scaled the GitHub API with a sharded, replicated rate limiter in Redis

    GitHub Engineering mediumAdept

    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. Two bugs followed. Deriving X-RateLimit-Reset from Redis TTL plus Ruby's clock made the header 'wobble' by a second. Lazy key expiration on replicas made reads return stale windows, so clients were rejected while seeing a full remaining quota. The fix was to store the reset-at timestamp explicitly, treat expired data as absent in application logic, keep Redis TTL only as cleanup one second later, and reuse the first read's result for response headers instead of making a second call.

  • From Event-Driven Chaos to a Blazingly Fast Serving API

    Zalando Engineering mediumAdept

    Zalando replaced an event-driven pipeline that merged Product, Price and Stock events with a central Product Read API (PRAPI). During Cyber Week that pipeline delayed price and stock updates by up to 30 minutes, because over 90% of each payload was unchanged. PRAPI is a Caffeine async-loading cache over DynamoDB, run on Kubernetes with Netty/Epoll non-blocking I/O, and serves millions of requests per second at sub-10ms P99. Consistent hash load balancing in Skipper partitions the catalogue so small per-pod caches hold hot products. Fixed ring positions and a bounded-load cap of 2× the average keep caches warm during scaling and stop hyped products from overloading a pod. Tail latency came down by caching payloads as byte arrays to avoid GC pauses, using LIFO queuing, and splitting DynamoDB clients into a 10ms primary and a 100ms fallback. Adoption across ~350 teams worked because PRAPI served the legacy formats via the Accept header, and the org was restructured along CQRS lines.

  • We replaced Redis with MySQL for inventory reservations—and it scaled

    Shopify Engineering mediumAdept

    Shopify moved checkout inventory reservations from Redis to MySQL by modeling one row per sellable unit and using SELECT ... FOR UPDATE SKIP LOCKED, so concurrent checkouts grab different rows without contention while reservations and the inventory ledger share ACID transactions. Key fixes included a bounded pool of 1,000 rows per item/location with locked inline replenishment, a composite primary key that halved row locks, READ COMMITTED to avoid gap/supremum locks, consistent lock ordering to prevent deadlocks, and UNION ALL batching. The real throughput ceiling turned out to be database connection exhaustion from other checkout code, found by tagging SQL with caller comments and measuring hold time in ProxySQL; cleanup cut 50% of reads and 33% of transactions, and raising InnoDB thread concurrency removed the limit. Cutover used dual-write shadow mode with a kill switch and gradual pod-by-pod rollout.

  • Keeping it 100(x) with real-time data at scale

    Figma mediumAdept

    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. The old design tailed a single globally ordered replication stream into per-server mutation-based caches, which caused excessive fan-in and fan-out, fragmented caches, thundering herds on deploy, and stalled optimistic updates whenever any shard blipped. Two traffic findings drove the redesign: most data is delivered by initial reads rather than live updates, and most queries can be invalidated directly from a row mutation. The result is a three-tier Go system: an edge that expands views, a read-through cache sharded by query hash, and stateless invalidators sharded like the databases that tail the replication streams and send invalidations only to the relevant cache shards.

  • Slack’s Incident on 2-22-22

    Slack Engineering mediumAdept

    A Consul agent rolling restart caused Mcrib, Slack's memcached control plane, to replace and flush cache nodes, dropping hit rates during peak traffic. A cache-fronted Group DM membership query hit a Vitess keyspace sharded by user, so every miss became a scatter query across all shards. Database load grew superlinearly, queries timed out, caches couldn't refill, and client retries kept the system stuck in a metastable cascading failure. Recovery required throttling client boots, fetching only missing keys, reading from replicas and later moving the query to a channel-sharded table; Mcrib's very efficiency at replacing nodes increased cache churn and worsened the outage.

The quest for software engineering knowledge.

Look:
Layout: