← Questions
Design a read-heavy service for org chart subordinate counts
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A system design interview question asked in Microsoft's system design round, last asked Feb 2026. It tests graphs, caching and read-heavy.
You are given manager-to-direct-report relationships for a company: each employee has at most one manager, and the top employee has none. Build a service that answers "how many people are under this person?" (all direct and indirect reports) for any employee at very high read volume, and stays correct when reporting lines change.
Requirements
- Functional: query the total number of reports under an employee; move an employee (with their whole subtree) from one manager to another; add and remove employees.
- Non-functional: reads vastly outnumber updates and must be fast; after an update, later queries return correct counts; an update must never create a cycle (someone ending up under their own report); concurrent updates must not corrupt counts.
Clarifying questions
- How many employees, and how deep is the hierarchy?
- How often do reporting lines change, and how fresh must counts be after a change?
- Do queries need only the count, or also the list of reports?
- Can several reorganisation moves arrive at once, as one batch?
What a strong answer covers
- The data model: a parent pointer per employee and a stored subtree count per employee.
- Reads in O(1) from the precomputed counts, served from a cache or replicas.
- Moving employee X with subtree size s: subtract s from every ancestor of the old manager and add s to every ancestor of the new one; cost O(depth) per move.
- Cycle prevention: reject a move whose new manager is X or one of X's descendants, by walking the new manager's ancestors.
- Concurrency: serialise updates (a single writer or per-tree locking) and apply each move's count changes atomically, so readers never see half a move.
- Alternatives and trade-offs: an Euler tour with a Fenwick tree for O(log n) subtree queries, a closure table in SQL, or recomputing in batch when updates are rare.
Follow-ups
- A reorg moves 5,000 people at once. Apply it without readers seeing intermediate counts.
- Also answer "how many engineers are under this person?" by role.
- The hierarchy is very deep (a chain of 10^5). What breaks, and what do you change?
- Spread the service across regions. Where do updates go?
Where it's asked
- Microsoft · System design · Last asked Feb 202660 min · Design discussion
What it tests
No official answer yet. Draw yours on the right; publish it and it shows under Community.
Nothing published yet. Publish your canvas and it shows here for others to open and remix.
Draw your answer hereBoxes, arrows and notes, saved for you to come back to.Sign in to start drawing
