Skip to main content

Price Sync Flow

Orchestration pipeline for global market synchronization, alert evaluation, and in-app notification delivery.

Sequence (current architecture)​


Alert Trigger Conditions​

ConditionEvaluation Logic
PriceAbovequote.CurrentPrice > rule.TargetValue
PriceBelowquote.CurrentPrice < rule.TargetValue
PriceTargetReached`
PercentDropFromCost(costBasis - currentPrice) / costBasis * 100 >= rule.TargetValue
LowHoldingsCountSUM(BuyQty) - SUM(SellQty) < rule.TargetValue

Logic Highlights​

FeatureDetail
Parallel I/OSyncPricesJob uses Parallel.ForEachAsync to fetch quotes, significantly reducing latency.
Bulk PersistenceUses AddRangeAsync for PriceHistories and Notifications to minimize EF Core overhead.
N+1 AvoidanceFetches all relevant AlertRules in a single query using GetBySymbolsAsync.
Evaluator + CooldownIAlertRuleEvaluator applies rule logic and enforces a Redis cooldown key to prevent alert storms.
In-App NotificationAlert breaches write to the Notification table, then are pushed via SignalR (IAlertNotifier).
Single TransactionAll state changes (history, notifications, rule updates) are saved in one unit of work.
TriggerOnceIf rule.TriggerOnce = true, rule is disabled automatically after first breach.
User IsolationLowHoldingsCount and PercentDropFromCost always filter by (UserId, TickerSymbol).

Relationship to SQS (integration events)​

SQS is used for event-driven evaluation paths that are separate from the scheduled SyncPricesJob:

  • The API can publish an EventEnvelope to SQS (see POST /api/v1/events).
  • The Worker polls SQS continuously (ProcessQueueJob) and routes known event types:
    • inventoryalert.pricing.price-drop.v1 → MarketPriceAlertHandler
    • inventoryalert.inventory.stock-low.v1 → LowHoldingsHandler
    • inventoryalert.news.sync-requested.v1 → enqueue NewsSyncJob