Detailed Component Design
Database Design
- nature of data
- comment is only text data, however, its size is not limited
- there is parent-child relationship between comments
- Choices
- SQL database (e.g. postgres, mySQL)
- Comment Table Schema
- comment_id: id: primary key
- s3_url: str: content's object storage url
- parent_id: id: id of its parent comment if parent_id == -1 then it is root comment
- noSQL database (e.g. neo4j, neptune)
- we can use graph database to maintain parent-child relationship between each comment by
- node as a comment
- edge as a relation
- source is parent
- destination is child
- Decision
- in our case, the design would benefit more from choosing graph database over traditional sql database as graph database is more suitable for representing relationship
- neo4j also support replication using onlinebackup
- raft algorithm for selecting leader-follower
- neo4j also support sharding
- hence we would want to pick neo4j as our database of choice
Cache
- cache is implemented to reduce overall load on database, by storing, comments of the more popular thread
- cache invalidation strategy
- in this case, we may use purge cache invalidation.
- every time we write data on the database we delete in on cache ensuring it will fetch it from the database for the next time
Nested Structure Algorithm
- In this case, we can use bfs algorithm for rendering the comment. When we fetch the thread we can fetch the 25 most popular root comment and cache their children. After that, if the user tap show replies for a specific comment we render its children and cache its grand children. Thus, the nested structure is established.