Scrivio Interview library
DesignPrincipal6 min read · updated 12 November 2026

Your company's ERP, HR and access-control systems each model the organization hierarchy differently, and vendors now pitch a graph database as the single answer. How do you decide whether to keep hierarchies in relational databases, adopt a graph database, or use a dedicated identity and directory service?

Decide from the questions the business asks, not from the technology: bounded-depth tree queries and ownership checks are well served by relational databases with recursive CTEs, closure tables or ltree, while graph databases earn their cost only for many-to-many traversals of unknown depth. Whatever the store, HR should be the single system of record that others consume through events or a directory, access control should live in an identity and directory service fed from HR, and effective-dated history must be in the design from the start.

Why this question is asked

When three systems model the org chart three ways, people feel the pain: a manager approves expenses in ERP for a team they left in HR, and access reviews show permissions nobody can explain. A vendor promising one graph database for everything sounds like relief. Interviewers ask this at principal level because the right answer is rarely about the database; it is about systems of record, ownership and history, and about not adding a technology without a workload that needs it. In this answer, we will start from the questions asked, separate ownership from storage, place access control, weigh the cost of a new database, and plan for history, ending with a decision flow.

1Start From the Questions Being Asked

List the actual queries. Who are all the people under this director. Who approves this purchase, meaning walk up the chain until someone has enough authority. Does this user belong to the finance org for this permission. These are tree questions of bounded depth, maybe 10 to 15 levels, and relational databases handle them well with recursive CTEs, closure tables or PostgreSQL's ltree.

Graph databases shine for a different shape: many-to-many relationships traversed to unknown depth with varied edge types, such as which people are connected through shared projects, matrix reporting and committees, within four hops. If nobody can name such a query with a real business owner, the graph database is solving a problem we do not have.

2One System of Record, Many Consumers

The deeper problem in the scenario is not storage but ownership. Three systems each keep their own copy, edited separately, so they drift. The fix is to choose one system of record for the hierarchy, almost always the HR system, since reporting lines are an HR fact, and make the others consume it.

Consumption happens through published change events, such as employee-moved or org-unit-created, or through a directory that systems query. ERP may still store the hierarchy in its own tables for its approval workflows, and that is fine, as long as those tables are derived and never edited by hand. Changing the storage engine without fixing ownership would just create a fourth copy.

Step throughHierarchy ownership after the change
  1. HR systemsystem of record for people and reporting lines
  2. Change events / directory syncemployee-moved, org-unit-created
  3. Identity and directory servicegroups and roles derived from HR
  4. ERP and other applicationsderived copies for their own workflows, read-only

4 layers, from the top down. Step through them one at a time.

Storage can differ per consumer; ownership must not.

3Where Access Control Belongs

Access control usually belongs in an identity and directory service, such as an LDAP directory, Entra ID or another identity provider, with groups and roles fed automatically from HR attributes like department and manager. Applications ask is this user in group finance-approvers rather than computing the org chart in their own tables. The benefit is one place for joiners, movers and leavers, and one place for auditors to review.

Fine-grained rules that do depend on the tree, such as a manager seeing their whole reporting line, can be served by an authorization service that holds the hierarchy as a closure table or a relationship graph. That is a narrow, well-defined workload, which is a better reason to choose specific technology than a general wish for one database.

4The Real Cost of a New Database

Adding a database technology means new operations work, backups and restore tests, upgrades, monitoring, security reviews, licensing and, most of all, skills: someone has to be on call for it at 3 a.m. A rough rule I use is that a new store needs a workload that existing ones cannot serve at acceptable cost, and an owner team willing to run it.

So the test for the vendor's pitch is concrete: name the queries the graph database will serve, show that the relational version is too slow or too complex for them, with a prototype on real data, and show who will operate it. Often the pilot reveals that the hard part was data quality and ownership, which the graph database does not fix.

5Planning for History

Audits ask questions about the past: who approved this invoice and were they the requester's manager on 14 March. A hierarchy that only stores the current state cannot answer, and graph pilots often skip history because it complicates the demo. We model reporting lines as effective-dated rows.

SQL
CREATE EXTENSION IF NOT EXISTS btree_gist;
CREATE TABLE reporting_line (
employee_id int NOT NULL,
manager_id int NOT NULL,
valid daterange NOT NULL, -- [from, to)
EXCLUDE USING gist (employee_id WITH =, valid WITH &&) -- no overlapping lines per person
);
-- who was the manager of 42 on 2026-03-14?
SELECT manager_id FROM reporting_line
WHERE employee_id = 42 AND valid @> DATE '2026-03-14';
-- 17
Step throughDeciding where the hierarchy lives
  1. List the real hierarchy queries and owners
  2. Bounded-depth tree questions only?
    Yesrelational: CTE, closure table or ltreeNoconsider a graph store for that workload
  3. Make HR the system of recordothers consume events or a directory
  4. Access control via identity servicegroups and roles fed from HR
  5. Model effective dates from the start

5 steps in order. Play them, or step through them one at a time.

The exclusion constraint guarantees that each person has at most one manager on any day. A recursive CTE that filters every level by the same date reconstructs the whole chain as of that date. Matrix organisations may need several lines of different types, which we add as a line_type column with the constraint per type.

6Follow-up questions

How would you model effective-dated reporting lines?

Store one row per employee, manager and validity range, using a daterange with a half-open upper bound, and an exclusion constraint that prevents overlapping ranges for the same employee. Changes close the current row and open a new one rather than updating in place. Queries filter by valid @> the date of interest, and a chain as of a date is a recursive CTE where each level applies the same date filter. Future-dated changes for planned reorganisations fit naturally.

What would make you choose the graph database after all?

A real workload of deep, many-to-many traversals, for example relationship analysis across projects, committees and matrix lines for compliance, where relational prototypes are slow or unreadable, plus a team ready to operate it. Even then I would feed it from the HR system of record rather than make it a new master.

How do you move three systems to one source without a big bang?

Start by publishing HR events and building a reconciliation report showing where ERP and access control disagree with HR. Fix the differences, then switch one consumer at a time to derived data and remove its manual editing screens, measuring the disagreement count until it reaches zero.

7Conclusion

In this answer, we decided from the queries asked: bounded-depth tree questions fit relational databases, while graph databases need deep many-to-many traversals to justify them. We made HR the system of record with consumers fed by events or a directory, placed access control in an identity service, required a concrete workload and owner before adding a database, and modelled effective-dated reporting lines so audits can ask about the past.

What to say in the interviewAbout 80 seconds aloud

Open with

I would start by listing the actual questions: all people under a manager, the approval chain for a purchase, whether a user belongs to an org for a permission.

Then, if they want more

Those are tree queries of bounded depth, and relational databases answer them well with recursive CTEs, closure tables or ltree. Graph databases are strong for many-to-many traversals of unknown depth, so I would ask the vendor to name those queries and prove the relational version cannot serve them. The bigger issue is that three systems each edit their own copy.

I would make HR the system of record for reporting lines and have ERP and the others consume it through change events or a directory, as derived, read-only copies.

Access control belongs in the identity and directory service, with groups and roles fed from HR, so applications ask about group membership instead of computing org charts; a narrow authorization service can hold a closure table for manager-sees-team rules. I would weigh the full cost of a new database: operations, backups, licensing and on-call skills.

And I would insist on history from the start: effective-dated reporting lines with a validity range and an exclusion constraint, so audits can ask who someone's manager was on a given date, which graph pilots often leave out.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Your company's ERP, HR and access-control systems each model the organization hierarchy...": https://scrivio-interview-library.netlify.app/databases/sql-coding-problems/618df08fa5/