title: Cassandra: how to model time series of sensor data?
body: <p>I need to store sensor readings in cassandra (version 2!).
  There are n sensors, of which each can send up to m different values which have different types (e.g. Float, Bool, String). The values have to be stored in cassandra. Later, values will be queried mostly by time ranges. So a query could be "give me all readings from 2016-05-01 09:00 to 2016-05-15 13:00". There could be filters by sensor ID/type, but the main query will always be the time. (So a query could be "Give me all data for sensor 1 and 5 from 2016-05-05" but most likely not "give me all data for sensor 1 and 5").</p>
  
  <p>For more detailed queries, it is ok if all the data (restricted by time and possibly sensor ID) has to be scanned. So for the query "give me all sensor data for sensor 5 from 2016-05-05 where the float value of a reading is greater than 1000" it's OK if cassandra has to scan all the values of sensor 5 from 2016-05-05!</p>
  
  <p>I read a lot of blog posts/questions about data modelling, (e.g. <a href="https://stackoverflow.com/questions/26009975/cassandra-time-series-data-modelling">[1]</a> <a href="https://stackoverflow.com/questions/36480280/using-cassandra-for-time-series-data-storage">[2]</a> <a href="https://stackoverflow.com/questions/36048660/cassandra-partition-key-for-time-series-data">[3]</a> <a href="https://academy.datastax.com/resources/getting-started-time-series-data-modeling" rel="nofollow">[4]</a> <a href="http://www.datastax.com/dev/blog/advanced-time-series-with-cassandra" rel="nofollow">[5]</a> <a href="https://stackoverflow.com/questions/27942152/only-date-range-scanning-cassandra-cql-timestamp">[6]</a> ) but some stuff is years old and I am not sure, if it is still the right way to do it. </p>
  
  <p>My main questions are:</p>
  
  <ul>
  <li>What data type do I use for the timestamp (needs millisecond resolution) </li>
  <li>How do I define the keys? (e.g. do I need an hourly primary key like some examples use? If yes, can I combine results for more than one hour in cassandra or do I need to do that manually?)</li>
  <li>how do I add the sensorID so it can also be efficiently queried</li>
  </ul>
  
  <p>The sensor data will always be inserted ordered, so no previous data is changed and no data with a timestamp lower than the current maximum will ever be added.</p>