title: Cassandra, partition/primary key: partitioning and constraint
body: <p>I'm trying to design some column-family in Cassandra but I have some doubt about the primary/partition key.<br>
  What I want is the following:</p>
  
  <ul>
  <li>Spread data evenly around the cluster</li>
  <li>Minimize the number of partitions read</li>
  </ul>
  
  <p>I know that these goals are achievable by choosing the appropriate partition/primary key, but suppose that the partition/primary key choosed allows invalid data in your colum-family, what do you do?<br></p>
  
  <p>Suppose that I have the following colum-family:</p>
  
  <pre><code>CREATE TABLE group (
    groupname text,
    username text,
    PRIMARY KEY (groupname, username))
  </code></pre>
  
  <p>Suppose that a username must belong only in <strong>one group</strong>, with this primary key I can achieve (with some assumption) the previous goals, but there is no way to avoid that a username is placed in more than one group.<br></p>
  
  <p>Can I simply make assumption on what will be in the column-family or there are ways to avoid the insertion of invalid data? </p>