Rolling Stock Price Alert System
Design one-shot percentage-jump alerts over per-second market data and rolling minute-to-year windows.
Problem statement
For this exercise, assume an exchange sends stock-price updates every second and users create one-shot alerts for a symbol, a positive percentage threshold, and exactly one rolling comparison unit: minute, hour, day, week, month, or year.
The system compares the latest accepted price with the latest accepted price at or before the exact rolling-window boundary. An increase at or above the threshold triggers one generic notification, after which the subscription is removed; an untriggered subscription expires after one month.
Duplicate and out-of-order ticks may arrive, notification transport is at least once, and each subscription must be observed as triggered at most once. Assume 10,000 symbols, up to 10,000 accepted updates per second, 10 million active subscriptions, and a five-second p95 alert-decision target.
Design ingestion, rolling-price storage, subscription indexing, evaluation, delivery, expiry, and recovery. Trading, order execution, accounts, and portfolio accounting are outside scope.
What to build
- Create, inspect, and cancel an active one-shot alert for one symbol, positive threshold, and rolling window unit.
- Accept per-second stock updates while detecting duplicates and defining deterministic treatment of out-of-order data.
- Compare the latest accepted price with the price at or before the rolling boundary and identify every active subscription whose positive threshold is met.
- Deliver an idempotently keyed one-shot notification, remove a triggered subscription, and expire untriggered subscriptions after one month.
At scale
- For this exercise, assume 10,000 symbols and up to 10,000 accepted stock-price updates per second across the market feed.
- For this exercise, assume 10 million active subscriptions distributed across symbols, thresholds, and six rolling window units.
- For this exercise, target five seconds p95 from an accepted update to an alert decision under healthy operation.
- For this exercise, retain enough accepted price history to perform exact at-or-before lookups for rolling windows as long as one year, while active subscriptions expire after one month.