KatInterview

Dependency-Aware Software Package Manager: Resolve, Install, Roll Back

System DesignModel answer
MediumModel answerSystem Designsystem-designdependency-resolutiongraphs

Last updated

Design a client-side package manager that resolves versioned dependencies, rejects cycles and conflicts, and applies installs transactionally with recovery after failure.

Problem

You are asked to design a tool in the spirit of apt, npm or pip. It installs, upgrades and removes software packages, and it must leave the machine in a healthy, consistent state after every operation, including when an operation fails midway.

What the tool must do

  • Transitive resolution. Given a package name and version, work out every package it needs, directly or indirectly.
  • Version constraints. Understand requirements such as A >= 1.2.0 or B < 2.0.0.
  • Conflict detection. Refuse an installation when two requirements demand incompatible versions of the same package.
  • Cycle detection. Reject circular dependencies (A needs B, B needs A) and report them clearly.
  • Atomicity. If an install breaks partway, there must be a way to return to the last known good state.

Quality targets

  • Scale: thousands of packages in play and deep dependency chains.
  • Speed: keep the time between the user's command and the first download as short as possible.

What to cover in your answer

  1. How package metadata and versions are stored.
  2. The in-memory graph model and how it supports cycle and conflict detection.
  3. The algorithm that picks a valid set of versions (backtracking, SAT, or something else), and its trade-offs.
  4. How you handle partially applied installs and protect system integrity.

State your assumptions (single machine vs. fleet, one version per package vs. several, and so on) before you start.

Hints

Hint 1

Separate the work into a pure planning phase (compute the final set and ordered actions) and an execution phase (download, verify, apply). Planning should touch nothing on disk.

Hint 2

Version selection with conflicting constraints is NP-complete in general. Think about a backtracking search with good heuristics, then about how conflict-driven learning (as in PubGrub or SAT solvers) avoids repeating doomed branches.

Hint 3

For atomicity, think like a database: take a lock, write a journal entry first, stage everything off to the side, then switch it into place with atomic renames, and use the journal to finish or undo after a crash.