Time Series Feature Design: Querying Over Large Data Sets
Join the DZone community and get the full member experience.Join For Free
what happens when you want to do an aggregation query over very large data set? let us say that you have 1 million data points within the range you want to query, and you want to get a rollup of all the data in the range of a week.
as it turns out, there is a relatively simple solution for optimizing this and maintaining a relatively constant query speed, regardless of the actual data set size.
time series data has the great benefit of being easily aggregated. most often, the data looks like this:
the catch is that you have a lot of it.
the set of aggregation that you can do over the data is also relatively simple. you have mean, max, min, std deviation, etc.
the time ranges are also pretty fixed, and the nice thing about time series data is that the bigger the range you want to go over, the bigger your rollup window is. in other words, if you want to look at things over a week, you would probably use a day or hour rollup. if you want to see things over a month, you will use a week or a day, over a year, you’ll use a week or a month, etc.
let us assume that the cost of aggregation is 10,000 operations per second (just some number i pulled because it is round and nice to work with, real number is likely several orders of magnitude higher). so if we have to run this over a set that is 1 million data points in size, with the data being entered on per minute basis. with 1 million data points, we are going to wait almost two minutes for the reply. but there is really no need to actually check all those data points manually.
what we can do is actually prepare, ahead of time, the rollups on an hourly basis. that gives us a summary on a per hour basis of just over 16 thousand data points, and will result in a query that runs in under 2 seconds. if we also do a daily rollup, we move from having a million data points to less than a thousand.
actually maintaining those computed rollups would probably be a bit complex, but it won’t be any more complex than how we are computing map/reduce indexes in ravendb (this is a private, and simplified, case of map/reduce). and the result would be instant query times, even on very large data sets.
Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.