rehanvdm / serverless-website-analytics

A CDK construct that consists of a serverless backend, frontend and client side code to track website analytics
GNU General Public License v2.0
162 stars 11 forks source link

feat: add cron that vacuums data #1 #43

Closed rehanvdm closed 10 months ago

rehanvdm commented 10 months ago

The lambda function runs at 1 hour past midnight UTC. At this point, the Firehose is done writing for the previous day and no new data will be written. The function is idempotent and will delete the raw files after doing the rollup only if it is successful.

During the test, it does an incredible job at rolling up.

BEFORE: S3 Objects (388) Input rows: 650 Input bytes: 181.34 KB Output rows: 148 Output bytes: 37.37 KB

AFTER: S3 Objects (4) Input rows: 148 Input bytes: 33.73 KB Output rows: 148 Output bytes: 37.26 KB

The important part is the almost 100x reduction in S3 file count. This will decrease the amount of files that Athena has to scan by magnitudes, which means big savings to gain from this rollup.