DynamoDB with daily/weekly/monthly aggregated values

Viewed 579

My application is creating a log file every 10min, which I want to store in DynamoDB in an aggregated way, e.g. 144 log files per day, 1008 log files per week or ~4400 log files per month. I have different partition keys, but for sake of simplicity I have used only a single partition key in the following examples.

The straight forward solution would be to have different tables, e.g.

Table "TenMinLogsDay":

id (=part.key) | date (=sort key) | cntTenMinLogs | data
-------------- | ---------------- | ------------- | -------------------------------
 1             | 2017-04-30       | 144           | some serialized aggregated data
 1             | 2017-05-01       | 144           | some serialized aggregated data
 1             | 2017-05-02       | 144           | some serialized aggregated data
 1             | 2017-05-03       | 144           | some serialized aggregated data

Table "TenMinLogsWeek":

id (=part.key) | date (=sort key) | cntTenMinLogs | data
-------------- | ---------------- | ------------- | -------------------------------
 1             | 2017-05-01       | 1008          | some serialized aggregated data
 1             | 2017-05-08       | 1008          | some serialized aggregated data
 1             | 2017-05-15       | 1008          | some serialized aggregated data

Table "TenMinLogsMonth":

id (=part.key) | date (=sort key) | cntTenMinLogs | data
-------------- | ---------------- | ------------- | -------------------------------
 1             | 2017-05-01       | 4464          | some serialized aggregated data
 1             | 2017-06-01       | 4320          | some serialized aggregated data
 1             | 2017-07-01       | 4464          | some serialized aggregated data

I would prefer however a combined table. Out of the box DynamoDB does not seem to support this. Also, I want to query either the daily OR the weekly OR the monthly aggregated items, thus I don't want to use the filter feature for this.

The following solution would be possible, but seems like a poor hack:

Table "TenMinLogsCombined":

id (=part.key) | date (=sort key) | week (=LSI sort key) | month (=LSI sort key) | cntTenMinLogs | data
-------------- | ---------------- | -------------------- | --------------------- | ------------- | -----
 1             | 2017-04-30       |   (empty)            |   (empty)             | 144           | ...
 1             | 2017-05-01       |   (empty)            |   (empty)             | 144           | ...
 1             | 0017-05-01       | 2017-05-01           |   (empty)             | 1008          | ...
 1             | 1017-05-01       |   (empty)            | 2017-05-01            | 4464          | ...
 1             | 2017-05-02       |   (empty)            |   (empty)             | 144           | ...
 1             | 2017-05-03       |   (empty)            |   (empty)             | 144           | ...

Explanation: By using the year "0017" and "1017" instead of "2017" I can query the date range for, e.g. 2017-05-01 to 2017-05-04 and DynamoDB won't read the items starting with 0017 or 1017 For week or month range queries, such a hack is not required, as empty LSI sort keys are possible.

Does anybody know of a better way to achieve this?

0 Answers
Related