Functional Requirements:
Non-Functional Requirements:
To ensure the APIs are RESTful, we separate the actions of fetching top-level comments from fetching replies. We also utilize your cursor-based pagination strategy using the TimeUUID.
1. Create a Top-Level Comment POST /v1/videos/{video_id}/comments
JSON
{
"content": "This is a great explanation!"
}
2. Reply to a Comment POST /v1/comments/{parent_id}/replies
JSON
{
"content": "I completely agree with this."
}
3. Fetch Top-Level Comments (Cursor Paginated) GET /v1/videos/{video_id}/comments?limit=20&cursor={time_uuid} Returns a list of comments. The client uses the commentId of the last item as the cursor for the next request.
4. Fetch Replies for a Comment (Lazy Loading) GET /v1/comments/{parent_id}/replies?limit=10&cursor={time_uuid}
Let's dig into the core mechanics that make your proposed solution scale.
1. TimeUUID & Cursor-Based Pagination Your choice of TimeUUID (UUIDv1 or UUIDv7) as the primary key is the linchpin of this design. Because the timestamp is embedded within the ID, the database inherently stores the comments in chronological order. When a user clicks "Load More", the SQL query simply becomes: SELECT * FROM comments WHERE parentId = X AND commentId < {cursor} ORDER BY commentId DESC LIMIT 10; This avoids the massive performance hits of OFFSET pagination on large tables.
2. Real-Time Updates (Pub/Sub & WebSockets) To satisfy the real-time requirement without the client spamming the server with pull requests, we use a push model.
video_{video_id}.