---
title: "Creating a Flexible Order Routing System with Shopify Functions"
description: "Shopify rebuilt its order routing, which picks the inventory location an order ships from, around composable \"routing rules\"."
url: "https://swe.quest/articles/creating-a-flexible-order-routing-system-with-shopify-functions-913fde626973c1ef"
canonical: "https://shopify.engineering/creating-a-flexible-order-routing-system-with-shopify-functions"
source: "Shopify Engineering"
published: "2023-04-13"
difficulty: "medium"
kind: "Case study"
reading_minutes: 8
tags: ["ecommerce","system-design","webassembly","rust"]
---

# Creating a Flexible Order Routing System with Shopify Functions

A post on [Shopify Engineering](https://swe.quest/sources/shopify.md), published 2023-04-13, 8 min read, Case study. Original: [https://shopify.engineering/creating-a-flexible-order-routing-system-with-shopify-functions](https://shopify.engineering/creating-a-flexible-order-routing-system-with-shopify-functions)

## Summary

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.

Written by swe.quest, not by the author.

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

## Topics

- [E-commerce](https://swe.quest/tags/ecommerce.md) (Domains)
- [System design](https://swe.quest/tags/system-design.md) (Architecture & design)
- [WebAssembly](https://swe.quest/tags/webassembly.md) (Languages)
- [Rust](https://swe.quest/tags/rust.md) (Languages)

## Prerequisites

- WebAssembly basics ([easy posts on WebAssembly](https://swe.quest/tags/webassembly.md?difficulty=easy))
- GraphQL basics ([easy posts on GraphQL](https://swe.quest/tags/graphql.md?difficulty=easy))

## Keywords

Shopify Functions, WebAssembly, GraphQL, Rust, smart order routing

## Related posts

- [How Shopify Dynamically Routes Storefront Traffic](https://swe.quest/articles/how-shopify-dynamically-routes-storefront-traffic-4416894393bf5cd2.md): Shopify Engineering · 2021-04-09 · Medium · 9 min read · Load balancing, Deployment, Refactoring & migrations, Configuration management, Resilience
  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.
- [Maestro: The Orchestration Language Powering Shopify Flow](https://swe.quest/articles/maestro-the-orchestration-language-powering-shopify-flow-a032ef3290783e5a.md): Shopify Engineering · 2022-05-13 · Medium · 12 min read · Language design, Static analysis, Scheduling, Resilience, Ruby
  Shopify rebuilt Flow around Maestro, a domain-specific orchestration language that decouples the merchant-facing visual editor from a horizontally scalable execution engine.
- [Introducing Roast: Structured AI workflows made easy](https://swe.quest/articles/introducing-roast-structured-ai-workflows-made-easy-0fdb158278ceca92.md): Shopify Engineering · 2025-06-18 · Easy · 9 min read · AI agents, AI for coding, Developer tools, Ruby, Testing
  Roast is Shopify's open-source, Ruby-based CLI framework for orchestrating structured AI workflows.
- [How Zillow runs 100 million daily notifications on AWS Step Functions](https://swe.quest/articles/how-zillow-runs-100-million-daily-notifications-on-aws-step-functions-43ac4ec68597baa8.md): AWS Architecture Blog · 2026-11-11 · Medium · 15 min read · Serverless, Communications, System design, Cloud platforms, Configuration management
  Zillow 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.
- [Shopify’s journey to faster breadth-first GraphQL execution](https://swe.quest/articles/shopify-s-journey-to-faster-breadth-first-graphql-execution-83f0f58b8c4dabd1.md): Shopify Engineering · 2026-03-12 · Hard · 14 min read · GraphQL, Performance engineering, Ruby, Query engines
  Shopify 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.

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)
