Detailed Component Design
View Verification Algorithm
- To get rid of the fraud views we can filter them by asking
- Does the view last longer than 1 minute
- Is it a part of spam
- for the first question, we can easily detected it by measuring time for each view.
- for the second question, it may be done through api gateway rate limit functionality
- We can use Captcha periodically to detect bots.
- If there are too many request from the same source ip, we will consider it as fraud view and doesn't count it.
Real Time Update
- Views are aggregrated by kafka architecture.
- Kafka producer will handle the incoming view then send it to kafka topic
- Kafka subscriber will receive the incoming view and aggregate (Count) them and sending the request to api gateway to access view increase service
- After the view increase if the cache hit, cache will launch push notification to update views on web ui (cache miss, database will launch push notification)
- WebUI show real time update using Web Socket
Cache Management
- Cache algorithm
- Cache retain its fast read/write speed by limiting its size
- hence, it needs algorithm to terminate item in case its size is overload
- LRU
- Least Recently Used cache
- This algorithm will prioritize the most recent item
- hence, it will delete item with the oldest latest used timestamp
- LFU
- Least Frequently Used cache
- This algorithm will prioritize the most used item
- hence, it will delete item with the least amount of usage
- in our case, we may use the combination of both cache
- The first layer will be LFU cache and in case there are multiple least frequently used items
- We will use LRU cache