Design Price Alert System (Stock / Amazon) - System Design
“Notify me when AAPL hits $250” or “tell me when this Amazon item drops below Rs 1,999” sounds like a WHERE price >= target query. Then you look at the numbers. There are 100M active alerts. Stock prices update millions of times a second across tens of thousands of instruments. If you run that WHERE on every price tick you are doing millions of full scans per second over a hundred million rows, and you melt. The whole problem is the inversion: it is not “given a price, which alerts match” as a database scan, it is “given a firehose of price changes, fire exactly the alerts that just got crossed, once, within a second, without scanning anything you do not have to.” ...