Store a hierarchy and return all children
AtlassianSoftware Engineer · OnsiteLast updated
This question evaluates understanding of hierarchical data modeling, REST API design, database schema choices (e.g., adjacency list vs alternatives), and systems-level concerns like scalability, pagination for large subtrees, and cycle prevention.
Design a service to store a hierarchical tree of nodes and expose APIs.
Requirements:
- Persist a hierarchy (a forest with multiple roots is acceptable).
- Support:
- Add a node under a parent.
- Return all descendants (all children recursively) of a given node.
- Emphasis on REST API design, DB schema, and edge cases.
Deliverables:
- API endpoints and example requests/responses.
- Storage model choice (e.g., adjacency list, materialized path, nested sets, closure table) and justification.
- How to handle large subtrees (pagination) and prevent cycles.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.