slug | id | title | date | comments | tags | slides | |
---|---|---|---|---|---|---|---|
162-designing-smart-notification-of-stock-price-changes |
162-designing-smart-notification-of-stock-price-changes |
Designing Smart Notification of Stock Price Changes |
2019-08-13 12:21 |
true |
|
false |
- 3 million users
- 5000 stocks + 250 global stocks
- a user gets notified about the price change when
- subscribing the stock
- the stock has 5% or 10% changes
- since a) the last week or b) the last day
- extensibility. may support other kinds of notifications like breaking news, earnings call, etc.
Contexts:
- What is clearing? Clearing is the procedure by which financial trades settle – that is, the correct and timely transfer of funds to the seller and securities to the buyer. Often with clearing, a specialized organization acts as an intermediary known as a clearinghouse.
- What is a stock exchange? A facility where stock brokers and traders can buy and sell securities.
<svg xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink" version="1.1" width="100%" height="100%" viewBox="-0.5 -0.5 749 424" content='7Vxdc9o4FP01zOw+JGNLtoFHSEjabtPSpttunzrCCKPGWIwsB+ivX8nIgC2VmIKxmUkegn0t2+Kee+6XlLTgzWx5z9B8+kDHOGwBa7xswdsWALbd8cSHlKzWEs9TgoCRsRq0FTySX1gJLSVNyBjHuYGc0pCTeV7o0yjCPs/JEGN0kR82oWH+rXMUYE3w6KNQl34jYz5dSzuutZW/wSSYZm+2LXVlhrLBShBP0ZgudkRw0II3jFK+Ppotb3AolZfpZX3f3W+ubibGcMTL3BD/mHx9XgT/vPvgryadz2+f46fZFXDU5Pgq+8Z4LBSgTinjUxrQCIWDrbTPaBKNsXysJc62Y95TOhdCWwh/Ys5XCk2UcCpEUz4L1VW8JPy/nePv8lHXrjq7Xaonpyer7CTibLW5SZ7s3CVPt7elZ7n7hpiRGeaYKaGuO6XOmCbMx3sUltkgYgHme8YpK5fK3HmBQuYeUzEbthIDGA4RJ895a0PKaIPNuC2u4kBBewDM6rnPKEzUm3rzucASWMMknoqPD5STCfHFVGgk1YDZMxF6AF4ovmR/xMRRII/+6g0/xH9rNpO3iMWUcPw4R6kiF8Iv5NH/rfKfMeN4uVdd6qqX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cOqbXEKoLcSHrgrqFNmjXyT9inX2ou7bg9RiTRfhmmAq8pd/jeoWtpYXxdnfveHGwnsFJI5ljiGTCAVMmSZjqGo0vNinJmHN8UmJdg24b5uDJ9jMca4150DcdluqTGHh5u5bPV190Szqt0y+vms0EOnk78WCnaCnruR7ttopvctrOXrelzQyAM7itjNmXunRU3sC6lRjYwcGsXQhOcH8wA1133/hqrCJT6stl2UIW3Q2oywBoXF0Ga2HSZbSdQNmVJdiwrXF62+nfWJq/9ShQIVFQ/94Ew+KSW3tXHerZsaaoZncaYKeoVtc2uRjX5GLcqtSqtxrOqVZGOVI7GK66J+ocOFYnr2VjR8ek5U5lxqsvpBX+QO1TgpMyLecL7ebotu+5pftslbVzoJ6k8KkwSR6mDtlHIjG5MCcDvGI7E5TLYapyME6tW8GbncM4oGQOYzcrh3HqaVc0GJ+TV4bH4QM0v+YzGv2kIw238+97LezXaJcLzdA7WFfidPvPCNZ17fZfOsDB/w==' style={{ backgroundColor: "rgb(255, 255, 255)" }}
(APNs)
(FCM)
AWS SES /sendgrid/etc
Market Prices
ticker
influx or prometheus
watcher
- Price ticker
- data fetching policies
- option 1 preliminary: fetches data every 5 mins and flush into the time-series database in batches.
- option 2 advanced: nowadays external systems usually push data directly so that we do not have to pull all the time.
- ~6000 points per request or per price change.
- data retention of 1 week, because this is just the speeding layer of the lambda architecture.
- data fetching policies
- Price watcher
- read the data ranging from last week or last 24 hours for each stock.
- calculate if the fluctuation exceeds 5% or 10% in those two time spans. we get tuples like (stock, up 5%, 1 week).
- corner case: should we normalize the price data? for example, some abnormal price like someone sold UBER mistakenly for $1 USD.
- ratelimit (because 5% or 10% delta may occur many times within one day), and then emit an event
PRICE_CHANGE(STOCK_CODE, timeSpan, percentage)
to the notification queue.
- Periodical triggers are cron jobs, e.g. Airflow, Cadence.
- notification queue
- may not necessarily be introduced in the first place when users and stocks are small.
- may accept generic messaging event, like
PRICE_CHANGE
,EARNINGS_CALL
,BREAKING_NEWS
, etc.
- Notifier
- subscribe the notification queue to get the event
- and then fetch who to notify from the user settings service
- finally based on user settings, send out messages through APNs, FCM or AWS SES.