Knowledge Guide
HomeOO & Low-Level DesignOO Design Problems

Design Stack Overflow

Stack Overflow is one of the largest online communities for developers to learn and share their knowledge. The website provides a platform for its users to ask and answer questions, and through membership and active participation, to vote questions and answers up or down. Users can edit questions and answers in a fashion similar to a wiki.

Users of Stack Overflow can earn reputation points and badges. For example, a person is awarded ten reputation points for receiving an "up" vote on an answer and five points for the "up" vote of a question. The can also receive badges for their valued contributions. A higher reputation lets users unlock new privileges like the ability to vote, comment on, and even edit other people's posts.

Image
Image

Requirements and Goals of the System

We will be designing a system with the following requirements:

  1. Any non-member (guest) can search and view questions. However, to add or upvote a question, they have to become a member.
  2. Members should be able to post new questions.
  3. Members should be able to add an answer to an open question.
  4. Members can add comments to any question or answer.
  5. A member can upvote a question, answer or comment.
  6. Members can flag a question, answer or comment, for serious problems or moderator attention.
  7. Any member can add a bounty to their question to draw attention.
  8. Members will earn badges for being helpful.
  9. Members can vote to close a question; Moderators can close or reopen any question.
  10. Members can add tags to their questions. A tag is a word or phrase that describes the topic of the question.
  11. Members can vote to delete extremely off-topic or very low-quality questions.
  12. Moderators can close a question or undelete an already deleted question.
  13. The system should also be able to identify most frequently used tags in the questions.

Use-case Diagram

We have five main actors in our system:

Here are the top use cases for Stack Overflow:

  1. Search questions.
  2. Create a new question with bounty and tags.
  3. Add/modify answers to questions.
  4. Add comments to questions or answers.
  5. Moderators can close, delete, and un-delete any question.
Image
Image

Class diagram

Here are the main classes of Stack Overflow System:

Image
Image
Image
Image

Activity diagrams

Post a new question: Any member or moderator can perform this activity. Here are the steps to post a question:

Image
Image

Sequence Diagram

Following is the sequence diagram for creating a new question:

Image
Image

Code

Here is the high-level definition for the classes described above.

Enums, data types, and constants: Here are the required enums, data types, and constants:

java
public enum QuestionStatus {
    OPEN,
    CLOSED,
    ON_HOLD,
    DELETED
}

public enum QuestionClosingRemark {
    DUPLICATE,
    OFF_TOPIC,
    TOO_BROAD,
    NOT_CONSTRUCTIVE,
    NOT_A_REAL_QUESTION,
    PRIMARILY_OPINION_BASED
}

public enum AccountStatus {
    ACTIVE,
    CLOSED,
    CANCELED,
    BLACKLISTED,
    BLOCKED
}

Account, Member, Admin, and Moderator: These classes represent the different people that interact with our system:

java
// For simplicity, we are not defining getter and setter functions. The reader can
// assume that all class attributes are private and accessed through their respective
// public getter methods and modified only through their public methods function.

public class Account {
    private String id;
    private String password;
    private AccountStatus status;
    private String name;
    private Address address;
    private String email;
    private String phone;
    private int reputation;

    public boolean resetPassword();
}

public class Member {
    private Account account;
    private List<Badge> badges;

    public int getReputation();

    public String getEmail();

    public boolean createQuestion(Question question);

    public boolean createTag(Tag tag);
}

public class Admin extends Member {
    public boolean blockMember(Member member);

    public boolean unblockMember(Member member);
}

public class Moderator extends Member {
    public boolean closeQuestion(Question question);

    public boolean undeleteQuestion(Question question);
}

Badge, Tag, and Notification: Members have badges, questions have tags and notifications:

java
public class Badge {
    private String name;
    private String description;
}

public class Tag {
    private String name;
    private String description;
    private long dailyAskedFrequency;
    private long weeklyAskedFrequency;
}

public class Notification {
    private int notificationId;
    private Date createdOn;
    private String content;

    public boolean sendNotification();
}

Photo and Bounty: Members can put bounties on questions. Answers and Questions can have multiple photos:

java
public class Photo {
    private int photoId;
    private String photoPath;
    private Date creationDate;

    private Member creatingMember;

    public boolean delete();
}

public class Bounty {
    private int reputation;
    private Date expiry;

    public boolean modifyReputation(int reputation);
}

Question, Comment and Answer: Members can ask questions, as well as add an answer to any question. All members can add comments to all open questions or answers:

java
public interface Search {
    public static List<Question> search(String query);
}

public class Question implements Search {
    private String title;
    private String description;
    private int viewCount;
    private int voteCount;
    private Date creationTime;
    private Date updateTime;
    private QuestionStatus status;
    private QuestionClosingRemark closingRemark;

    private Member askingMember;
    private Bounty bounty;
    private List<Photo> photos;
    private List<Comment> comments;
    private List<Answer> answers;

    public boolean close();

    public boolean undelete();

    public boolean addComment(Comment comment);

    public boolean addBounty(Bounty bounty);

    public static List<Question> search(String query) {
        // return all questions containing the string query in their title or
        // description.
    }
}

public class Comment {
    private String text;
    private Date creationTime;
    private int flagCount;
    private int voteCount;

    private Member askingMember;

    public boolean incrementVoteCount();
}

public class Answer {
    private String answerText;
    private boolean accepted;
    private int voteCount;
    private int flagCount;
    private Date creationTime;

    private Member creatingMember;
    private List<Photo> photos;

    public boolean incrementVoteCount();
}
🤖 Don't fully get this? Learn it with Claude

Stuck on Design Stack Overflow? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **Design Stack Overflow** (OO & Low-Level Design) and want to truly understand it. Explain Design Stack Overflow from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **Design Stack Overflow** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **Design Stack Overflow** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **Design Stack Overflow** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes