How would you approach designing a database for a large-scale social media application?

Instruction: Outline key considerations and a high-level design strategy for a social media application's database.

Context: This question challenges the candidate to apply their database design skills to a complex, real-world problem, taking into account scalability, performance, and data consistency.

Updated

Official answer

Define the first features: posting, following, reactions, visibility and feeds. A relational starting model could use:

  • users(user_id, handle), with a unique normalized handle under a stated policy.
  • posts(post_id, author_id, created_at, body, visibility), with author_id referencing users.
  • follows(follower_id, followed_id, created_at), two user references and a unique pair; reject self-follow if required.
  • reactions(user_id, post_id, kind), with the uniqueness rule matching whether one or several reaction types are allowed.
  • media(media_id, post_id, object_key, state), storing controlled object references rather than unrestricted public URLs.

Model blocks and group membership explicitly. A feed cache is derived data, not an authorization decision: check current visibility and blocking rules when serving content, and define how deletions and permission changes invalidate derived copies.

Index measured access paths such as an author's posts ordered by creation time plus a unique tie-breaker. Specify pagination behavior under new inserts. Feed fan-out, search and analytics may need separate derived stores as scale demands, but SQL versus NoSQL does not decide scalability alone. Preserve stable IDs and replayable events; test duplicate follows, missing authors, restricted posts, deletion propagation and a very popular account before adding distribution.

Related Questions