Creating a Flexible Order Routing System with Shopify Functions
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.
Related posts
- How Shopify Dynamically Routes Storefront Traffic
Shopify Engineering mediumAdeptShopify 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.
- Maestro: The Orchestration Language Powering Shopify Flow
Shopify Engineering mediumAdeptShopify rebuilt Flow around Maestro, a domain-specific orchestration language that decouples the merchant-facing visual editor from a horizontally scalable execution engine. Maestro coordinates calls to host-language (Ruby) primitive functions and records checkpoints to durable storage such as Kafka, Redis or MySQL, so interrupted executions resume without redoing completed steps, giving at-least-once semantics. Flow workflows are translated into Maestro functions. Maestro's static analysis (type checking, scope and field-navigation checks, symbol tables) drives fast in-editor validation and code completion. Activation adds usage analysis to limit GraphQL data hydration, plus compilation that strips unused definitions before deployment to the engine.
- Introducing Roast: Structured AI workflows made easy
Shopify Engineering easyNoviceRoast is Shopify's open-source, Ruby-based CLI framework for orchestrating structured AI workflows. It interleaves non-deterministic LLM steps with deterministic code through YAML workflow definitions and markdown/ERB prompts. Workflows can mix directory prompt steps, shell commands, inline prompts, custom Ruby steps, parallel steps, iteration and conditionals. Steps share conversation context, and session replay lets authors resume from any step without re-running expensive AI calls. A Claude Code-powered CodingAgent handles iterative tasks such as fixing Sorbet type errors after deterministic cleanup. The core lesson is that breaking agent tasks into discrete, guarded steps makes AI reliable enough for jobs like grading tests at scale.
- How Zillow runs 100 million daily notifications on AWS Step Functions
AWS Architecture Blog mediumAdeptZillow replaced more than 10 per-campaign notification generator services with a configuration-driven Campaign Orchestrator that runs each of 100M+ daily email and push notifications as a short-lived AWS Step Functions Express Workflow, calling a shared library of stateless, schema-driven content modules (the Universal Content Generator) via HTTP Invoke. Step Functions beat Temporal, Flowable and an in-house engine at roughly a quarter of the build and maintenance effort. Express mode was chosen over Standard for its higher start quota and low latency, with at-least-once semantics handled by idempotent modules. Key techniques include an SQS-fed router for pausing, replay and throttling, EventBridge connections for API-key auth, component inheritance compiled into task states, a declarative config layer that AI tools can safely generate, and batching for throughput and cost.
- Shopify’s journey to faster breadth-first GraphQL execution
Shopify Engineering hardMasterShopify built GraphQL Cardinal, a breadth-first GraphQL execution engine that calls each field resolver once with the full set of objects at that level instead of once per object. Depth-first execution, used by graphql-ruby and graphql-js, multiplies per-field overhead from tracing hooks, authorization and dataloader promises by response breadth. Cardinal builds a typed execution tree, runs a bottom-up lookbehind planning pass inspired by Grafast, and executes generation by generation with flat object/result sets in a queue-driven loop rather than recursion. Large list queries ran up to 15x faster with 90% less memory and saved over 4s at P50. The tradeoffs are that errors are inlined and located by a final depth traversal, and that migrating a monolith from one-in/one-out resolvers requires an incremental bridge.