title: Cassandra Primary Key Selection to Bound Partition Growth
body: <p>We are currently testing Cassanda as a database for a big amount of meta-data on communication events. As most queries will be limited to a single customer, it makes sense to shard by customer ID. However, this would mean the partitions would keep growing infinitely over time. I'm struggling a bit to come up with a solution that seems clean enough.</p>
  
  <p>The first idea is to use a composite key of customer ID and some time interval. Are there other options, that might be better and grow more organically?</p>
  
  <p>As we want to have as few partition reads as possible, I was thinking to simply use the year to put an upper bound on data per customer per partition. However, this would distribute the data rather unevenly, if I'm not mistaking. Could this be solved by moving to months or even weeks/days?</p>
  
  <p>I'm sure that this is a problem that often comes up and I'm interested in hearing the various solutions that people put into place.</p>
  
  <p>EDIT: To be more clean on the type of query, they will calculate aggregates over big time slices, per customer. Ideally, we would only have this:</p>
  
  <p>PRIMARY KEY ((customer_id), timestamp)</p>
  
  <p>However, as I've mentioned, this would lead to unbound growth per partition over the years.</p>