back
1 comments
Yeah I did look at the docs, hence my question. If you have a deeply nested comment tree, wouldn't you have to load each level sequentially?

So let's say you have A (root) -> B -> C -> D

Wouldn't you make one request to fetch A (root comments). Then a second request to fetch B (replies of A), another request to fetch C (replies of B) and then finally another request to fetch D (replies of C)?

And you can't fetch B,C,D in parallel, because you don't know the id's ahead of time to request the child comments.

Just something to think about, obviously doesn't matter until you have deeply nested discussions. But if you look at Reddit (or even HN) that is probably the most common case.

You’re right, and this was a tough design choice I made when I built the first prototype. Loading only first level of child comments should (correct me if I miscalculated this) be the most cost-efficient way as not every user is (hopefully) ever going to read all child comments in all levels in the hierarchy.
I wanted to make sure I understood the design decisions.

I actually have no idea what the right choice is. I only know how I use these types of sites and I usually go depth first. So I'd start with one thread, read it until I get bored, then continue. Not great for your current architecture, but I could be a weird user.

I had to design comment systems quite a few times, so I'm always curious how other people do it. I don't think there's a perfect solution, always trade offs to be made.

A comment could store a “head”/grandparent comment and a direct parent as well. For a top comment, every other comment could be fetched that has it as head, and the actual relationships can be reconstructed on server/client side as needed.

Though most dbs can do efficient recursive queries like this nowadays.

Yeah, I was thinking about the HTTP level. At the database level you can do recursive queries like you say. But on the client, with the current API, you're stuck fetching each level of comments sequentially. If you have 100-200ms per request (which is a pretty realistic scenario), loading discussions isn't going to be great.