MentorNode
Start free
Social, Feed & EngagementMediumdesign-comment-system

Design a Nested Comment & Voting System (Reddit)

Design threaded discussion: deeply nested replies, live vote counts, multiple sort orders, and a hot thread where ten thousand people comment in the same minute.

Materialized PathHot RankingSharded CountersWrite Contention
Traffic & Capacity Estimates:

50M comments/day · 500M votes/day · threads up to 50k comments · 10-level nesting

Functional Requirements

  • •Store arbitrarily nested comments and return a thread subtree efficiently.
  • •Support multiple sort orders (best, top, new, controversial) over the same thread.
  • •Apply upvotes and downvotes with live-updating scores and a per-user vote record.
  • •Collapse, paginate, and lazily load deep or low-scoring branches.

Non-Functional Requirements

  • •Loading the top 200 comments of a hot thread must stay under 300ms.
  • •Vote writes must not contend on a single row for a viral comment.
  • •Counts may be approximate for a few seconds; a user's own vote must appear instantly.

Back-of-the-Envelope Math

  • 500M votes/day = ~6k votes/second average, with a hot post absorbing 5k votes/second on its own.
  • A 50k-comment thread at 500 bytes each is 25 MB — far too much to send in one response, so subtree pagination is mandatory.

Key Architectural Trade-offs

  • Materialized path or nested-set storage makes subtree reads one range scan and makes moves expensive; a plain parent_id needs recursive queries.
  • Precomputing each sort order per thread is fast to read and multiplies write work; sorting at read time is flexible and hurts on the biggest threads.
  • Sharded counters plus periodic rollup remove vote hotspots and make the displayed score briefly wrong — which is nearly always the right call.

Click or drag a component onto the canvas, then connect the handles to draw the data flow.

3 nodes · 2 edges

Components · 35

Client & Edge4
Compute & Gateway7
Storage & Caching11
Messaging & Streaming6
Coordination & Ops5
Intelligence2
Canvas overview