Getting Ready: Stack Overflow
Why This Problem Matters
Stack Overflow is one of the most influential software platforms ever built. Launched in 2008 by Jeff Atwood and Joel Spolsky, it has grown to over 100 million monthly visitors, hosts 23+ million questions and 34+ million answers, and was acquired by Prosus in 2021 for $1.8 billion. Nearly every developer has used Stack Overflow — it's the de facto knowledge base of the software industry.
What makes Stack Overflow an exceptional design problem is the reputation and gamification engine at its core. Unlike a simple Q&A forum, Stack Overflow uses a sophisticated point system where every upvote, downvote, accepted answer, and bounty changes a user's reputation score. That reputation score then gates privileges: you need 15 reputation to upvote, 125 to downvote, 2,000 to edit others' posts, and 3,000 to cast close votes. This creates a self-moderating community — no team of paid moderators could review 8,000+ new questions posted daily. The design challenge is modeling this reputation-privilege system cleanly with objects.
The second design challenge is the content hierarchy. Both questions and answers are "posts" — they share attributes like body text, author, creation time, vote count, and comments. But they behave differently: questions have titles, tags, bounties, and close status; answers have an acceptance flag and link back to their parent question. This shared-yet-different structure is ideal for inheritance and polymorphism — a concept you've practiced in fundamentals but now apply to a real system.
This problem appears frequently in LLD interviews at companies like Stack Overflow itself, Quora, Reddit, Discourse, and general mid-to-senior engineering roles. Interviewers evaluate whether you can model the voting/reputation system without tangling it into the post classes, whether you separate search from content, and whether your class hierarchy supports extensibility (adding new post types like wikis or polls without modifying existing code).
What You'll Learn
By completing the Stack Overflow design problem, you will:
- Design a reputation and gamification system — model how upvotes, downvotes, accepted answers, and bounties affect user reputation, and how reputation gates privileges
- Apply the Observer Pattern to notifications — when someone answers your question, comments on your post, or awards a bounty, the system notifies you without the post classes knowing about notifications (Fundamentals S12)
- Apply the Strategy Pattern for search ranking — users can sort search results by relevance, newest, votes, or activity. The search algorithm is swappable at runtime (Fundamentals S12)
- Model a content hierarchy with inheritance — Questions and Answers share a common
Postbase but have distinct behaviors, demonstrating practical polymorphism - Design a voting system that tracks who voted on what, prevents duplicate votes, and propagates reputation changes
- Build a Use Case Diagram identifying multiple actors (Member, Moderator, Admin, Guest) with distinct capabilities
- Build a Class Diagram with 10-12 classes demonstrating composition, association, and inheritance
- Implement the complete system in Python and Java with realistic driver examples
This is a Medium-level problem. We assume you've completed at least one Easy problem and are comfortable with OOP relationships and basic pattern application.
Prerequisites
Before starting this problem, make sure you're comfortable with:
- Inheritance and Polymorphism — Questions and Answers share a common base class. You'll use polymorphism to treat both uniformly when voting and commenting (Fundamentals S3)
- OOP Relationships — Composition for comments bound to posts, Association for users linked to questions, Aggregation for tags shared across questions (Fundamentals S4)
- Observer Pattern — notifications are decoupled from the content classes. When a new answer is posted, the question author is notified without the
Answerclass knowing about notifications (Fundamentals S12) - Strategy Pattern — search ranking algorithms are interchangeable. We used this for pricing in the Parking Lot (DP1) and scheduling in the Elevator (DP8); here we apply it to search result ordering (Fundamentals S12)
- UML Class Diagrams — reading class boxes, relationship arrows, and stereotypes like
<<interface>>and<<abstract>>(Fundamentals S5) - At least one Easy design problem completed — ideally the Parking Lot (DP1) or Logging Framework (DP5)
If the Observer Pattern feels unfamiliar, revisit Fundamentals S12 before proceeding. The notification system and reputation propagation depend on understanding how subjects notify observers without tight coupling.
Problem Scope
We will design: The core domain logic of a Stack Overflow-style Q&A platform — question/answer posting, voting and reputation, tagging, comments, search with multiple ranking strategies, bounties, question lifecycle (open/closed), badge awards, and notification dispatch.
We will NOT design:
- Database schemas or persistence layer
- REST APIs or web interface
- Full-text search indexing (Elasticsearch, Lucene) — we model the search interface, not the engine
- Rich text editing or Markdown rendering
- OAuth/authentication infrastructure
- Distributed systems concerns (caching, CDN, load balancing)
- Chat/messaging features
- Community wiki or documentation features
This is a Low Level Design (object-oriented) exercise. We focus on classes, relationships, the reputation algorithm, voting mechanics, and design patterns — not infrastructure.
The Design Process We'll Follow
We'll follow the systematic process from Fundamentals S16 (Interview Framework):
- Requirements — Define what the Q&A platform must do (functional) and how well (non-functional)
- Use Case Diagram — Identify actors (Guest, Member, Moderator, Admin) and map their interactions
- Class Diagram — Design the object model with all classes, attributes, methods, and relationships
- Code Implementation — Full Python and Java implementation matching the class diagram
- Reputation & Voting System — Deep dive into the reputation algorithm, vote tracking, and privilege gating
- Design Patterns — Analyze how Observer, Strategy, and other patterns improve the design
- Testing & Edge Cases — Validate with tests and identify failure scenarios
- Summary — Consolidate design decisions and key takeaways
The Reputation & Voting System tutorial is unique to this problem — it's an algorithm-focused deep dive into how reputation points flow through the system, how badges are awarded, and how privilege thresholds work. This is the heart of what makes Stack Overflow more than a simple forum, and it's the tutorial where most interview follow-up questions will focus.