Replacing Stocky before Shopify switches it off

StocKey: Inventory & Purchasing

Shopify is retiring Stocky. This replaced it — with the team's own math.

The problem

Stocky shuts down on August 31, 2026, and every purchase order, cost and count ran through it.

Country Life Natural Foods buys from many suppliers, much of it in bulk cases that are repacked in-house into smaller sizes. Stocky held the suppliers, the purchase orders, the receiving and the stock counts, and Shopify is discontinuing it. A replacement had to do more than copy screens. The team had a paper worksheet for how much to order that no off-the-shelf forecast matched; costs in Shopify had to include freight, which is charged per pound; and every inventory write goes straight into the live store, where a double-counted delivery or a wrong cost is a real problem for the people selling those products the same day.

test cases
942test cases
data models
24data models
reports
10reports
test files
73test files
GraphQL operations
27GraphQL operations
commits
353commits

How it works

StocKey is a Remix app embedded in Shopify admin, with PostgreSQL behind Prisma for suppliers, purchase orders, sales history and costs, and Shopify's Admin GraphQL API as the system of record for stock. Every write to Shopify goes through one guarded layer: a single environment switch must be exactly "true" for anything to reach the store, each inventory write carries a stored idempotency key, and quantity changes are compare-and-set against the stock that was read. Sales history arrives from an order webhook and a daily cron that overlaps by a day, so a missed delivery heals itself. The math that people check by hand — the forecast, landed cost, expected dates, rounding — lives in small pure modules with the team's own worked examples as tests, separate from the code that talks to Shopify.

Engineering decisions

The non-obvious calls — where the straightforward approach fails, and what it cost to find that out.

01

The forecast is the team's worksheet, not a textbook formula

Why it breaks

A generic "sales per day × days" forecast did not subtract stock on hand, treated every size as its own product, and double-counted unfulfilled orders by reading Shopify's available stock. The store buys bulk cases and repacks them into smaller bags, so a per-size forecast orders the wrong thing entirely, and its numbers never matched the purchasing team's paper worksheet.

What I did

The forecast implements the team's rule exactly: the larger of the last 90 days and a quarter of the last year, scaled to the chosen horizon, minus stock on hand. Sizes marked as repacked are converted to pounds and rolled into the bulk size the store actually buys, rounded to the nearest case to match the worksheet. Units on open orders are shown in the note but never counted as stock. The worksheet's own examples are the tests.

export function demandFromSales(
  sold90: number,
  sold365: number,
  days: number = DEFAULT_FORECAST_DAYS,
): Demand {
  const quarterlyAvg = Math.round(sold365 / 4);
  const usesYear = quarterlyAvg > sold90;
  const basis = Math.max(sold90, quarterlyAvg);
  return {
    sold90,
    sold365,
    quarterlyAvg,
    usesYear,
    need: Math.round((basis * days) / 90),
    days,
  };
}
app/utils/forecast.ts
02

Landed cost never guesses

Why it breaks

Shopify's cost per item should be raw cost plus freight, and freight is charged per pound. When a product has no weight, the obvious fallback — send the raw cost — quietly understates cost in the field the whole business reads margins from, and nobody would ever notice.

What I did

Every line gets one of four states. A supplier with no freight rate yet sends raw cost, so rates can be rolled out supplier by supplier without making anything worse. A missing weight or missing cost sends nothing, and the save message names those lines. The freight rate is captured on the order at confirm, so a later rate change never moves that order's costs, and freight is added after currency conversion so it is never converted twice.

03

Writes to the live store are off unless explicitly on

Why it breaks

The app had to be connected to the real store while it was still being checked. A flag that treats "false", a typo or an empty value as enabled — or one read once at startup — lets real inventory changes through at exactly the wrong moment.

What I did

One guard returns true only when the variable is exactly "true", and it is read on every call. Every inventory and cost write checks it first; a blocked write returns a clear "writes disabled" result instead of crashing, and the interface shows a banner saying the app is read-only.

04

A retry must not receive a delivery twice

Why it breaks

Generating a fresh idempotency key on each call deduplicates nothing: when someone clicks Confirm or Receive again after a timeout, Shopify sees a brand new request and adds the stock a second time.

What I did

Before calling Shopify, a key is stored per shop, operation, record and content hash. A retry of the same operation reuses it, so Shopify drops the duplicate; an edited operation hashes differently and gets a new key. Confirm is also a single-winner status flip, and every quantity write states the stock it expects to change from, so Shopify rejects it if someone else moved stock in between.

05

Count orders, not order lines

Why it breaks

Sales history is stored one row per order and SKU, so adding up per-product order counts counts any multi-product order several times. And with sales syncing hourly, the list, the totals and the table of one report could each be read from different moments.

What I did

The orders report counts with COUNT(DISTINCT orderId) and runs every query in a single repeatable-read transaction, so one page always reflects one snapshot of the data.

06

A corrected SKU must not erase a year of sales

Why it breaks

Supplier products store the SKU they were created with. When a SKU is fixed in Shopify, the stored copy goes stale and a year of history silently stops counting toward the forecast — the product looks like it never sold.

What I did

The nightly catalog sync moves the old value into a previous-SKU field and copies in the live one, and the forecast matches sales on all three: live, stored and previous.

Correctness in production

What keeps it right once nobody is watching it run.

Production ships only what was merged

The deploy script refuses production unless the checked-out commit is exactly the merged main branch with no uncommitted changes, and deploys an archive of that commit rather than the working tree. It was added after an unmerged branch reached production once, and it has its own tests.

Every change passes the same gate

CI runs lint, type checking, the full test suite and a production build on a pinned Node version for every push and pull request.

Data scripts are dry runs by default

Backfill and dedupe scripts report what they would change and only write with an explicit flag; the dedupe dry run happens inside a read-only transaction. Migrations are additive.

Shopify failures never lose local work

A failed cost push changes the message, not the record: the purchase order is saved, and the lines that did not reach Shopify are named so they can be resent.

Outcome

The purchasing team builds, confirms and receives purchase orders inside Shopify admin, ahead of Stocky's shutdown. Suggested quantities follow the team's own worksheet — including the bulk cases repacked into smaller sizes — instead of a formula nobody trusted, Shopify's cost per item now carries freight, and receiving keeps a rolling average cost as deliveries arrive. Ten reports cover stock, sales, profit and purchasing, nine of them with CSV export.

Ready to upgrade your store's infrastructure?

Whether you want this exact architecture deployed to your store, or a completely bespoke solution built from scratch.

I want this exact solution.

Skip the R&D. I can deploy the StocKey: Inventory & Purchasing architecture directly to your operations in days, not months.

I need something custom.

Have a unique workflow? Let's build a bespoke app tailored perfectly to your complex business needs.