Skip to content

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

Shopify Engineering 9 min read Case study mediumAdept

How Shopify Dynamically Routes Storefront Traffic

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.

Assumes: nginx request phasesreverse proxy load balancingLua basics

Related posts

  • Möbius: Shopify’s Unified Edge

    Shopify Engineering mediumAdept

    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). SFE is nginx with custom Lua deployed per region, fed by Kubernetes controllers that register application domains with a central API. Routing-layer active/active and active/passive load balancing then shifts traffic almost instantly, without waiting on DNS TTLs. Möbius terminates TCP and TLS at the provider's PoPs close to clients and reuses the SFE controller's domain data to automate domain validation and certificate issuance at the edge vendor, so migrating an app becomes a manual DNS switch plus per-app edge observability dashboards.

  • How We Built Oxygen: Hydrogen’s Counterpart for Hosting Custom Storefronts

    Shopify Engineering easyNovice

    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. Shopify briefly built its own V8-isolate infrastructure but chose Cloudflare's Workers for Platforms instead to ship faster and reduce scale and security risk. A Gateway Worker checks authorization and routes requests to per-storefront workers via the Dynamic Dispatch API, and a Trace Worker forwards logs and metrics to a separate Grafana/Loki/Cortex/Tempo stack that keeps merchant-facing telemetry apart from internal metrics.

  • Dynamic ProxySQL Query Rules

    Shopify Engineering mediumAdept

    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. To make rules safe, they patched their ProxySQL fork with a dry-run mode (active=0, log=1) that logs matched queries with exponential backoff instead of acting on them. A web app writes rules to a global key-value store, and a sidecar next to each ProxySQL polls it and syncs the mysql_query_rules table. If the sidecar and ProxySQL drift, both rule lists are wiped and rebuilt, favouring consistency over availability; rules also carry TTLs, and rules that must always be present are loaded statically from proxysql.cnf.

  • How we prepare Shopify for BFCM

    Shopify Engineering mediumAdept

    Shopify readies for Black Friday Cyber Monday with a year-long program that runs from March to October. It combines capacity planning on Google Cloud, What Could Go Wrong risk assessments, chaos-engineering Game Days on critical journeys like checkout, and a centralized Resiliency Matrix of failure modes, RTOs and runbooks. Five scale tests at forecast and p99 load (up to 200M requests per minute) used the Genghis load generator from three GCP regions, Toxiproxy fault injection and regional failovers. The tests surfaced issues such as checkout queue backups, rate-limit paths in authenticated checkout and slow region rebalancing. The newly rebuilt analytics platform needed more Kafka partitions, API memory optimization, connection-timeout tuning and load-balancer changes before facing its first holiday peak.

  • Creating a Flexible Order Routing System with Shopify Functions

    Shopify Engineering mediumAdept

    Shopify rebuilt its order routing, which picks the inventory location an order ships from, around composable "routing rules". Each rule is a Shopify Function written in Rust and compiled to WebAssembly. Each rule takes a GraphQL-shaped input and independently ranks eligible locations, with 0 as best; default rules cover closest location, staying within the destination market, and merchant-ranked locations. A reducer applies the rules in the merchant's chosen order, using each later rule only to break ties among locations ranked best by earlier ones. Replacing a tightly coupled nested-loop algorithm with a pipeline pattern (prepare input, run rules, reduce, output) made the code easier to understand and debug.

The quest for software engineering knowledge.

Look:
Layout: