The main function of the LikeBatchUpdater service is to consume LikeToggledEvent and update RTLikeCountCollection in batches.
Although noSQL database is used but a proper Schema is maintained.
Attribute | Type | Description |
---|---|---|
_id |
ObjectId |
id of an item (a post or comment) (Primary Key) |
count |
Int32 |
no. of likes on the item (a post or comment) |
Attribute | Type | Description |
---|---|---|
_id |
ObjectId |
id of an item (a post or comment) (Primary Key) |
count |
Int32 |
no. of likes on the item (a post or comment) |
Handlers consumes events from NATS stream and processes them.
It captures the LikeToggledEvent and processes it and updates theRTLikeCountCollection in batches (update per 5min.) to update the likeCount of items.
RTLikeCountCollection does not store accurate likeCount
Since NATS does not guarantee exactly once messaging, so some events may be consumed more than once, so RTLikeCount won't always have a precise like count.
DailyLikeCountCollection to store accurate likeCount
A daily cron job will update the DailyLikeCountCollection from ItemLikeCollection and clear the user's RTLikeCount in a single transaction.
Then the total likes on an item can be more accurately calculated by summing the values of RTLikeCount and DailyLikeCount.