KatInterview

Org Chart Service: Hierarchy Storage and Safe Manager Moves

System DesignModel answer
HardModel answerSystem Designsystem-designhierarchyclosure-table

Last updated

Design a service for a large company's reporting structure that serves chain and subtree lookups quickly and keeps reporting lines acyclic under concurrent reorganizations.

Org Chart Service

A company with more than 100,000 people (and room to grow) needs a backend that stores who reports to whom. Design that service.

What it must do

  1. Create employees and change who an employee reports to.
  2. Return the people who report directly to a given manager.
  3. Return the full upward chain of managers for any employee.
  4. Return everyone beneath a given manager, at any depth.

Quality requirements

  • Directory reads must be fast and highly available.
  • Reorganizations are frequent, including moving whole teams or departments.
  • Reporting lines must be strongly consistent. The structure must never contain a loop, such as A managing B while B manages A, even when many changes arrive at the same time.

What to cover in your answer

  • A storage schema, and why it keeps subtree queries cheap.
  • The HTTP API for the operations above.
  • An architecture that handles concurrent changes to the structure safely.
  • How you detect and prevent loops when a manager is changed, including what happens when two changes race.

State your assumptions about scale (read and write rates, tree depth) and justify your choices with trade-offs.

Hints

Hint 1

Compare four ways of storing a tree: a plain parent pointer, nested intervals, stored paths, and an ancestor/descendant pair table. For each, ask how costly subtree reads and subtree moves are.

Hint 2

Moving employee E under manager M creates a loop exactly when M is E or already sits below E. Think about which storage layout lets you test that with a single lookup.

Hint 3

Two moves can each look safe on their own and still form a loop together (A under B, B under A). Which isolation or locking strategy rules this out, and is a heavy one acceptable at your write rate?