LLD for a Version Control System (features like push, pull request, merge, etc.)
Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2024-02-02
Problem Statement
Designing a simplified Version Control System (VCS) that supports common source-control operations. The system will allow multiple developers to collaborate on projects, track changes, and manage code versions.
Functional Requirements
1.Repository Management
•Create repositories with a unique name.
•Track commits and maintain version history.
•Branching and merging support.
2.Commits
•Store code changes (diffs or snapshots).
•Each commit should have an author, message, timestamp, and parent reference(s).
3.Push & Pull
•Developers can push commits to a remote repository.
•Developers can pull latest commits from remote to local repository.
4.Pull Request (PRs)
•A user can raise a PR from one branch to another.
•PRs should allow review, approval, or rejection.
5.Merge
•System should support fast-forward merges and conflict detection.
•In case of conflicts, user should resolve manually.
6.Version Browsing
•Users should be able to checkout a commit/branch.
•Retrieve full history of commits for a file or branch.
Non-Functional Requirements
•Consistency → Repository state must remain consistent across push/pull.
•Scalability → Should support multiple users and branches.
•Extensibility → Future support for distributed repos, rebasing, tags, etc.
•Thread-Safety → Concurrent pushes/pulls must not corrupt repo state.
Design Hints (OOP + Patterns)
•Core Classes/Interfaces:
•Repository → holds branches, commits.
•Branch → pointer to a chain of commits.
•Commit → immutable object storing code changes.
•User → represents a developer.
•PullRequest → request object for branch merge.
•VersionControlService → orchestrates push, pull, merge.
•Design Patterns:
•Observer Pattern → Notify reviewers on PR creation.
•Command Pattern → Encapsulate VCS operations (commit, merge, revert).
•Strategy Pattern → Merge strategies (fast-forward, squash, rebase).
•Singleton → Global repository registry.
✅ Example:
"Design a Version Control System (like Git) with support for repositories, commits, branches, push, pull, pull requests, and merge. Identify key classes and their interactions. Extend the design to handle merge conflicts and code review workflows."