DDSA Solutions
Case Study6 min read·

Design a Q&A Platform (Stack Overflow)

How to design Stack Overflow / Quora for interviews: questions and answers, voting, reputation, full-text search, caching hot posts, and moderation.

A Q&A site looks like a blog until traffic concentrates on a few viral questions. You need durable posts, sorted answers, votes that must not double-count, reputation side effects, and search that actually finds duplicates. It is a read-heavy news feed cousin mixed with a search engine and a careful counter service.

Set scope with the framework: ask/answer/vote/comment/search/tags. Skip ads and Teams billing. Moderation can be rules + queues, not a full Trust & Safety org chart.

Functional requirements

  • Post questions with tags; answer and comment.
  • Upvote/downvote; accept an answer.
  • Reputation derived from votes; basic badges.
  • Search questions by text and tags; related questions.
  • User profiles and activity history.
  • Optional: bounties, real-time notifications on answers.

Non-functional

  • Read-heavy: popular questions cached at the edge/CDN.
  • Vote idempotency per user per post — strong enough to prevent doubles.
  • Search lag of a few seconds OK; vote counts can be slightly eventual on the page.
  • Abuse: rate-limit posting and voting (rate limiter).
  • SEO-friendly public URLs — many visits are anonymous Google traffic.

Hot posts dominate

A tiny fraction of questions get almost all reads. Design for cache hits on the hot set and do not put every page view as a SQL row lock on the question. That single insight separates juniors from mid-levels here.

Capacity sketch

100M page views/day, write rate much smaller — say 50 QPS asks/answers peak, 500 QPS votes. Average question page 50 KB HTML-equivalent API payload. Cache hit ratio on top 1% URLs should be >90%. Reputation updates are fan-out-on-write to a user counters table, async if needed.

High-level architecture

  1. API tier — REST for posts, votes, users (API design).
  2. Post service — questions, answers, comments, accepts.
  3. Vote service — idempotent votes; emits score deltas.
  4. Reputation worker — consumes vote events; updates user reputation.
  5. Search indexer — async to Elasticsearch.
  6. Cache / CDN — anonymous question pages and tag homepages.
  7. Notification — new answer on your question (notifications).
  8. Moderation queue — flags, spam scores, review tools.

Data model

EntityStoreNotes
Question / AnswerSQLBody, author, timestamps, accepted_answer_id
VoteSQL unique(user_id, post_id)Direction +1/−1; source of truth
Tag / TagMapSQLMany-to-many; denormalize counts
User reputationSQLUpdated by workers; cache on profile
Search docElasticsearchTitle, body, tags, score
Timeline / feedsOptional RedisPersonalized home if Quora-like

Pick SQL for posts and votes — relational integrity and unique constraints buy you correctness. Shard by question_id for answers if a single thread becomes huge; most never will.

Voting and reputation

  1. POST /vote with user_id, post_id, direction — upsert on unique key.
  2. Compute delta vs previous vote (none → up is +1; up → down is −2, etc.).
  3. Update denormalized score on post (transaction or ordered event).
  4. Emit event; reputation worker applies rules (answer upvote +10, etc.).
  5. Invalidate cached question page fragment for score.

Do not increment score without the votes table — audits and undos become impossible. Eventual reputation is fine; show “score updating…” only if you must. For leaderboard-style global ranks, reuse ideas from the leaderboard article sparingly — Stack Overflow is not a realtime game ranking.

Read path and caching

Anonymous GET question → CDN → origin cache (Redis) → SQL. Key by question_id + content_version. On edit/vote, bump version or purge. Authenticated users may need personalized bits (your vote state) layered client-side or via a small uncached include. This is textbook caching with stampede protection on viral posts.

Search and duplicates

Index title/body/tags; rank by text relevance × post score × recency. As-you-type ask box should suggest existing questions (typeahead) to reduce duplicates. “Related questions” can be a precomputed similarity list refreshed offline — same spirit as light recommendations.

Quora-style feed variant

If the prompt leans Quora: add follow graph and a home feed of answers from followed topics/people. Use fan-out on write for average users and fan-out on read for celebrities — straight from the news feed playbook. Stack Overflow can stay request-response + search.

Moderation and abuse

  • Rate-limit asks/votes/votes per user and IP.
  • Automate spam signals; send to review queue (job scheduler for SLA).
  • Soft-delete with tombstones for audit; hard-delete attachments from object storage later.
  • CAPTCHA / proof-of-work on suspicious clients — mention briefly.

Worked example

  1. User asks “Why is my HashMap slow?” with tags java, performance.
  2. Indexed in seconds; similar questions shown while typing.
  3. Answer A1 posted; author of question gets a push.
  4. 50 upvotes: votes table enforces one per user; score cached on page.
  5. Asker accepts A1; accepted flag flips; reputation worker grants accept bonus.

Interview narrative

Lead with read-heavy caching, SQL votes with unique constraints, and async search/reputation. Contrast Stack Overflow (search + canonical threads) with Quora (feed + follows). Tie notifications and rate limits as supporting boxes. Clean, practical, and distinctly not a generic CRUD app.

More in this series