AWS Builder Center

Amazon Timestream handled a year of sensor data queries that were getting slow in a relational table

Time series queries against a growing sensor readings table in PostgreSQL kept getting slower, and moving that specific data to Amazon Timestream fixed the problem without touching the rest of the application.

A table of sensor readings, one row per reading per minute across a few dozen sensors, had grown past a year of data, and queries asking for daily averages over a long time range had gone from instant to uncomfortably slow.


Why time series data behaves differently


 Timestream  is built specifically around the access pattern time series data usually has, recent data queried often and in detail, older data queried rarely and usually in aggregate, with separate storage tiers that match that pattern automatically instead of treating every row the same regardless of age.


Moving just this one table


Rather than migrate the whole application, I moved only the sensor readings table, keeping everything else in PostgreSQL, and pointed the existing ingestion Lambda at Timestream instead, which took an afternoon since the write pattern did not need to change much.


The result


The exact same daily average query that had gotten slow in PostgreSQL came back in a fraction of the time in Timestream, mostly because the aggregation and tiered storage are built around exactly that kind of query. For a single misbehaving table with a genuinely time series access pattern, moving just that piece turned out to be a lot less disruptive than I expected going in.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article