Keeping Shelves Stocked: How Striim Turns CDC into Stockout Prevention

Table of Contents

The Problem

Imagine a typical Friday afternoon in October. A national retailer runs a flash promotion on a top-selling sports drink
SKU — 20% off, pushed via the loyalty app to 4 million subscribers. Sales velocity at Store #47 in Austin climbs from 12
units/hour to 58 units/hour within 20 minutes of the notification going out.  But nobody yet knows what’s
happening.   Store #47 · Austin, TX · Friday — the invisible stockout, minute by minute

Store #47 · Austin, TX · Friday · 5 events, 2:00 to 5:12 PM

 

The tragic thing about this example is how it could have been prevented. The information to prevent this was
available at 2:45 PM. Sales velocity was in the POS database. Inventory was in the warehouse management system. The
truck’s new ETA was in the logistics system. The answer — this SKU will run out 2.5 hours before its next replenishment arrives
— could have been computed by anyone with access to all three.   But who had access to all three sources? Nobody—
and even if they had, they’d have had to manually pull three reports, reconcile the numbers, and do the math themselves
— every 15 minutes, across 10,000 SKUs, across 200 stores.


The core dysfunction. POS, inventory, and replenishment systems were each built to optimize their own slice of the
business. None were designed to talk to each other in real time. Stockouts don’t happen because the data doesn’t
exist, they happen because the data isn’t correlated until it’s too late.

The Enterprise Scale Problem

Solving it for one store and one SKU on a Friday afternoon is feasible: a sharp analyst with a spreadsheet and three
tabs open could do it. Solving it continuously, for every SKU, across every store, in real time, is a fundamentally
different engineering problem.

  • Volume. A 200-store retailer with 10,000 active SKUs has 2 million supply/demand combinations to evaluate
    continuously. A batch job that runs once a night or every few hours can’t keep up with demand that changes by the
    hour during a flash sale.
  • Velocity. POS transactions fire thousands of times per minute across a store network. Inventory adjustments happen
    at receiving, at every sale, at every shrinkage write-off. Replenishment ETAs shift when trucks hit traffic or
    weather. The state changes faster than any polling interval can safely capture.
  • System heterogeneity. POS lives in PostgreSQL. Inventory management in Oracle. Logistics and replenishment in MySQL
    or SQL Server. Each system has its own schema, its own transaction semantics, its own change cadence. ETL pipelines
    that flatten these into a warehouse table lose the subsecond resolution you need to catch a spike before it becomes
    a stockout.
  • Latency budget. To be actionable — to give a DC manager time to call a nearby store, authorize an inter-store
    transfer, or re-route a truck — the alert needs to arrive at least 90 minutes before the shelf empties. That means
    detecting the risk signal within 10–15 minutes of the conditions forming, not the next morning.

 

What an Enterprise Solution Requires

A system that solves this at scale needs four capabilities to work seamlessly together:

Capability What it means Why batch fails here
Event-driven ingestion Capture every INSERT, UPDATE, and DELETE from each source system the instant it commits Batch ETL samples state at intervals; it misses changes between runs
Subsecond correlation Join demand velocity, inventory position, and replenishment ETA into a single risk score per SKU, continuously Overnight reconciliation only tells you what was true at midnight
Automated risk scoring Compute hours_of_supply and compare against hours_to_next_truck without human intervention Manual analysis can’t scale to 2M SKU×store combinations
Proactive alerting Push a notification to the right person the moment risk is detected, with context (SKU, store, runway, ETA) Dashboard polling means someone has to be watching; alerts find the right person

How We Solve This at Striim

Striim is a real-time data integration and streaming analytics platform built for exactly this class of problem:
multiple transactional source systems, sub-second change capture, and continuous query logic that correlates data in
motion before it ever reaches a data warehouse.   The answer here is not to build a faster batch job. It’s to treat
every committed transaction in every source system as an event, stream those events through a continuous correlation
engine, and write the risk signal to an open table format (Apache Iceberg on GCP Lakehouse) that feeds both dashboards
and alerts — without moving data through a staging layer first.


Our design principle. Don’t reconcile three systems at the end of the day. Correlate them continuously, the moment
each system speaks. The stockout risk score is a function of three live streams — not three overnight files.

Breaking Down the Problem

The stockout detection problem decomposes cleanly into seven responsibilities. Each maps to a specific Striim component.
Understanding the mapping is the key to building this correctly — and to extending it later.

# Problem component Responsibility Striim component Source system
1 Sales event capture Know every transaction the moment it posts PostgreSQL Reader PostgreSQL — POS
2 Inventory position tracking Know units on hand at all times, per store per SKU Oracle CDC Reader Oracle
3 Replenishment schedule Know when the next truck arrives, updated live as ETAs shift MySQL CDC Reader → EventTable MySQL — Logistics
4 Demand velocity computation Compute units/hour per SKU using a rolling time window CQ + Window POS sales stream
5 Supply vs. demand correlation Join velocity + inventory + ETA; compute hours_of_supply and risk flag CQ — StockoutCorrelationCQ POS · Inventory · Replenishment
6 Risk signal persistence Write the scored output to an open table format for BI and ML GCP Lakehouse Writer → Iceberg GCP — GCP Lakehouse

