All Questions
Data Modeling medium

Which pattern is simplest for modeling a hierarchical tree (e.g., Comment Threads) in SQL, despite its recursive query limitations?

  1. A Nested Sets, which provide superior write performance by utilizing a continuous mathematical range to identify all child nodes in a single operation.
  2. B Adjacency List, where each row simply contains a reference to its immediate parent node (e.g., a `parent_id` foreign key column).
  3. C Materialized Path, which encodes the entire ancestral lineage of a node into a single, searchable string field that is indexed for rapid prefix-based lookups.
  4. D Closure Table, which maintains a separate join table mapping every relationship between any two nodes in the tree, regardless of their distance.

One system design question a day, with spaced repetition so the ones you miss come back.

Get the app

Related questions