Skip to content

Latest commit

 

History

History
56 lines (32 loc) · 2.1 KB

README.md

File metadata and controls

56 lines (32 loc) · 2.1 KB

LikeBatchUpdater Service

The main function of the LikeBatchUpdater service is to consume LikeToggledEvent and update RTLikeCountCollection in batches.


Database (like)

Although noSQL database is used but a proper Schema is maintained.


RTLikeCountColletion

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)

DailyLikeCountCollection

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)

EventHandlers

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.


Architecture

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.


Architecture Diagram

likeBatchUpdater