-Post a comment on post/video/image
-Reply to the comment and create a hierarchy.
-Display comment with pagination - sort by time
Calculations:
100 DAU
20 % comments at least once
2 avg comments
40 mil comments per day
Peak is 10 times higher
Storage capacity req:
We can revisit this but right now considering 50-100 TB per year
Traffic :
We can revisit the numbers
~ 500 wps
r: w ratio 100 :1
Strong consistency within single post
Eventual consistency across broader system
Choose Nosql over postgres here to complex avoid joins and complicated fetches over multiple tables - based on time, based on which user comment on what would need joins between user table comments table etc and we would need good sharding to scale.
Entities:
comments: id/uuid, post_id, parent_id, depth as int, author_id, text, user_id
post_comment_aggregates: post_id, total_counts, last_comment_at, votes_count
POST /comments
{post_id, parent_id, body}
response : {id, depth:}
GET /comments/{id}
response { body}
DELETE /comments/{id}
We can get votes and ratings
Main components:
UI client to post comments
CDN - to serve, image, video you are commenting on , caches to HTML, css
API gateway: Auth, rate limiting , routing
Load Balancer: route to concurrently running commenting services ( scaled horizontally )
Services:
Auth service
Comment Service
Aggregation service
Redis between Nosql and services, read replicas to scale reads and fault tolerance.
Kafka for real time comment aggregation feed aggregation services