title: Aggregating data in DynamoDB that fits our access pattern
body: <p>I am currently trying to aggregate accelerometer data as it is loaded to our dynamo table. I would like to aggregate in 5 minute time windows on a per-user basis and insert the aggregation result into another dynamo table. Because I am not super well versed in Dynamo or Lambda, I am hoping someone can steer me in a different direction if I'm overlooking better solutions.</p>
  
  <p>I am thinking the best way to do this would be to leverage DynamoDB Streams and have a Lambda that works on the data, aggregating it as it comes in so we don't have to query the DynamoDB table across every user every 5 minutes. The latter certainly keeps the Lambda simpler, but I assume that will take a substantial chunk out of our read capacity and will also cause Lambda execution times to be longer. </p>
  
  <p>So, my idea is to process the stream inside a lambda that is triggered every 1000 records, and have it upsert a record in the new table on a per user basis for each 5 minute time window throughout the day, starting with midnight as time 0. The record will be inserted if none exists for the user for that time window. If a record does exist, it will conditionally update the aggregation.</p>
  
  <p>The table will consist of a user id which is the partition key, in the format &lt;\company id>|&lt;\user id>, a window start time (&lt;\date> 00:00, 00:05, 00:10, etc) which will be the sort key, a sum of the data i'm aggregating, and a count of the number of records used to calculate that sum, and an average.</p>
  
  <p>With this structure, I believe can then pull data out on a per user basis for a particular company over a time range that I specify in my query. </p>
  
  <p>Does this seem like a proper way of solving data aggregations with Dynamo? Is there anything I need to look out for both from a lambda perspective or a streams perspective that could cause scalability issues or query issues based on the structure I have outlined above?</p>
  
  <p>Thanks!</p>