Component Deep-Dives

Each component has a specific responsibility in the pipeline. Here’s what each one does, what Striim capability it maps
to, and why the boundary matters.

1. Sales Event Capture

PostgreSQL · POS system
— PostgreSQL Reader (WAL / Logical Decoding)

Every sale that posts to the POS system writes a row to SALES_TRANSACTIONS. Striim tails the PostgreSQL
Write-Ahead Log (WAL) via logical decoding, capturing committed transactions with zero impact on the transactional
database. No polling, no triggers, no ETL job to schedule.   Responsibilities:

  • Capture every new transaction row the instant it commits
  • Emit a typed event: SKU, store, quantity, timestamp
  • Feed the demand velocity CQ (component 4)

 

2. Inventory Position Tracking

Oracle · Warehouse Mgmt System
— Oracle CDC Reader

The Oracle Warehouse Management System maintains the authoritative count of units on hand per SKU per store.
Striim’s Oracle CDC Reader captures changes from Oracle — every receiving adjustment, every sale deduction, every
shrinkage write-off — and streams them as InventoryLiveStream.   Responsibilities:

  • Maintain a real-time view of units_on_hand per SKU
  • Reflect receiving events (inbound stock) instantly
  • Feed the correlation CQ (component 5) via a 1-min window

 

3. Replenishment Schedule + Restock Detection

MySQL · Logistics system
— MySQL CDC Reader → Live EventTable

Truck schedules live in MySQL’s REPLENISHMENT_SCHEDULE table. Striim reads it via CDC — not as a static file, but
as a live stream. Every UPDATE to a truck ETA propagates to the in-memory cache within seconds. Every new INSERT (a
newly dispatched replenishment order) is a restock signal: fresh supply is confirmed before the truck even leaves the
DC.   Responsibilities:

  • Keep hours_to_next_truck current as ETAs shift
  • Detect restock events (new rows = new supply confirmed)
  • Serve as a fast lookup for the correlation CQ

 

4. Demand Velocity Computation

Derived · POS sales stream
— Continuous Query + 30-min Window

Raw transaction counts aren’t useful for predicting a stockout — velocity is. A 30-minute window over
SalesTransactionStream aggregates units sold per SKU, producing units_per_hour. This is the demand signal that drives
the risk calculation: a spike here is the leading indicator.   Responsibilities:

  • Smooth noisy transaction data into a stable velocity metric
  • Update velocity every window cycle (subsecond)
  • Feed SalesVelocityStream to the correlation CQ

 

5. Supply vs. Demand Correlation

Derived · POS · Inventory · Replenishment
— CQ: StockoutCorrelationCQ

A single CQ joins the velocity window, the inventory window, and the replenishment EventTable on SKU. It computes
hours_of_supply (units_on_hand ÷ units_per_hour) and compares it against hours_to_next_truck to produce a three-tier
risk level: RED when supply runway is already below truck wait time, AMBER when within 1.5×, GREEN otherwise. This runs
continuously, every window cycle, for every SKU.   Responsibilities:

  • Compute stockout risk score per SKU in real time
  • Emit risk events to StockoutRiskStream
  • Drive the GCP Lakehouse write for BI and ML consumption

 

6. Risk Signal Persistence

GCP · GCP Lakehouse
— GCP Lakehouse Writer → Apache Iceberg

All three live streams — sales velocity, inventory positions, and the stockout risk scores — are written to
Apache Iceberg tables on GCP Lakehouse. Iceberg gives downstream BI queries (Looker Studio) and ML workloads a
consistent, time-travel-capable view of supply chain state. The Looker Studio dashboard queries retail.stockout_risk on
a ~15-second refresh cycle.   Responsibilities:

  • Write all streams to Iceberg with ACID guarantees
  • Power the Looker Studio at-risk SKU dashboard
  • Enable time-travel queries for post-incident analysis

 

End-to-End Pipeline Flowchart

The seven components chain together into a single continuous pipeline. Data flows top to bottom; the correlation CQ is
the convergence point where three independent streams meet and produce the risk signal.


Two CDC source branches (Inventory · POS) plus a live Replenishment EventTable converge at StockoutCorrelationCQ. Side
targets persist each stream independently to Iceberg.

The Correlation Query: Exact TQL

Components 4 and 5 are expressed as TQL. Here is the complete statement that drives the risk computation, along with the
EventTable and window setup it depends on.

Component 3: MySQL CDC → EventTable

CREATE OR REPLACE TYPE ReplenishmentType (
  sku                 java.lang.String,
  store_id            java.lang.String,
  hours_to_next_truck java.lang.Double
);

— CDC source: captures ETAs as dispatchers update them
CREATE OR REPLACE SOURCE ReplenishmentSource USING Global.MysqlReader (
  ConnectionURL: ‘jdbc:mysql://localhost:3306/retail’,
  Tables:        ‘retail.REPLENISHMENT_SCHEDULE’,
  Username:      ‘root’
)
OUTPUT TO ReplenishmentStream;

