title: Sequence Generator / Auto Increment using Cassandra 3.0
body: <p>I read a lot of Cassandras documentation and checked the Counter changes and alike. But it seams that Cassandra does not ship with a default and standard way to generate incremental sequences on the fly. </p>
  
  <p>All I found is using the IF statement / clause by doing a compare and set.</p>
  
  <p>This way one can check for the existence of a document and if not present generate one. Since this is done by a quorum algorithm regarded a cluster it should be easy to use and safe but with a high latency.</p>
  
  <p>To circumvent this latency one can generate (reserve) a thousand IDs by incrementing the nextSequenceId by thousand instead of one. This way one pays for the latency only once the first of the thousand is generated (or if its done prematurely it will have almost no latency at all).</p>
  
  <p>I understand that doing so will create a hot-spot or a congestion.</p>
  
  <p>One way to avoid this congestion is using more sequence number generators all going by a different offset (modulo) and limiting the chance of collision by randomly picking a certain sequence generator by choosing the modulo. </p>
  
  <p>So this will be my naive implementation. </p>
  
  <p>Since Cassandra 3.0 hit the street, I just wonder three things:</p>
  
  <ol>
  <li>Does Cassandra offer a smarter way of implementing sequences.</li>
  <li>Does Cassandra offer something to ease the pain of implementing this? I mean I do a read and than I do compare and set. Is there something more smarter?</li>
  <li>Does any library exist already giving me a kind of sequence numbers?</li>
  </ol>