<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by psalsbury on Medium]]></title>
        <description><![CDATA[Stories by psalsbury on Medium]]></description>
        <link>https://medium.com/@p.r.salsbury?source=rss-10e167408c01------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*syvZMsM0HNvn1NvTTjm3mg@2x.jpeg</url>
            <title>Stories by psalsbury on Medium</title>
            <link>https://medium.com/@p.r.salsbury?source=rss-10e167408c01------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 12:18:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@p.r.salsbury/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Visualizing Large Scale Time-series Data With ClickHouse and LTTB]]></title>
            <link>https://medium.com/@p.r.salsbury/visualizing-large-scale-time-series-data-with-clickhouse-and-lttb-88635e100c05?source=rss-10e167408c01------2</link>
            <guid isPermaLink="false">https://medium.com/p/88635e100c05</guid>
            <category><![CDATA[time-series-data]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[clickhouse]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[big-data]]></category>
            <dc:creator><![CDATA[psalsbury]]></dc:creator>
            <pubDate>Thu, 12 Nov 2026 17:23:27 GMT</pubDate>
            <atom:updated>2026-11-13T05:36:33.155Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3KxHYF_y_VSm42pFeeMX8w.png" /></figure><p>Visualizing large scale time-series data is a common challenge in any scenario where viewing it needs to be fast. Although this problem has been solved before in different ways, this article highlights how ClickHouse provides a ready-to-use downsampling algorithm natively, and how it can be used to enhance the performance of time-series visualizations.</p><h4>Slow visualizations</h4><p>Nobody likes a slow visualization. People visit dashboards and signal viewers expecting data to be ready at their fingertips. People want data to be responsive and interactive, allowing them to kick-off their own investigation and explore the data further. But just as people are eager to view the data, they are equally eager to become frustrated with the tool when none of these expectations are met.</p><p>A slow visualization not only delays turnaround time for data-driven decision making, but it also removes motivation for further use. On the contrary, a fast visualization actually encourages users to obtain more value from it, since the overall experience is much more inviting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X4gqRsQjfnFkuAL8QCgjGQ.png" /></figure><p>Fortunately, this undesirable outcome of a slow visualization application can be attributed to two main reasons.</p><h4><strong>Fetching the data is slow</strong></h4><p>Disregarding how optimized or carefully-written a SQL statement for fetching data is, the first instinct for many engineers is to try and query the entire existence of the time-series data. While this provides full granularity of the data, it is the least effective approach if the goal is to maximize visualization speed.</p><p>Consider a telemetry signal with two fields: a value and a timestamp, each stored in 8 bytes. If this signal was logged at 10 Hz for 30 days consistently, we would have 25.92 million data points. This translates into about 415 MB of uncompressed data. Although compression reduces this payload, retrieving the full signal still means moving a substantial amount of data from the database to the visualization application.</p><p>This number will only grow larger as the lifespan of the signal continues, thus making the fetch get slower and slower.</p><h4>Generating the visualization is slow</h4><p>Now that data has eventually arrived into our frontend application, it is up to the software to generate the visualization. From here, engineers have a catalogue of fancy tools they could use to present the data, with each usually having their own advantages and disadvantages.</p><p>But regardless of the tool picked, many applications will still struggle to handle a dataset of +25 million points for a single signal, making it impossible when the desire now becomes plotting a handful of them. Trying to do so only results in slow rendering speed, unresponsive visualizations, and even application crashes because of memory constraints.</p><h4><strong>Questioning the requirements</strong></h4><p>Before us engineers try to tear our hair out — digging into low-level code enhancements or redesigning database tables for further optimizations, it is usually more productive to take a step back and question the underlying requirements:</p><blockquote>Even if we plot +25 million points, is a user even capable of interpreting it all?</blockquote><p>Fortunately, the answer to this question is “no” more times than it is “yes”.</p><p>Any visualization that attempts to plot more than +10 million points will likely find itself doing one of the two things:</p><ol><li>abstracting time-series behavior by introducing additional noise to the visualization</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F9Oh4Ky7B0-h1pW4JnnqBw.png" /><figcaption>Noisy Signal</figcaption></figure><ol><li>including meaningless data points that don’t illustrate any additional changing behavior</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nk-bPMelMHWmayI-_dGGrA.png" /><figcaption>Simple Signal</figcaption></figure><p>With both of these in mind, it becomes easier to realize that:</p><blockquote>not all data points need to get plotted</blockquote><h4>Downsample the data</h4><p>Downsampling the data is the next most effective step in solving slow large scale time-series visualization performance issues. If we can reduce the number of data points that need to get transferred over the network and need to get plotted, we can drastically improve visualization speeds. Especially if we can downsample the data within the database, the previously mentioned network transfer and client-side rendering bottlenecks can be resolved.</p><p>Hence, the motivation for different SQL downsampling approaches suddenly appears. Although there are many different techniques to downsampling signal data, some common universal SQL approaches include:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pP2YpjR6QtXsUn8fJ8VDsQ.png" /><figcaption>Common SQL-Based Downsampling Methods</figcaption></figure><p>But as outlined above, all of these approaches share a common shortcoming: possibly missing data points that may be considered significant.</p><p>This highlights the main challenge for all downsampling algorithms: trying to devise an algorithm that is capable of capturing key signal characteristics and ignoring redundant points without introducing significant additional computational time complexity. After all, there are many sophisticated algorithms that are much more effective than the three mentioned above, but many of them can’t be performed within the database layer or are just too slow.</p><p>Or so we thought…</p><h4>ClickHouse’s native LTTB function</h4><p>Largest Triangle Three Buckets (LTTB) is a popular downsampling algorithm amongst the time-series visualization community. In contrast to the challenges mentioned before, it is capable of preserving significant datapoints while drastically reducing the number of data points — all in O(n) time complexity (assuming input is already sorted).</p><p>At a high-level, the algorithm operates around the idea of triangles. By using data points to generate triangles throughout intervals of the time-series data, LTTB can intelligently determine which points are the most significant based on how large each formulated triangle is.</p><pre>### LTTB pseudocode<br>0. Sort the signal data points<br>1. keep first and last data points<br>2. divide the interior data points into <strong>N-2</strong> buckets<br>3. For each bucket:<br>    Point A: point from <strong>previous</strong> bucket<br>    Point B: a candidate point in the <strong>current</strong> bucket<br>    Point C: average the position of the points in the <strong>next</strong> bucket<br>    - generate a triangle from these three points<br>    - select the point B that forms the largest triangle with point A and C</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L7SPf0FTAqOQRQaiPxC7Vg.png" /><figcaption>LTTB Triangle Generation and Point Evaluation Example</figcaption></figure><p>The larger the triangle is for a bucket, the more-significant that data point is; where the number of triangles/buckets to evaluate is a configurable parameter.</p><p>However, it’s important to recognize that this algorithm requires a stateful, iterative approach, meaning that a typical implementation in SQL would require a considerable amount of complexity and would result in suboptimal performance.</p><p>But if ClickHouse wasn’t already impressive as is for handling large scale time-series data, it takes things one step further by offering its own <a href="https://clickhouse.com/docs/reference/functions/aggregate-functions/largestTriangleThreeBuckets">native implementation</a> of the LTTB algorithm.</p><pre>select <br>  largestTriangleThreeBuckets(n)(x, y) as downsampled_data<br>from <br>  signals_table<br><br>-- n: number of final points<br>-- x: x axis component of time-series<br>-- y: y axis component of time-series<br>-- example result: Array(Tuple(Float64, Float64))</pre><p>This means we can completely offload the downsampling functionality to ClickHouse, reducing the amount of data required to be transported and rendered substantially.</p><p>how awesome?</p><h4>Results</h4><p>All results were obtained using a local containerized ClickHouse v25.8 instance, configured with 2 cores and 6 GB of RAM. The final table contained 100 generated synthetic signals sampled at 10 Hz; each signal consisted of various seasonality behavior, different levels of noise, and random outlier spikes. The number of data points per signal ranged from 1 million to 100 million, with a total number of 5.05 billion records in the final signals table. The table schema used ORDER BY(signal_id, timestamp) and PARTITION BY toDate(timestamp) to maximize efficiency for single-signal time-range queries. Both raw and LTTB queries applied the same filters so the experiment could accurately compare server processing, data transfer, decoding, and rendering costs under the same conditions.</p><p>All queries were performed using a single thread and received a warm-up before each trial without using query caching. Additionally, all final numbers were obtained from the median of five trials per configuration, with execution order rotated.</p><p>Metrics:</p><ul><li>Input points: The number of data points for the raw input signal that is fed into the LTTB algorithm.</li><li>LTTB N: The set number of desired data points to return from the LTTB algorithm; it corresponds to the ‘n’ in ClickHouse’s LTTB algorithm function signature “largestTriangleThreeBuckets(n)(x,y)”</li><li>Compressed payload: The actual gzip-compressed HTTP response body received from ClickHouse, this excludes the HTTP headers and network protocol overhead.</li><li>Fetch time: Includes database execution, response compression and HTTP transfer. Here, transfer delay is minimal since the experiment is conducted within the same host machine.</li><li>Draw time: The time to create and draw the chart using Matplotlib, after the data has been decoded. Includes figure setup and rendering.</li><li>Total time: <strong>Fetch + decode + draw.</strong> Decoding includes in-memory decompression and creation of a NumPy array.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YfpiNl0bLCX3_Trj0lYCYQ.png" /><figcaption>Median Fetch-to-Chart Times</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yPSHiQyYb4rifrbhH04i0w.png" /><figcaption>Table of All Results</figcaption></figure><p>Across the tested configurations, ClickHouse’s LTTB reduced median fetch-to-chart time anywhere from 2.5x to 6.9x. Even for a signal as large as 100M points, selecting 1,000 data points reduced the compressed response from 577.47 MB to less than 10 KB and total visualization time from 17.5 seconds down to only 2.7s.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jpKFx2M7md14xtI6w6ZQNw.png" /><figcaption>LTTB (n=1,000) Results</figcaption></figure><p>Using a point budget of N=1,000 for the LTTB algorithm, the overall shape and its significant points were able to get captured without losing any major fidelity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ADoGeEYqzvnJETF9p5Z5Yg.png" /><figcaption>100M Raw Points Downsampled at Different Levels of N</figcaption></figure><p>Retaining only 100 out of the 100 million point count, 0.0001% of points, the algorithm couldn’t preserve the shape of the signal. However, at 1,000 points or 0.001%, the results became much more promising. At this level much of the visual structure of the signal was retained and 226 of the 232 injected outliers were caught. Increasing N to 10,000 resulted in all 232 outliers being included and resembled minimal variance between the raw and downsampled versions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*alFfh8xHfgsCqVUOHl9MCg.png" /><figcaption>Performance Tradeoff When Increasing Point Budget</figcaption></figure><p>Little variability was observed when increasing the point budget up to 1 million points, or 4% of the raw signal count. Somewhere between 15 and 17.5 million points (60–70% of the raw signal count), using the LTTB algorithm started to demonstrate an increase in total visualization time, surpassing the original 4.74s recorded.</p><h4>Conclusion</h4><p>When it comes to visualizing large-scale time-series data, plotting every single data point is likely hurting visualization performance while providing little additional value. Not all data points need to get included, but at the same time, knowing how to properly handle signal heuristics is required to effectively capture points that are significant. Thankfully, ClickHouse offers the LTTB downsampling algorithm, which has been demonstrated throughout this article to be a powerful tool to help solve this problem conveniently.</p><p>ClickHouse’s native LTTB function was able to showcase how a 100M data point signal can be represented in only 1,000 points with much of its signal structure preserved — demonstrating a significant drop in total visualization time from 17.51 to only 2.73 seconds. At this scale, some applications might not even be capable of even supporting this magnitude of data, but now it can be viewed with respectable performance.</p><p>However, these speedups don’t come for free. The trials also showcased how decreasing the point budget to too low of a threshold can result in significant points being missed, as demonstrated when we set N to be 0.001% of the total points and 6 of the 232 outliers were missed. This means choosing the right number of output points is a knob that can require tuning: too few points can misrepresent the signal while a too many points may preserve more detail, but reduce performance gains.</p><p>ClickHouse is awesome for providing engineers the LTTB algorithm at their fingertips, but just like any tool, it must be used wisely. Trying to apply a generalized minimum point budget to all signals can be a dangerous action, especially if signals have unique characteristics and behavior. Not all data is created equally, but it’s our responsibility as data professionals to tackle this challenge to deliver accurate, timely, and accessible results to better inform data-driven decisions.</p><h4>Additional Takeaways</h4><p>Although the LTTB algorithm is extremely effective and popular amongst the visualization community, it is primarily used for visualization purposes only. It is not recommended to leverage this algorithm as a permanent data transformation because it is lossy; it is only designed to preserve visual fidelity not statistical fidelity. If leveraged within in an interactive visualization application, a common approach is to re-sample the data per zoom level, since the granularity of data is dynamic and typically a function of the time-range/zoom level.</p><p>Additionally, the LTTB algorithm may not always be the optimal downsampling algorithm. While it excels at preserving the overall visual shape of time-series data, alternatives such as Min-Max downsampling may be a better choice when the goal is to retain extreme values. At the end of the day, the best algorithm depends on whether the objective is visualization, anomaly detection, or statistical analysis.</p><p>Lastly, it is worth giving justice to other databases besides ClickHouse that also offer the LTTB algorithm out-of-the-box. Other time-series databases that provide it natively include QuestDB and CrateDB, and other databases like TimescaleDB and DuckDB can offer it using extensions.</p><p>Notebook Link (Github): <a href="https://github.com/patsals/clickhouse-lttb-benchmark/blob/main/notebooks/clickhouse_lttb_demo.ipynb">https://github.com/patsals/clickhouse-lttb-benchmark/blob/main/notebooks/clickhouse_lttb_demo.ipynb</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88635e100c05" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>