We are building the comment model for Reddit's new backend that supports their app. We have come up with the following Comment structure. The numbers on the right side are the Like counts for each comment.
- Comment uuid 1: (Root level comment) 89
|-- Reply uuid 2 (First level reply comment). 150
|-- Reply uuid 7 (Second level reply comment) 92
|-- Reply uuid 8 (Third level reply comment) 40
|-- Reply uuid 3 (First reply comment) 112
|-- Reply uuid 4 (First reply comment). 1
|-- Reply uuid 9 (Second level reply comment). 0
|-- Reply uuid 10 (Third level reply comment). 3
|-- Reply uuid 5 (First reply comment) 5
|-- Reply uuid 6 (First reply comment) 10
|-- Reply uuid 11 (Second level reply comment). 78
|-- Reply uuid 12 (Third level reply comment) 200
Goal: Write an API to fetch the top 5 comments ordered by Like count for a given Root Level Comment. If the comment is a Second or Third Level Reply Comment, fetch the entire thread. The API should not return more than 5 comments at a time.
Eg.: 1st call by API -> returns comments 2, 3, 6, 11 & 12. 2nd call of API -> returns comments 7,8 & 5.
- How do you store the data in SQL? Assume a Comment has an ID, Comment Message, Like Count, Timestamp and Parent Comment ID.
- What does the API look like? Should there be one massive SQL query?
from Design Reddit Comment API using SQL
No comments:
Post a Comment