Design Reddit: Schema, Partitioning and Scaling for Posts, Comments and Votes

Quick Overview

A system design question asking how to build Reddit, with communities, posts, nested comments, voting and ranked feeds. The discussion centers on the database schema, the partition key for each table, and how to scale home feeds, vote counting and hot threads.

Design Reddit: Schema, Partitioning and Scaling for Posts, Comments and Votes

Company: StackAdapt

Role: Software Engineer

Category: System Design

Difficulty: medium

Interview Round: Onsite

Design Reddit. Users join communities (subreddits), publish text or link posts in them, discuss each post in nested comment threads, and upvote or downvote posts and comments. A community page lists its posts by hot, new or top, and each user has a home feed built from the communities they subscribe to. The interviewer concentrated on three areas and kept asking follow-up questions in each: the schema, how to partition the data, and how to scale the system. ### Clarifying Questions - Which features are in scope: posting, nested comments, voting, community listings, the home feed, search, moderation, notifications? - What scale should the design target: daily active users, posts, comments and votes per day, and peak traffic on a front-page post? - Must vote counts be exact and visible at once, or may they lag by a few seconds? - Which sort orders are required for posts and for comments? - After a user posts, comments or votes, must they see their own change immediately? ### Part 1: Schema Define the core entities and the schema for users, communities, subscriptions, posts, nested comments and votes. Say which store holds each one and why. ```hint Comments form a tree A thread can be both deep and very wide. Decide how a comment row records its place in the tree and how you would load the first page of a large thread sorted by score. ``` ```hint Votes are the largest table Each user votes at most once per post or comment and can change that vote. Think about what a vote row needs and how a page shows scores without counting rows. ``` #### What This Part Should Cover - Entities, primary keys and relationships, including an id scheme. - How the comment tree is stored and paged. - Vote rows, uniqueness per user and item, and where aggregated scores live. - A storage choice per table, justified by its access pattern and volume. ### Part 2: Partitioning The data no longer fits on one database node. How do you partition posts, comments, votes and subscriptions? Name the partition key for each, and say which queries end up crossing partitions. ```hint Start from the hottest reads List the reads that dominate (a community page, a post with its comments, a home feed, a user's own votes on a page) and check whether each one can be served from a single partition. ``` #### What This Part Should Cover - A partition key per table, tied to the queries it serves. - Hot partitions: a viral post, a huge community, a heavy user. - Queries that cross partitions, and how secondary index tables serve them. - How shards are added or rebalanced later. ### Part 3: Scaling Scale the read and write paths: building home feeds, maintaining hot, new and top listings, absorbing a burst of votes on a front-page post, and caching. ```hint Feeds: compute on write or on read A home feed can be assembled when the user opens it or precomputed when a post is written. Weigh both against the size of the largest communities and how often rankings change. ``` ```hint Votes arrive in bursts A front-page post can receive votes much faster than a single database row can be updated. Decide where its counter lives and how stale the displayed score may be. ``` #### What This Part Should Cover - A home feed strategy and its fan-out cost. - How ranked listings are stored and kept up to date as votes arrive. - The vote write path under a burst, including protection against double counting. - Caching for posts, threads and listings, and what happens when a cache is lost. ### What a Strong Answer Covers - Requirements and rough estimates that drive the storage, partitioning and caching choices. - A schema and partition keys that agree with the main access paths. - Specific handling of each hot spot: viral posts, giant communities and vote bursts. - Consistency choices, failure handling and the metrics that show the system is healthy. ### Follow-up Questions - How do you delete a comment that has replies without breaking the thread? - How would you add a "controversial" sort for comments? - How would you detect and limit vote manipulation by coordinated accounts? - What changes when one community grows from thousands to tens of millions of subscribers?

Overview: A system design question asking how to build Reddit, with communities, posts, nested comments, voting and ranked feeds. The discussion centers on the database schema, the partition key for each table, and how to scale home feeds, vote counting and hot threads.

Read the full StackAdapt Software Engineer interview experience this question came from

StackAdapt logo
StackAdapt
Nov 24, 2026
mediumSoftware EngineerOnsiteSystem Design
0
0

Design Reddit. Users join communities (subreddits), publish text or link posts in them, discuss each post in nested comment threads, and upvote or downvote posts and comments. A community page lists its posts by hot, new or top, and each user has a home feed built from the communities they subscribe to.

The interviewer concentrated on three areas and kept asking follow-up questions in each: the schema, how to partition the data, and how to scale the system.

Clarifying Questions Guidance

  • Which features are in scope: posting, nested comments, voting, community listings, the home feed, search, moderation, notifications?
  • What scale should the design target: daily active users, posts, comments and votes per day, and peak traffic on a front-page post?
  • Must vote counts be exact and visible at once, or may they lag by a few seconds?
  • Which sort orders are required for posts and for comments?
  • After a user posts, comments or votes, must they see their own change immediately?

Part 1: Schema

Define the core entities and the schema for users, communities, subscriptions, posts, nested comments and votes. Say which store holds each one and why.

What This Part Should Cover Guidance

  • Entities, primary keys and relationships, including an id scheme.
  • How the comment tree is stored and paged.
  • Vote rows, uniqueness per user and item, and where aggregated scores live.
  • A storage choice per table, justified by its access pattern and volume.

Part 2: Partitioning

The data no longer fits on one database node. How do you partition posts, comments, votes and subscriptions? Name the partition key for each, and say which queries end up crossing partitions.

What This Part Should Cover Guidance

  • A partition key per table, tied to the queries it serves.
  • Hot partitions: a viral post, a huge community, a heavy user.
  • Queries that cross partitions, and how secondary index tables serve them.
  • How shards are added or rebalanced later.

Part 3: Scaling

Scale the read and write paths: building home feeds, maintaining hot, new and top listings, absorbing a burst of votes on a front-page post, and caching.

What This Part Should Cover Guidance

  • A home feed strategy and its fan-out cost.
  • How ranked listings are stored and kept up to date as votes arrive.
  • The vote write path under a burst, including protection against double counting.
  • Caching for posts, threads and listings, and what happens when a cache is lost.

What a Strong Answer Covers Guidance

  • Requirements and rough estimates that drive the storage, partitioning and caching choices.
  • A schema and partition keys that agree with the main access paths.
  • Specific handling of each hot spot: viral posts, giant communities and vote bursts.
  • Consistency choices, failure handling and the metrics that show the system is healthy.

Follow-up Questions Guidance

  • How do you delete a comment that has replies without breaking the thread?
  • How would you add a "controversial" sort for comments?
  • How would you detect and limit vote manipulation by coordinated accounts?
  • What changes when one community grows from thousands to tens of millions of subscribers?