— Parse WAEvent into typed ReplenishmentType events
CREATE OR REPLACE CQ ParseReplenishment
INSERT INTO ReplenishmentLiveStream
SELECT TO_STRING(r.data[0]) AS sku,
      TO_STRING(r.data[1]) AS store_id,
      TO_DOUBLE(r.data[2]) AS hours_to_next_truck
FROM ReplenishmentStream r;

— Live-updatable EventTable keyed on SKU, updated by every CDC change
CREATE EVENTTABLE ReplenishmentCache
USING STREAM (NAME: ‘Retail.ReplenishmentLiveStream’)
QUERY (keytomap: ‘sku’)
OF ReplenishmentType;

Components 4 + 5: Velocity Windows and Correlation CQ


— Component 4: rolling demand velocity per SKU (30-min window)
CREATE OR REPLACE WINDOW SalesWindow OVER SalesTransactionStream
  KEEP WITHIN 30 MINUTE PARTITION BY sku, store_id;

CREATE OR REPLACE WINDOW InventoryWindow OVER InventoryLiveStream
  KEEP 1 ROWS PARTITION BY sku, store_id;

CREATE OR REPLACE CQ SalesVelocityCQ
INSERT INTO SalesVelocityStream
SELECT s.sku,
      s.store_id,
      TO_DOUBLE(SUM(s.quantity_sold)) / 0.5 AS units_per_hour
FROM SalesWindow s
GROUP BY s.sku, s.store_id;

— Component 5: three-way join — velocity × inventory × replenishment schedule
CREATE OR REPLACE CQ StockoutCorrelationCQ
INSERT INTO StockoutRiskStream
SELECT
  v.sku,
  v.store_id,
  i.units_on_hand                                                          AS qty_on_hand,
  v.units_per_hour,
  TO_DOUBLE(CASE WHEN v.units_per_hour > 0
                THEN i.units_on_hand / v.units_per_hour
                ELSE 9999.0 END)                                          AS hours_of_supply,
  r.hours_to_next_truck,
  CASE WHEN v.units_per_hour > 0
        AND (i.units_on_hand / v.units_per_hour) < r.hours_to_next_truck
      THEN true ELSE false END                                            AS stockout_risk,
  CASE WHEN v.units_per_hour > 0
        AND (i.units_on_hand / v.units_per_hour) < r.hours_to_next_truck       THEN ‘RED’
      WHEN v.units_per_hour > 0
        AND (i.units_on_hand / v.units_per_hour) < r.hours_to_next_truck * 1.5 THEN ‘AMBER’
      ELSE ‘GREEN’ END                                                    AS risk_level
FROM VelocityWindow v,
    InventoryWindow i,
    ReplenishmentCache r
WHERE v.sku = i.sku AND v.sku = r.sku;

Two-step fallback. If the three-way join proves unstable, split it: first join the two live windows into a SupplyDemandStream (velocity × inventory → hours_of_supply ), then join that result against the cache. Two simple two-source joins produce the same output as one three-source join — with lower risk in production.

Production consideration: correlation requires data in all three windows, and that isn’t guaranteed. InventoryWindow is populated only when Oracle pushes a CDC event for that SKU + store. ReplenishmentCache is populated only when MySQL has a row for that SKU + store and it has been inserted or updated since the pipeline started. If a SKU has never had an inventory adjustment recorded, or a store’s replenishment schedule has no entry for a particular product, the corresponding window will hold no row. When StockoutCorrelationCQ runs, the three-way join finds no match — and no risk score is produced, even if POS sales for that SKU are spiking. Silent gaps in the source tables become silent gaps in your risk output.

An External Cache as fallback. Striim’s External Cache reads the full source table via a direct database connection at
startup and holds the snapshot in memory. The correlation CQ can then use a two-source lookup pattern: check the CDC
window first; if no row matches the SKU + store, fall back to the External Cache. This guarantees a risk score on
every sale event, even for SKUs and stores with no recent CDC activity.

Here’s How to Get Started

The pipeline uses three Striim CDC readers, the GCP Lakehouse Writer, and the streaming cache pattern backed by a live
CDC source. Documentation for each component is linked below.

Area Component Docs
PostgreSQL PostgreSQL Reader CDC docs
Oracle Oracle CDC Reader CDC docs
MySQL MySQL CDC Reader CDC docs
GCP GCP Lakehouse Writer Writer docs
TQL Continuous Queries CQ reference
Pattern CDC-backed Cache Cache pattern

Spot Stockouts Before Your Customers Do

Your POS, inventory, and logistics systems already hold the signal. Striim correlates them the moment each one changes,
so your team can act hours before the shelf empties, not the morning after. Talk to a Striim engineer about running this
pipeline on your own sources, or start a free trial and build it yourself.

Talk to a Striim Engineer →
Try Striim for Free →

More Resources