BlogsShopifyJavaScript Runtime for Shopify Functions

JavaScript Runtime for Shopify Functions

JavaScript Runtime for Shopify Functions

2
posts
2023

Shopify is expanding its Shopify Functions capabilities to support custom routing rules for order fulfillment. This involves leveraging Rust for default routing rules and enabling merchants to create their own rules using JavaScript compiled to WebAssembly (Wasm). The system utilizes a pipeline pattern for processing and a reducer for tie-breaking among rules. Future work will focus on opening up order routing for third-party developer-created rules.

2023

Creating a Flexible Order Routing System with Shopify Functions - Shopify

4/13/2023

This post details the implementation of a flexible order routing system using "routing rules" and Shopify Functions. It explains how routing rules are defined as functions that rank inventory locations based on criteria like proximity and destination market. The system uses a pipeline pattern for processing and a reducer to break ties between equally ranked locations. Three default routing rules (ship from closest, stay within destination market, ranked locations) were built using Rust and deployed as Shopify Functions, demonstrating dogfooding of the Functions feature.

Bringing Javascript to WebAssembly for Shopify Functions - Shopify

2/9/2023

This post details the technical journey of bringing JavaScript support to Shopify Functions, which are WebAssembly (Wasm) modules. It explains the core principles of Shopify Functions, emphasizing their role in backend customization and the critical role of WebAssembly. The post highlights the constraints imposed on these functions (module size, execution time) and the challenges of running JavaScript in Wasm due to the lack of JIT compilation support. It introduces Javy, a toolchain developed to compile JavaScript to Wasm, and discusses the use of QuickJS as the JavaScript engine. The post also details the initial approach using Wizer and QuickJS crates, which resulted in modules exceeding the size limit. It then explores dynamic linking as a potential solution for reducing module size, acknowledging its current limitations in Wasm standardization.