title: Design data model for messaging system with Cassandra
body: <p>I am new to Cassandra and trying to build a data model for messaging system. I found few solutions but none of them exactly match my requirements. There are <strong>two main requirements</strong>:</p>
  
  <ol>
  <li>Get a list of last messages for a particular user, from all other users, sorted by time.</li>
  <li>Get a list of messages for one-to-one message history, sorted by time as well.</li>
  </ol>
  
  <p>I thought of something like this,</p>
  
  <pre><code>CREATE TABLE chat (
    to_user text,
    from_user_text,
    time text,
    msg text,
    PRIMARY KEY((to_user,from_user),time) 
    ) WITH CLUSTERING ORDER BY (time DESC);
  </code></pre>
  
  <p>But this design has few issues, like I wont be able to satisfy <strong>first requirement</strong> since this design requires to pass from_user as well. And also  this would be inefficient when number of (to_user,from_user) pair increases.</p>