title: Cassandra design pattern for shared record (m:n)
body: <p>we have two entities User and Role. One User can have multiple Roles, and single Role can be shared by many users - 
  typical m:n relation.
  Roles are also dynamic and we expect large amount (millions).</p>
  
  <p>It is quiet simple to model such data in relational DB. I would like to find out whenever it would be possible in cassandra. </p>
  
  <p>Currently I see two solutions:</p>
  
  <p><strong>A) Use normalized model and create something similar to inner-join</strong> </p>
  
  <p>Create each single role in separate CF and store in User record foreign keys to referenced roles.</p>
  
  <p><em>pro:</em> Roles are not replicated and maintenance is simple</p>
  
  <p><em>contra:</em> In order to get all Roles for single User multiple network calls are necessary. User record contains only FK, Roles are stored
  using random partitioner, in this case each role could be stored on different cassandra node.</p>
  
  <p><strong>B) Denormalize model and replicate roles to avoid round trips</strong>
  In this scenario User record in cassandra contains all user roles as copy. </p>
  
  <p><em>pro:</em> It is possible to read User with all roles within single query. This guarantees short load times.</p>
  
  <p><em>contra:</em> Each shared Role is copied multiple times - on each related User. Maintaining roles is very difficult, especially if we have
      large data amount. For example: one Role is shared by 1000 users. Changes on this Role require update on 1000 User records.
      For very large data sets such updates has to be executed as asynchronous job.</p>
  
  <p>Solutions above are very limited, meybie Cassandra is not right solution for m:n relations ? Do you know any cassandra design patter for such problem?</p>
  
  <p>Thanks,
  Maciej</p>