I'm using Apache Flink in a stock market project to calculate the current price change. The formula is
price_change = (current_price - previous_close_price) / previous_close_price
previous_close_price is a security's closing price on the preceding day of trading. Everyday before the market opens, I need to update previous_close_price.
Now I've come up with several solutions but I don't know which one is the best.
Store
previous_close_pricein redis and fetch the price in every calculation. It's easy and flexible to update the price but this solution could kill the performance.Set the TTL of state to 1 day. Get the new state when the old state is expired. But it's not flexible as the TTL is hardcoded.
Broadcast State Pattern. I'm not sure if this solution works.
Send a special message to flink. When flink receives the message, it updates the
previous_close_price.
Any suggestions are appreicated.