---
title: "How Shopify Dynamically Routes Storefront Traffic"
description: "Shopify shifted storefront traffic from its legacy Rails storefront to a rewritten renderer using a rule-based routing system in nginx/OpenResty Lua load balancers, with rules stored as JSON in a control plane and managed via the spy chatbot so changes skip CI and deploys."
url: "https://swe.quest/articles/how-shopify-dynamically-routes-storefront-traffic-4416894393bf5cd2"
canonical: "https://shopify.engineering/dynamically-route-storefront-traffic"
source: "Shopify Engineering"
published: "2021-04-09"
difficulty: "medium"
kind: "Case study"
reading_minutes: 9
tags: ["load-balancing","deployment","refactoring","configuration","resilience"]
---

# How Shopify Dynamically Routes Storefront Traffic

A post on [Shopify Engineering](https://swe.quest/sources/shopify.md), published 2021-04-09, 9 min read, Case study. Original: [https://shopify.engineering/dynamically-route-storefront-traffic](https://shopify.engineering/dynamically-route-storefront-traffic)

## Summary

Shopify shifted storefront traffic from its legacy Rails storefront to a rewritten renderer using a rule-based routing system in nginx/OpenResty Lua load balancers, with rules stored as JSON in a control plane and managed via the spy chatbot so changes skip CI and deploys. Each rule specifies filters, target shop IDs, and sampling rates for rendering, forward verification (legacy renders, new storefront checked), reverse verification, and self-verification against the local region's deployment. Rules are checked in the nginx rewrite phase, verification is decided in the header filter phase, and duplicate requests are sent asynchronously via nginx timers in the log phase so clients never wait on both upstreams. The same mechanism let the team mirror traffic to a separate deployment disconnected from Redis to test resilience before BFCM.

Written by swe.quest, not by the author.

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

## Topics

- [Load balancing](https://swe.quest/tags/load-balancing.md) (Infrastructure)
- [Deployment](https://swe.quest/tags/deployment.md) (Reliability & operations)
- [Refactoring & migrations](https://swe.quest/tags/refactoring.md) (Engineering practices)
- [Configuration management](https://swe.quest/tags/configuration.md) (Reliability & operations)
- [Resilience](https://swe.quest/tags/resilience.md) (Distributed systems)

## Prerequisites

- nginx request phases
- reverse proxy load balancing ([easy posts on Load balancing](https://swe.quest/tags/load-balancing.md?difficulty=easy))
- Lua basics

## Keywords

Shopify, nginx, OpenResty, Lua, spy, Storefront Renderer, Redis, MySQL

## Related posts

- [Möbius: Shopify’s Unified Edge](https://swe.quest/articles/mobius-shopify-s-unified-edge-dc92594de9527689.md): Shopify Engineering · 2022-04-20 · Medium · 9 min read · CDN & edge, Load balancing, Networking, System design, Kubernetes
  Shopify replaced more than six distinct ingress paths (GenPop core, apps, PII-restricted regions, mTLS APIs) with a single edge, Möbius, backed by a unified routing layer, Shopify Front End (SFE).
- [How We Built Oxygen: Hydrogen’s Counterpart for Hosting Custom Storefronts](https://swe.quest/articles/how-we-built-oxygen-hydrogen-s-counterpart-for-hosting-custom-storefronts-456fa9160b3a6002.md): Shopify Engineering · 2022-08-23 · Easy · 6 min read · Serverless, CDN & edge, Observability, E-commerce, System design
  Oxygen, Shopify's hosting platform for Hydrogen custom storefronts, assembles GitHub, GitHub Actions and Cloudflare Workers with first-party Shopify services such as the CDN, Admin API and identity.
- [Dynamic ProxySQL Query Rules](https://swe.quest/articles/dynamic-proxysql-query-rules-1a5fc44afbe14316.md): Shopify Engineering · 2021-04-20 · Medium · 10 min read · MySQL, Configuration management, Resilience, Incidents & postmortems, Distributed systems
  Shopify runs thousands of ProxySQL instances in front of MySQL and uses query rules to reroute, rewrite or reject queries matching a regex, often during incidents.
- [How we prepare Shopify for BFCM](https://swe.quest/articles/how-we-prepare-shopify-for-bfcm-4b4a641105e86a3e.md): Shopify Engineering · 2025-11-20 · Medium · 8 min read · Chaos engineering, Capacity planning, Scaling, SRE, E-commerce
  Shopify readies for Black Friday Cyber Monday with a year-long program that runs from March to October.
- [Creating a Flexible Order Routing System with Shopify Functions](https://swe.quest/articles/creating-a-flexible-order-routing-system-with-shopify-functions-913fde626973c1ef.md): Shopify Engineering · 2023-04-13 · Medium · 8 min read · E-commerce, System design, WebAssembly, Rust
  Shopify rebuilt its order routing, which picks the inventory location an order ships from, around composable "routing rules".

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)
