Skip to content

A storefront is only the beginning of commerce operations

Orders become operational work. Design the connection to inventory and fulfilment around that reality, not around the checkout.

Published
Reading time
3 minutes
Written by
Cyber Vision engineering

A storefront platform handles the part customers see. Behind it, every order turns into work: stock to allocate, items to pick, parcels to label, exceptions to resolve. Most problems in commerce operations come from treating that work as a single status field.

Model the order lifecycle#

Payment, confirmation, allocation, packing and dispatch are related events with different owners. Write down which system owns each decision and how a person resolves an exception.

  1. 01Paid
  2. 02Allocated
  3. 03Picked
  4. 04Packed
  5. 05Dispatched
A typical lifecycle. Each transition has one owning system and a defined exception path.
StepOwnerTypical exceptionWho resolves it
PaidStorefrontPayment reviewStore operator
AllocatedInventory systemNot enough stockOperations
PickedWarehouseItem damaged or missingWarehouse lead
DispatchedCarrier integrationLabel rejected, address invalidCustomer service

Once ownership is explicit, it becomes clear which system should hold which state, and where synchronisation is actually needed.

Assume events can repeat#

Webhooks are delivered at least once. Treat each one as an input to a durable workflow: verify it, record its identity, then process it. A repeated delivery must not create a second shipment or decrement stock twice.

app/api/webhooks/orders/route.ts
import { createHmac, timingSafeEqual } from "node:crypto";
 
export async function POST(request: Request) {
  const raw = await request.text(); // verify the exact bytes received
  const signature = request.headers.get("x-shopify-hmac-sha256") ?? "";
  const expected = createHmac("sha256", process.env.SHOPIFY_WEBHOOK_SECRET!)
    .update(raw, "utf8")
    .digest("base64");
 
  const valid =
    signature.length === expected.length &&
    timingSafeEqual(Buffer.from(signature), Buffer.from(expected));
  if (!valid) return new Response("Invalid signature", { status: 401 });
 
  const deliveryId = request.headers.get("x-shopify-webhook-id");
  if (!deliveryId) return new Response("Missing delivery id", { status: 400 });
 
  // Record first, process asynchronously. Duplicates hit the unique constraint.
  const isNew = await inbox.insertIfAbsent(deliveryId, "orders/create", raw);
  if (isNew) await queue.publish("order.received", { deliveryId });
 
  return new Response(null, { status: 200 });
}

Respond quickly and do the real work in a worker. Providers retry slow endpoints, which multiplies duplicates exactly when your system is already under load.

Reconcile deliberately#

Events give a timely view. Reconciliation checks whether that view still agrees with the source. Webhooks get dropped, edits happen in two places, and a manual stock correction in the warehouse system will never arrive as a storefront event.

Make the work visible#

An operations interface should help someone find the orders that need attention, understand why, and take the next permitted action. Filters by exception type and age matter more than revenue charts. If an order has been allocated but not picked for six hours, that should be the first thing the warehouse lead sees.

Release one connected path#

Begin with a narrow path from a storefront order to a confirmed operational record. Before expanding, test the difficult cases on purpose:

  1. A cancellation after allocation.
  2. A partial fulfilment across two parcels.
  3. A return of one item from a multi-item order.
  4. A stock level that changed in the warehouse system mid-order.

A connected system earns trust through predictable handling of these cases, not through the happy path.

  1. Infrastructure · 3 min read

    Changing a PostgreSQL schema without taking the application down

    Expand, migrate, contract: how to add columns, indexes and constraints to a live table without long locks or a maintenance window.

  2. AI Engineering · 3 min read

    Why operational AI needs an approval boundary

    Separate analysing information from taking consequential actions, bind every approval to a specific change, and make each decision traceable.

  3. Software Architecture · 3 min read

    Idempotency keys in PostgreSQL: a pattern that survives retries

    Clients retry, webhooks repeat and networks time out. A small table and one unique constraint make a write safe to repeat.