User able to load and read discussion comments
User able to post top-level comment
User able to reply to comment
Low latency
Highly available
Eventually consistent okay (user A doesnt have to see user B's comment immediately after it's submitted, some delay is okay)
1 million comments per day
100:1 read write ratio
100 million comment reads per day
10 comments per second
1000 comments read per second
500 MB per day
200 GB per year
20 comments in a discussion
5 million discussion reads a day
50 discussions read per second
.5KB per comment
GET read (user_info, discussion, comment?)
If comment included in request only retrieve comments under tree of specified comment
POST comment (discussion, text, user_info, comment?)
If comment included in request overwrite old comment
Use distributed tree database like Neo4J to store comments. Comments are vertices and replies to comments are stored as bi-directional edges in the graph. Vertices store user and time of comment.
Store discussion id on vertices. Store an index on discussion id and on user id so easy to retrieve all comments in a discussion and all comments for a user. Discussions are isolated to a single node. With current data growth/number of comments a day dont have to worry about archiving discussions.
Replicate database to safeguard data from crashes.
Neo4J to hold tree of discussions. Each discussion is its own tree.
Distributed LRU cache to hold most recently viewed threads for fast read retrieval.
Load Balancer to balance requests across servers.
Read request:
Load balancer checks if client rate limited. If not, route request to an application server. Application server checks Redis LRU cache for discussion. If discussion in cache, return to user. If not, load from Neo4J database and add to cache.
Write request:
Load balancer checks if client rate limited. If not, route request to an application server. App server loads discussion into cache if not already there. Then application server adds
For large discussions, can have lazy loading system from client where more comments are only loaded when user scrolls to bottom of page. Can also have a default depth loaded on initial load of a comment
Neo4J graph DB over relational db as more suited to threaded model
Try to discuss as many failure scenarios/bottlenecks as possible.
Can implement say voting and different commenting sorting based on votes like Reddit. Votes would be eventually consistent, can use say Apache Kafka to process comment votes async