title: Migrate data model from MySQL to Cassandra
body: <p><strong>Structure in MySql</strong> (for compactness i am using a simplified notation)</p>
  
  <p><em>Notation: table name->[column1(key or index), column2, …]</em></p>
  
  <pre><code>documents-&gt;[doc_id(primary key), title, description]
  elements-&gt;[element_id(primary key), doc_id(index), title, description]
  </code></pre>
  
  <p>Each document can contain a large number of elements (between 1 and 100k+) </p>
  
  <p>We have two key requirements:</p>
  
  <ul>
  <li>Load all elements for a given doc_id quickly</li>
  <li>Update the value of one individual element by his element_id quickly</li>
  </ul>
  
  <p><strong>Structure in Cassandra</strong></p>
  
  <p>1st solution</p>
  
  <pre><code>documents-&gt;[doc_id(primary key), title, description, elements] (elements could be a SET or a TEXT, each time new elements are added (they are never removed) we would append it to this column)
  elements-&gt;[element_id(primary key), title, description]
  </code></pre>
  
  <p>To load a document we would need:</p>
  
  <ul>
  <li><p>Load document with given  and get all element ids: SELECT * from documents where doc_id=‘id’</p></li>
  <li><p>Load all elements with the given ids: SELECT * FROM elements where element_id IN (ids loaded from query a)</p></li>
  </ul>
  
  <p>Updating elements would be done by their primary key.</p>
  
  <p>2nd solution</p>
  
  <pre><code>documents-&gt;[doc_id(primary key), title, description]
  elements-&gt;[element_id(primary key), doc_id(secondary index), title, description]
  </code></pre>
  
  <p>To load a document we would need:</p>
  
  <ul>
  <li>SELECT * from elements where doc_id=‘id’</li>
  </ul>
  
  <p>Updating elements would be done by their primary key.</p>
  
  <p>Questions regarding our solutions: </p>
  
  <ul>
  <li><p>1st: Will it be efficient to query 100k+ primary keys in the elements table?</p>
  
  <pre><code>SELECT * FROM elements WHERE element_id IN (element_id1,.... element_id100K+)?
  </code></pre></li>
  <li><p>2nd: Will it be efficient to query just by a secondary index?</p></li>
  </ul>
  
  <p>Could anyone give any advice how would we create a model for our use case?</p>