Market Data Throttle Control Approach
- Define a sliding window duration, which is the time interval within which MarketData for a symbol must be processed.
- Create a HashMap to keep track of the number of calls per second for each symbol.
- Check if the MarketData already been processed within the sliding window period.
- If the number of calls for the symbol is less than the maximum allowed calls per second, increment the count for the symbol and continue.
- If the number of calls for the symbol is greater than 100, ignore the data.
- If the MarketData for the symbol is latest, update latest MarketData and publish the aggregated MarketData
Test Cases
- To test, I have created sample 1000 message, out of 1000, around 50 messages will be called per second to process.
- To test maximum count 100, need to reduce the SLEEP_DURATION = 5 or less or just comment the Thread sleep line. Then per second more than 100 messages will be called and onMessage won't process.