Developers February 14, 2020

How to implement a multi-thread indiehackers like commenting system

Kieran Parker @kjparker

Hi all,

I am currently building heeed.co and a large part of the product is leaving feedback to one another, so comments are kind of a big deal.

I am new to development and currently using Javascript (Vue.js) to build this, witha firebase backend. I have built a basic comment system but dont know how to best tackle the reply-levels?

I have been made aware of disqus but a key point of my product is the users comments gains votes which add to their total score/reputation, so having a third party handle the comment doesnt seem to be an answer.

  1. 1

    Check out https://scottishtech.com/post/6

    This is a community platform that I’ve built from scratch.

    As you can see I believe I’ve “nailed” the comment reply problem (disclaimer: nothing is ever nailed).

    However i have solved the problem that indiehackers has with infinite indentation.

    It was actually a fairly complex problem to solve.

    I did so by making “replies” separate to “comments” which are separate to “posts”. So each is its own Model related by foreign keys and one to many relationships.

    A post can have many comments. And a comment can have many replies.

    1. 1

      Oh interesting! I shall have to explore this a little more and see how you have got it working so well!

      Do you have a repo I can take a look at, or maybe you can share your code or anything? I would love to properly see "under the hood" as a way to learn that.

      But you are right, maybe approaching it this way is best, and a 2-tier reply (vs the infinite tier system like reddit) may be a good MVP version for now.

  2. 1

    I have the same tech stack as you, Vue and Firebase. I'm planning on building a simple forum with commenting in the near future.

    Are you using RTDB or Firestore? As each implementation will be different.

    I'd start off exploring whether a flat structure of storing your comments will suffice. Replies are also comments but have a property that reference a parent comment.

    Vue should be able to handle ordering and representing comments with a parent ref as replies.

    If you're supporting pagination, then this approach might not be best because you would be required to fetch all comments. I would explore a nested data structure in this case.

    1. 1

      Hi there! Nice, I would love to see how you are handling your system!

      I am useing Firebase, apparently it is the newer and better but, as I said I am new so I just go with the more readily available knowledge/things tutorials use.

      Yes I was thinking a reference depending on the depth of the reply would be a good way to tier the comments, but have yet to test that approach (For example, if replying to parent directly, level = 1, if replying to a lvl 1 reply, level = 2, sort of thing. Would this be a good way to approach?)

      1. 1

        I don't think an explicit level property is needed because the level is inferred if a comment reply has a reference to a parent comment or is nested inside an existing comment.

        I'm going to be building my forum/comment system this week. I'm leaning towards keeping things a little more simple and only support a maximum of 2 levels of replies because I don't want to deal with the UI of infinite nested replies. This might change as I go but we'll see.

  3. 1

    The question is a bit unclear. Are you asking about the front-end or the back-end of the comment system?

    Is multi-threaded a reference to CPU multithreading, or are you referring to the fact that comments can have replies?

    1. 1

      Hey! Sorry for such an unclear question, you are right I should have specified a bit better.

      Essentially, both backend and frontend, although I believe I have a good understanding as to how to approach it, it is always nice to see how others would do so.

      and multi-threaded as a tier-comment system such as indiehackers where you can see the "tiers" or even like reddit. (Maybe multi threaded is the wrong word, maybe there is a better phrase for this type of comment system?

Recommended Posts