Commerce Architecture & Specs
An event-driven, schema-first commerce engine designed for strict ACID compliance, atomic inventory locking, real-time fraud detection, and offline-capable POS.
Performance & Commerce Metrics
P50 Checkout Latency
12ms
P95 Checkout Latency
42ms
API Throughput
10,000 req/sec (Horizontally Scalable)
Offline POS Sync
idempotency-keyed order replay on reconnect (server-side dedup) + a compiled pricing engine deployed to a connected Bridge POS register for local on-device pricing
Fraud Detection Latency
<5ms per order
Inventory Lock Timeout
5 seconds (prevents deadlocks)
Recovery Email Sequence
3-step (1h, 24h, 72h) with token-based URLs
1. Schema-Driven Architecture
Every commerce entity (products, orders, customers, subscriptions, gift cards) is a strictly typed collection backed by PostgreSQL 17.
Auto-Generated APIs: The platform's dynamic routing exposes REST endpoints providing 30+ filter operators, cursor/offset pagination, and sparse fieldsets out of the box.
Infinite Extensibility: Core structured fields map to indexed SQL columns for lightning-fast querying, while dynamic attributes (like custom product specs) map to flexible JSON fields, allowing schema flexibility without requiring costly database migrations.
Multi-Location Inventory: Inventory is tracked per-location with available, reserved, and committed quantities. Location-aware availability checks run during checkout.
2. Atomic Inventory Locking
Order processing relies on strict row-level database locking to ensure inventory counts are decremented atomically, eliminating double-sell race conditions during flash sales.
The Reserve Flow: 1. Stock is verified for each item (global or per-location) 2. A row-level lock is acquired on the affected product rows 3. A 5-second lock timeout prevents deadlock accumulation under high concurrency 4. On success, the reserved quantity increments; on failure, rollback releases all locks
Deduplication: Reservations are keyed to the order, so duplicate reservation calls for the same order return the existing reservation without re-reserving.
Release on Cancellation: Order cancellations return reserved stock to the available pool automatically, under the same locking guarantee.
3. Real-Time Fraud Detection
| Signal | Weight | Description |
|---|---|---|
| IP Velocity (high) | +40 | 6+ orders from the same IP in the last 24h |
| IP Velocity (elevated) | +20 | 3-5 orders from the same IP in the last 24h |
| Email Velocity | +20 | 4+ orders from the same email in the last 24h |
| High-Value Order | +30 | Order ≥ $3,000 |
| Elevated-Value Order | +20 | Order ≥ $1,000 |
| Moderate-Value Order | +10 | Order ≥ $500 |
| Disposable Email | +30 | Email domain in a 56-entry disposable-domain list |
| Billing Mismatch | +25 | Billing ZIP and state both differ from shipping |
| First Order + High Value | +15 | No prior orders from this email, and order > $200 |
4. Abandoned Cart AI Recovery
| Step | Delay | Subject Pattern | Content |
|---|---|---|---|
| Reminder | 1 hour | "You left items in your cart" | Product list + direct checkout link |
| Discount | 24 hours | "Complete your order with X% off" | Generated discount code + urgency |
| Final | 72 hours | "Your cart is about to expire" | Last chance + expiration countdown |
5. Subscription Renewals
A commerce subscription is the fulfilment record: the product line and quantity, the delivery address and window, the service zone, the delivery notes. The money — the saved payment method, the invoice per cycle, the charge, dunning — lives in Billing, which also runs the clock. Each commerce subscription links to its billing subscription; checkout creates both, and a customer who consents to automatic renewals has the card they paid with saved for them.
Renewal: when Billing announces billing.subscription.renewed, commerce raises the renewal order from the subscription's own snapshot (product, quantity, price, shipping), finalizes it as paid with Billing's transaction, and rolls its own period to match Billing's — exactly one order per invoice, however many times the announcement is delivered. Fulfilment, finance posting, loyalty and container deposits all follow from that order the way they follow from any paid order. When Billing could not charge (no saved card, or a manual-payment store), the order is raised pending payment against the open invoice. When Billing could not collect, the subscription follows the money into past_due.
Memberships: a subscription in on_request mode is enrolled but never renewed on a timer — the customer places an order when they need one, and delivery offers replace the schedule. Nothing in the clock touches it.
Customer self-service: pause, resume, skip the next period, cancel, change cadence (to one the product offers) or quantity, and change the delivery address — each reaches the billing subscription as well, so the clock and the fulfilment record never disagree.
Migration: a store can run on the legacy commerce clock and switch to Billing's per tenant, after a backfill gives every subscription its billing row with the same next renewal date. Exactly one clock is ever live for a tenant.
6. Native POS Hardware Integration
| Device | Protocol | Features |
|---|---|---|
| Receipt Printer | ESC/POS over USB/Serial | Line items, QR codes, store branding |
| Cash Drawer | Printer DCD pin or serial | Kick-open via print job |
| Card Reader | USB HID mag-stripe/chip | Masked card number only (PCI compliance) |
| Barcode Scanner | USB HID keyboard wedge | Real-time product lookup |
| Customer Display | USB/Serial | Running totals, item names |
| Label Printer | ESC/POS thermal | Price tags, shelf labels |
typescript
// Example: create an order via the Commerce APIconst res = await fetch("/api/v1/commerce/checkout", { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}` }, body: JSON.stringify({ cartId, paymentMethodId, // tokenized payment method from your gateway's SDK }),});
if (!res.ok) { const { errors } = await res.json(); throw new Error(errors[0].message); // e.g. "Order flagged by fraud detection"}
const { data: order } = await res.json();
// Example: print a POS receipt via Bridgeawait fetch("/api/v1/commerce/bridge/receipt/print", { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}` }, body: JSON.stringify({ storeName: "Downtown Store", orderNumber: order.orderNumber, items: order.items, subtotal: order.subtotal, tax: order.tax, total: order.total, paymentMethod: "Visa **** 4242", }),});These are planned integrations with Aeion Spatial, not yet shipped in Commerce. The intended design: a video editor that tracks moving products across frames so customers can add-to-cart directly from marketing video, and for 3D products, a visual node-based material builder that compiles into a ready-to-render 3D component for AR shopping. The underlying compilation engine ships today (used elsewhere in the platform); the shoppable-hotspot editor and the 3D-configurator generator for Commerce specifically are on the roadmap.
B2B portals use dedicated wholesale price lists keyed by customer tier and minimum quantity thresholds. Order routing evaluates these rules at checkout, applying tier-specific pricing and payment terms (net-15, net-30, net-60). Multi-tier approval workflows route large orders through configurable approval chains before fulfillment.
Smart order routing evaluates available inventory locations against shipping cost and delivery time tradeoffs. It considers: real-time stock levels, customer location, warehouse proximity, carrier rates, and fulfillment cost. Routing decisions optimize for either cost (cheapest warehouse) or speed (fastest delivery) based on cart configuration.