title: Cassandra - Make Counter Update And Normal Update Atomic
body: <p>I was going through this <a href="https://engineering.instagram.com/instagration-pt-2-scaling-our-infrastructure-to-multiple-data-centers-5745cbad7834" rel="nofollow noreferrer">Instagram engineering article</a> where in they had mentioned about denormalizing counters, I quote </p>
  
  <blockquote>
    <p>To reduce the resources needed for each of these operations, we denormalized the counter for likes on the post. Whenever a new like comes in, the count is increased in the database. Therefore, each read of the count will just be a simple “select” which is a lot more efficient.</p>
    
    <p>There is also an added benefit of denormalizing counters in the same
    database where the liker to the post is stored. Both updates can be
    included in one transaction, making the updates atomic and consistent
    all the time. Whereas before the change, the counter in cache could be
    inconsistent with what was stored in the database due to timeout,
    retries etc.</p>
  </blockquote>
  
  <p>I tried to update the counter table and a normal table which had the user who liked the post in a batch using,</p>
  
  <pre><code>BEGIN BATCH 
    UPDATE postlike_counter_counter
      set likecount = likecount+1 
      where postid = c77b9e44-379b-11e7-93dc-dd4982fae088;
    INSERT INTO postlikes (postid, likedtime, likedby) values(c77b9e44-379b-11e7-93dc-dd4982fae088, unixTimestampOf(now()), 
      {"firstname": 'fname', "lastname": 'lname', "profileimgurl":'img/pic'});
  APPLY BATCH;
  </code></pre>
  
  <p>I see the error, <strong><em>Counter mutations are only allowed in COUNTER batches</em></strong>
  If i make it as a counter batch, i get, <strong><em>Only counter mutations are allowed in COUNTER batches</em></strong></p>
  
  <p>Is there any way I can make this work? If not, what exactly did the article mean when they wrote the above quoted lines?</p>