Design a Discussion Forum with Posts and Votes
Model a small discussion forum with post creation, nested replies and per-user votes that remain correct under retries and concurrent changes.
For this exercise, assume a single in-memory discussion forum serves an existing set of registered users. An upstream caller supplies the authenticated user identity. Users can publish a plain-text post with a nonblank title and body, list posts in reverse creation order, and open a post with its comments.
A comment belongs to exactly one post and may reply to that post or to an existing comment within the same post. Replies may nest; siblings appear in creation order. Posts and comments receive stable identities and remain unchanged after creation.
For this exercise, a user can set their vote on a post to +1, -1 or 0, where 0 removes that user's current vote. Voting on comments is outside scope. There is at most one current vote per user and post, and the displayed score is the sum of current votes.
Repeating the same chosen value does not add another contribution. Vote requests include a caller-scoped request identity and the expected revision of that caller's vote on the target post. The initial vote is 0 at revision 0.
An actual value change advances the vote revision once; an unchanged value at the current revision is a successful no-op. A new request with a stale revision fails without changing state.
Repeating an identical request returns its original outcome, even after a later vote change; reusing its identity with different inputs conflicts. Such a replay is historical evidence, not a claim about the current vote or score. Retain request outcomes for the life of this process.
Design the responsibilities, state ownership, public method contracts and interactions. Missing users or posts, invalid vote values, blank text and a reply parent from another post must have explicit failure outcomes with no partial mutation. Returned views must not let callers mutate domain state.
A post read observes a coherent current thread and score. Several application threads may vote concurrently; changes to a user's vote, its revision, the score and the request outcome must appear indivisible to callers.
Explain where a design pattern helps and where simpler composition is enough, without implementing the code.
Persistence, process-restart recovery, distributed services, moderation, post/comment editing or deletion, user tags, follow-based feeds, search, media, ranking customization, pagination and vote-receipt eviction are outside scope.
Creation calls are distinct submissions; retry semantics in this exercise apply only to voting.