KatInterview

Threshold-Crossing Price Notifications at Scale

System DesignModel answer
MediumModel answerSystem Designsystem-designevent-drivennotifications

Last updated

Design a service where users set price-level triggers on securities and get notified quickly, exactly once, through push, email or SMS, even during market-open bursts.

Price Trigger Notification Service

You are asked to design a backend that lets investors register price triggers on securities and be told when the market price passes a level they chose.

For example, a user might ask to be notified when a given stock rises above 150 or falls below 90.

What to cover

Walk through your design and discuss:

  • Functional requirements: what users can create, change and see, and whether triggers fire once or repeatedly.
  • APIs: the main endpoints and the validation you would apply.
  • Data model: what is stored, where, and how it is partitioned.
  • Architecture: how market data and trigger definitions come together.
  • Evaluation strategy: how you decide efficiently, and correctly, that a price has crossed a level.
  • Scalability and latency: how the design copes with a large number of triggers and with sudden bursts.
  • Reliability and deduplication: how you avoid both missed and duplicate notifications.
  • Delivery: push, email and SMS, including user preferences and retries.

Assumptions you may use or adjust

  • Tens of millions of users and a couple hundred million active triggers, heavily skewed toward popular tickers.
  • Around 10,000 symbols.
  • Peak market data of several hundred thousand quote updates per second at the open.
  • A market-wide move can fire millions of triggers within minutes.

Hints

Hint 1

Scanning every trigger for a symbol on every price update does not scale. Think about how to organise thresholds so that one update only touches the triggers it actually passes.

Hint 2

Define 'crossing' using the interval between the previous price and the new price, not just the new price. This matters when updates are conflated or the price gaps.

Hint 3

Duplicates can appear at several layers (replays, queue redelivery, delivery retries). Plan an idempotency mechanism for each layer, such as a conditional state transition and a unique key per trigger event.

Hint 4

Keep the notification pipeline decoupled from evaluation through a queue, so a burst of triggers cannot slow down price processing.