Samuele B.
Samuele B.

Reputation: 658

Create time series in TimeScaleDB from filtered raw data

This is my first time using TimeScaleDB so I don't have a lot of experience with its usage patterns.

Here's the context: I'm building an analytics application that uses TimeScaleDB to generate time series of aggregated data computed from the data of projects in another application.

The basic flow is:

I have the following requirement, which is subject to becoming more complex in the future: the project may belong to a group, and the consumer of the analytics API needs to be able to access the aggregated statistics filtering by group.

In order to implement this, here's what I thought:

This effectively yields a "global" time series, plus one time series per group.

Unfortunately, this doesn't work for more complex requirements, such as AND'ing or OR'ing the groups (e.g. filtering by two groups).

I can't think of anything else other than generating the time series on the fly with each request, which would be pretty taxing performance-wise. Is there a better way?

Upvotes: 0

Views: 68

Answers (1)

jonatasdp
jonatasdp

Reputation: 1412

the raw data isn't the metric that we're interested in seeing change over time--that would be the aggregated statistics, which absolutely need TimescaleDB.

That's the perfect case for Timescaledb. You'll have:

  1. The hypertable with raw data with the chunk time interval of like 1 day, with a retention policy of 1 day or week
  2. A continuous aggregates in the minimal level with the aggregated statistics using a refresh policy every 1 minute.

As far as I understand that what TimescaleDB has for "continuous" part is that that it continuously polls the hypertable and triggers view refresh.

Timescaledb is not based on triggers to refresh or pooling mechanis. The continuous aggregates use a combined mechanism that tracks a watermark from what is missing to process and uses another temp table with "invalidation logs" to track updates in case some data in the past is updated.

Then, remember that continuous aggregates are also hypertables and you can enable compression, retention policies.

Upvotes: 1

Related Questions