Text: the users can comment a text of 500 words.
Answers: The user can reply to a comment another user left there.
Comments: The comments come before the first comment.
Edits: the user can edit or delete the comments
real-time notifications: the user must see the real time notifcations
Estimate the scale of the system. Consider daily active users, read/write ratio, storage requirements, bandwidth, and any relevant QPS calculations...
API Design
Write API — REST
POST /v1/posts/{postId}/comments
Create a new root comment.
POST /v1/comments/{commentId}/replies
Create a reply to an existing comment.
PATCH /v1/comments/{commentId}
Update an existing comment.
DELETE /v1/comments/{commentId}
Delete an existing comment.
Read API — GraphQL
Query:
post(id: ID!) {
comments(first: Int, after: String) {
id
text
createdAt
author {
id
name
}
replies(first: Int, after: String) {
id
text
createdAt
author {
id
name
}
}
}
}
| ServiceResponsibility | |
| API Gateway | Provides the public API entry point and routes read and write requests to the appropriate backend service. |
| Read Service | Handles GraphQL queries and retrieves comment data from the cache, falling back to the database when necessary. |
| Write Service | Handles REST commands such as creating, updating, and deleting comments and persists changes to the database. |
| Cache Layer | Stores frequently requested comment data to reduce database reads and improve response latency. |
| NoSQL Database | Acts as the source of truth for comments, replies, relationships, and persistent comment state. |
| Event Bus | Publishes comment-domain events such as CommentCreated or ReplyCreated to independent asynchronous consumers. |
| Cache Queue | Buffers cache-update events so temporary processing spikes do not overload the cache worker. |
| Cache Worker | Consumes cache events and invalidates or refreshes stale cached comment data. |
| Notification Queue | Buffers notification events independently so slow notification processing does not affect cache synchronization. |
| Notification Worker | Consumes comment/reply events and determines which notification operations must be executed. |
| Notification Service | Delivers notifications to affected users through the configured notification channels. |
| Dead Letter Queue | Stores messages that repeatedly fail processing so they do not block normal queue consumption. |
Define the data model. Identify the main entities, their attributes, and relationships. Consider the choice of database type (SQL vs NoSQL) and justify your decision based on access patterns...
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.