How would you model posts, comments, and threaded chat replies in a relational database? #167352
-
Select Topic AreaQuestion BodyHey everyone, I’d love to initiate a discussion on how developers approach designing relational database schemas for posts, comments, and threaded replies (such as chat or discussion threads). The kind of structure I’m thinking of is similar to what you’d see in forums, comment sections, or collaborative tools:
Some points to kick off the discussion:
This is something that comes up in lots of apps, from blogs and forums to support systems and chat platforms, and there’s no one-size-fits-all. I’m curious to hear how different people have approached this problem, especially with scalability, maintainability, and developer experience in mind. Feel free to share your models, thoughts, trade-offs, or even pain points from past projects. Looking forward to learning from the community! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Single self-referencing table all the way; Don't overthink this, it's a solved pattern.
Key decisions:
Performance reality check: Reddit, HN, and most forums use variations of this. If it's good enough for millions of comments, it's good enough for your app. |
Beta Was this translation helpful? Give feedback.
-
As you started this conversation here, I thought you'd like to imitate message threading in GitHub, as they thread messages in only one tier only in "discussions". (They could let us enable in repositories any feature of "discussions".) I read "table" and thought "project table". |
Beta Was this translation helpful? Give feedback.
Single self-referencing table all the way; Don't overthink this, it's a solved pattern.
Key decisions: