title: Storing binary blobs in Cassandra
body: <p>I am building a simple HTTP service, that stores arbitrary binary objects. The service is backed by Cassandra. It is a simplified version of Amazon's S3. The system must withstand a heavy write load and should be highly available on the write and read path. </p>
  
  <p>The stored data is kind of immutable. It can be deleted, but it cannot be updated. Therefore, data inconsistency is not an issue. The datastore must be able to efficiently expire old data.</p>
  
  <p>The service uses Netflix's <a href="https://github.com/Netflix/astyanax" rel="nofollow">Astyanax</a> library, which provides a <a href="https://github.com/Netflix/astyanax/wiki/Chunked-Object-Store" rel="nofollow">recipe</a> for storing (large) binary objects in Cassandra. </p>
  
  <p>I see two solution to tackle the problem, which both have pros and cons. For me it is hard to estimate, which way fits Cassandra better. </p>
  
  <h2>Single table with TTL</h2>
  
  <p>Astyanax automatically chunks large objects into small pieces and stores them into a single table. A TTL is assigned to each blob to expire it after a certain period of time. A compaction run removes blobs, when the TTL is expired.</p>
  
  <p>This solutions works and is pretty straight forward to implement. I started using the <code>SizeTieredCompactionStrategy</code>, but I think, that <code>DateTieredCompactionStrategy</code> might be the better choice, when dealing with TTL data. </p>
  
  <p>My main concern is: can Cassandra's compaction keep up? Has anyone experience with a similar use case? </p>
  
  <h2>Sharding data by time</h2>
  
  <p>Another approach would be to shard the data by time. I could create a table for each day and store the chunks in that table. In this case I can drop the complete table to get rid of the expired data.</p>
  
  <p>This solution requires a little more effort in the implementation, but simplifies and probably speeds up the deletion of expired data. </p>
  
  <p>How performant is Cassandra in dropping a table? </p>