create_comment(thread_id: str, comment: str, parent_id: str | None):
REST API: POST
create comment in specific thread if parent_id is not None the comment is reply
get_comments(thread_id: str, parent_id: str | None, limit: int = 25):
REST API: GET
get {limit} comments with {parent_id} from thread {thread_id} if parent_id is None return only main comment
Database
Database choice: relational database like MySQL
Data schema:
Comment Table:
comment_id: primary key
thread_id: foreign key
comment: context of the comment
parent_id: parent comment's comment_id
Comment Rendering Algorithm
Pre-order depth first search:
To render, nested comments we need to render the parent comment first then we will render child comment sorted by created datetime.