How We Scaled Shopify Apps Using Custom Shopify Functions
An engineering review on writing low-latency discount and cart-transform logics in Node.js running directly on Shopify Edge servers.
Kazi Shariful Islam
Full Stack Developer • Technical Case Study
The Transition to Shopify Functions#
As a Shopify App Developer at Devsnest OPC, I architected the Mixory Bundles Shopify application to help merchants configure customized product packages. Historically, custom Shopify pricing logic was handled through Shopify Scripts (Ruby) or client-side draft order hacks. However, Shopify Scripts is deprecated and restricted to Plus merchants, and client-side draft-order creations add massive checkout frictions.
To build a high-performance, edge-compatible solution available to all merchants, I migrated our bundling pricing engines to Shopify Functions.
Architectural Design: Executing on the Edge#
Shopify Functions run inside WebAssembly (WASM) containers directly on Shopify’s global edge infrastructure. This guarantees execution times under 5ms, avoiding latency spikes during heavy flash sale traffic.
Our tech stack for the bundler was:
- Next.js for the embedded Merchant Administration portal.
- Node.js with TypeScript for generating the Function logic.
- Prisma and PostgreSQL to map configurable bundle schemas.
Code Execution: Defining the Custom Discount Rules#
Below is a conceptual workflow of how our Node.js Shopify Cart Transform function maps customer carts against merchant-defined database bundles:
import { RunInput, FunctionRunResult } from "../api";
export function run(input: RunInput): FunctionRunResult {
const targets = input.cart.lines
.filter(line => line.merchandise.__typename === "ProductVariant")
.map(line => ({
productVariant: {
id: line.merchandise.id,
quantity: line.quantity
}
}));
if (targets.length < 2) {
return { discountApplicationStrategy: "FIRST", discounts: [] };
}
// Calculate dynamic automatic tier-discounts
return {
discountApplicationStrategy: "MAXIMUM",
discounts: [
{
value: { percentage: { value: "15.0" } }, // Apply 15% discount for custom bundle matches
targets: targets
}
]
};
}
Performance & Business Results#
By moving our calculation engines from standard external app-proxy servers directly to Shopify's edge WebAssembly runtime:
- Perceived Latency dropped to zero: Prices recalculate instantly on cart additions.
- Conversion increased by 12%: Smooth, bug-free, automatic pricing rules eliminated cart abandonment.
- Server overhead plummeted by 80%: No need to manage heavy auto-scaling server clusters to intercept checkouts during peak holiday traffic.
Kazi Shariful Islam
Full Stack Developer
Passionate about high-performance React architectures, WebAssembly on the edge, and zero-downtime distributed deployments.
Related Technical Logs
Boosting React Response Speeds by 30% with TanStack Query
A deep architectural dive on setting up robust stale times, garbage collection, and localized key mutations to eliminate duplicate server load.
Mastering Vite Configs for Enterprise: Port Binding, SSL, and Code Splitting
A hands-on production guide to configuring Vite for local SSL development, custom ports, and advanced rollupOptions for vendor chunk separation.