incubator-cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kanwar Sangha <>
Subject RE: DataModel Question
Date Thu, 07 Feb 2013 05:30:32 GMT
Thanks Aaron !

My use case is modeled like "skype" which stores IM + SMS + MMS in one conversation.

I need to have the following functionality -

*        When I go offline and come online again, I need to retrieve all pending messages
from all my conversations.

*        I should be able to select a contact and view the 'history' of the messages (last
7 days, last 14 days, last 21 days...)

*        If I log in to a different device, I should be able to synch at least a "few days"
of messages.

*        One conversation can have multiple participants.

*        Support full synch or delta synch based on number of messages/history.

I guess this makes the data model span across many CFs ?

From: aaron morton []
Sent: 06 February 2013 22:20
Subject: Re: DataModel Question

2)      DynamicComposites : I read somewhere that they are not recommended ?
You probably wont need them.

Your current model will not sort message by the time they arrive in a day. The sort order
will be based on Message type and the message ID.

I'm assuming you want to order messages, so put the time uuid at the start of the composite
columns. If you often want to get the most recent messages use a reverse comparator.

You could probably also have wider rows if you want to, not sure how many messages kids send
a day but you may get by with weekly partitions.

The CLI model could be:
row_key: <phone_number : day>
column: <time_uuid : message_id : message_type>

You could also pack extra data used JSON, ProtoBuffers etc and store more that just the message
in the column value.

If you use using CQL 3 consider this:

create table messages (
            phone_number                        text,
            day                                                      timestamp,
            message_sequence     timeuuid, # your timestamp
            message_id                             integer,
            message_type                         text,
            message_body                        text
) with PRIMARY KEY ( (phone_number, day), message_sequence, message_id)

(phone_number, day) is the partition key, same the thrift row key.

 message_sequence, message_id is the grouping columns, all instances will be grouped / ordered
by these columns.

Hope that helps.

Aaron Morton
Freelance Cassandra Developer
New Zealand


On 7/02/2013, at 1:47 AM, Kanwar Sangha <<>>

1)      Version is 1.2
2)      DynamicComposites : I read somewhere that they are not recommended ?
3)      Good point. I need to think about that one.

From: Tamar Fraenkel [<>]
Sent: 06 February 2013 00:50
Subject: Re: DataModel Question

I have couple of questions regarding your model:
 1. What Cassandra version are you using? I am still working with 1.0 and this seems to make
sense, but 1.2 gives you much more power I think.
 2. Maybe I don't understand your model, but I think you need  DynamicComposite columns, as
user columns are different in number of components and maybe type.
 3. How do you associate between the SMS or MMS and the user you are chating with. Is it done
by a separate CF?

Tamar Fraenkel
Senior Software Engineer, TOK Media
Tel:   +972 2 6409736
Mob:  +972 54 8356490
Fax:   +972 2 5612956

On Wed, Feb 6, 2013 at 8:23 AM, Vivek Mishra <<>>
Avoid super columns. If you need Sorted, wide rows then go for Composite columns.


On Wed, Feb 6, 2013 at 7:09 AM, Kanwar Sangha <<>>
Hi -  We are designing a Cassandra based storage for the following use cases-

*        Store SMS messages

*        Store MMS messages

*        Store Chat history

What would be the ideal was to design the data model for this kind of application ? I am thinking
on these lines ..

Row-Key :  Composite key [ PhoneNum : Day]

*        Example:   19876543456:05022013

Dynamic Column Families

*        Composite column key for SMS [SMS:MessageId:TimeUUID]

*        Composite column key for MMS [MMS:MessageId:TimeUUID]

*        Composite column key for user I am chatting with [UserId:198765432345] - This can
have multiple values since each chat conv can have many messages. Should this be a super column









View raw message