Question

I'm looking for a good way to store comments in cassandra. Can someone provide me a good Cassandra data model to store comments?

The data model should allow me to retrieve a certain number of these comments with phpcassa.

This was my idea:

Comments = {
    CommentId1:{
        CommentAuthor,
        Content,
        Timestamp
    },
    CommentId2:{
        CommentAuthor,
        Content,
        Timestamp
    }
    ...
}

CommentsLine = {
    EntryId1:{
        CommentId1: timestamp,
        CommentId2: timestamp,
        CommentId3: timestamp,
        ...
    }
    ...
}

But i'm not sure this is the better way. Thanks for helping.

Was it helpful?

Solution

Your solution seems to be cool but may be it's better to store in the CF CommentsLine the key with a timestamp like that you can order your comments.

CommentsLine = {
    EntryId1:{
        timestamp: CommentId1 ,
        timestamp: CommentId2 ,
        timestamp: CommentId3 ,
        ...
    }
    ...
}

OTHER TIPS

I've solved this problem once. Here is How i solved this problem. A separate ColumnFamily comments where each row is an ID of comment (my ID were of the form {Parent Post ID}-{Comment author user ID}-{Comment Posted Timestamp}) and then have a columns within containing Author, comment, posted date etc.

You can have your own format and separating them out in an individual column family makes sure they are distributed.

Once done link you have to link each comment to its parent you can do so by keeping a column name comments that can have {Posted Timestamp} -> {{Comment author user ID} and other meta data as JSON} (This was totally specific to my scenario you should think something you like).

When somebody comments you can generate is posted micro time from PHP and accordingly insert into cassandra. This format ensures that Cassandra distributes comments in rings and the row in post remains minimal only containing required information.

Loading comments back requires you selecting columns and then do a MultiGet call on Comments column family.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top