---
title: "Creating a Flexible Order Routing System with Shopify Functions"
description: "Shopify’s smart order routing replaces a one-size-fits-all approach to choosing which inventory location fulfills an order with configurable routing rules. Rules can rank eligible locations by proximity to the destination, staying within the destination market, or merchant-defined location priorities, and merchants can arrange them in an order in the admin. Each rule is a Shopify Function written in Rust, receives data shaped through a GraphQL query, and returns location rankings; a reducer resolves ties by applying later rules to locations tied at rank 0. The rebuilt process uses the pipeline pattern to separate input preparation, rule execution, reduction, and final location selection, improving readability and debugging compared with the earlier tightly coupled implementation. This first stage dogfooded Shopify Functions on its own merchant stores, with a later stage planned to let developers add more complex rules."
---

# Creating a Flexible Order Routing System with Shopify Functions

[Shopify](https://yomu.fyi/company/shopify) · 2023-10-18 · Apr 13, 2023

**Type:** Explainer

## Summary

Shopify’s smart order routing replaces a one-size-fits-all approach to choosing which inventory location fulfills an order with configurable routing rules. Rules can rank eligible locations by proximity to the destination, staying within the destination market, or merchant-defined location priorities, and merchants can arrange them in an order in the admin. Each rule is a Shopify Function written in Rust, receives data shaped through a GraphQL query, and returns location rankings; a reducer resolves ties by applying later rules to locations tied at rank 0. The rebuilt process uses the pipeline pattern to separate input preparation, rule execution, reduction, and final location selection, improving readability and debugging compared with the earlier tightly coupled implementation. This first stage dogfooded Shopify Functions on its own merchant stores, with a later stage planned to let developers add more complex rules.

## Context

Merchants fulfilling orders from multiple inventory locations need to decide which location should ship an order. The previous system primarily prioritized fulfilling all items from one location and used a merchant-defined prioritized location list to break ties, but different business setups require different routing factors and priorities.

## Approach / What changed

The system represents routing criteria as independently executed rules that rank eligible locations. Merchants select and order the rules in the admin, while a reducer resolves ties by applying subsequent rankings to locations tied at rank 0. Shopify implemented the default rules as Rust-based Shopify Functions using GraphQL-shaped input and rebuilt the surrounding process with a pipeline that separates input preparation, rule execution, reduction, and final location selection.

## Takeaways

- Default rules prioritize proximity to the destination, staying within the destination market, or ranked locations; merchants can combine them in the order they choose.
- The reducer resolves ties progressively: it starts with locations ranked 0 by the first rule and uses lower rank numbers from subsequent rules to select among them.
- The pipeline pattern separates order-routing stages, making the rebuilt process easier to understand and debug than the earlier tightly coupled implementation.

**Tags:** [Architecture](https://yomu.fyi/topic/architecture), [Developer Experience](https://yomu.fyi/topic/developer-experience), [GraphQL](https://yomu.fyi/topic/graphql), [Rust](https://yomu.fyi/topic/rust)

- Source: [Shopify](https://shopify.engineering/creating-a-flexible-order-routing-system-with-shopify-functions)
- Source URL: https://shopify.engineering/creating-a-flexible-order-routing-system-with-shopify-functions
- Ingested by Yomu: 2026-08-30T13:21:12.137Z

[Read original post](https://shopify.engineering/creating-a-flexible-order-routing-system-with-shopify-functions)
