advancedTop 15 Database Design Questions
Design a social media platform database: users, posts, follows, likes, comments.
users(id BIGSERIAL PK, username UNIQUE, email UNIQUE, created_at) posts(id BIGSERIAL, user_id FK, content TEXT, media_urls JSONB, created_at) — partition by month follows(follower_id FK, following_id FK, created_at, PRIMARY KEY(follower_id, following_id)) likes(user_id FK, post_id FK, created_at, PRIMARY KEY(user_id, post_id)) — no duplicates comments(id, post_id FK, user_id FK, content, parent_id
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response