Problem
Design the frontend of a nested comment system, like the comments under a Reddit post or a Disqus thread on a news article: people reply to the post and to each other, threads go many levels deep, the best replies get voted up, and new replies keep arriving while people read.
Interviewers use it to test how you model and load a deep tree, how you page and sort it while votes keep changing, how you make replies, edits and votes feel instant without ever losing someone's text, and how you keep very long threads fast, safe and accessible.
Functional requirements
- Read a thread: replies nested under the comments they answer, sorted by Top, New or Controversial, with more replies loaded on demand.
- Reply at any level, edit and delete your own comments, and vote up or down.
- See other people's new replies, edits and deletions without refreshing.
- Format comments with a small Markdown subset and @mentions.
Constraints
- Most posts have under 100 comments, but a hot post can reach 20,000, with 5,000 people reading at once and bursts of 10 new comments per second.
- Posts are public, and about 90% of readers are logged out and arrive from search: the first comments must be readable within 2.5 seconds on a mid-range phone on 4G.
- Votes and replies show on screen in under 100 ms, and other readers see new comments within 2–5 seconds.
- Typed text is never lost: not on a refresh, a failed post, a rate limit or a flaky connection.
- More than half of readers are on phones (screens down to 320 px wide), and it must be accessible to WCAG 2.2 AA: keyboard, screen reader and touch.
Discussion areas
- Core entities and key actions: what a post, a comment, a page of replies and the reader's own state are, and which user actions shape the design.
- Architecture and rendering: how to render comments that must be indexed by search engines and readable fast, the layers between components and the server, and the component tree for a recursive thread.
- Data model: how a deep, partly loaded tree lives in the client store, and how "12 more replies" and "Continue this thread" are represented.
- Pagination and sorting: paging through Top, New and Controversial while scores keep changing, without skipping or repeating comments.
- API and live updates: endpoints for loading and writes, how other readers' new comments reach the browser, and when they should appear on screen.
- Writes and consistency: making replies, edits, deletes and votes feel instant, retries that never post twice, and deleted comments that still have replies.
- Errors, rate limits and offline: which failures to retry and which to give up on, what to do on a 429, and keeping half-written replies safe.
- Content safety: Markdown, mentions, XSS and moderation states.
- Performance: threads with thousands of comments, deep nesting on small screens, and bursts of incoming updates.
- Accessibility: the right semantics for a thread, moving between comments with the keyboard, and where focus goes after posting.
Follow-up questions interviewers ask
- Why SSE and not WebSockets or polling?
- Why not load the whole tree at once?
- Why keep the server's order instead of sorting in the browser?
- What if my own SSE event arrives before the 201?
- Someone deletes a comment while you're replying to it. What happens?
- How do you stop double posting?
- What changes for an embeddable widget like Disqus?
- Why is virtualizing a tree harder than a list?