How would you design LIKE system for a post?


  • 2

    How would you design like/unlike system for a particular post.


  • 0
    W

    There are a lot of questions needs to be clarified. For example, do we only show the number of likes like instagram or we show both like and unlike

    If we only show the count of like.

    Use an atomic type (or other ways to make sure the thread safe)
    when like, count++, when unlike, count--

    Also, one account can only like and unlike once.


  • 1
    D

    addLike(postId, personId) {
    //update post likes by 1
    // add person like with post id
    }


  • 4
    B

    Have just implemented this for a project im working on.

    So for LIKE, I'm using GraphQL Mutation. You need two argument.

    1. userId,
    2. postId

    Then ensure the user is authenticated and first know for sure the post exist and then do something like post.createLike(user) depending on how you structured your DB and table. If you need further help on this, do let me know.

    For removeLike its almost similar, post.removeLike(user)


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.