Improving Byteful Analytics: Bringing ClickHouse Into Our Stack

Observability is one of the things we pride ourselves on at Byteful, and it's long been appreciated in our reviews [Proxyway Byteful review]. However, as we've scaled, the analytics behind our Overview page began to struggle for our largest customers
We’ve now moved those analytics onto ClickHouse, a database designed for exactly this kind of workload. A query that took over a minute for our largest customer now takes a second!
If you just want a brief overview of why we took some of the load off of TimescaleDB:
Row stores excel at picking out individual records. Column stores are effective at operations across many records. Our live activity page does the former and our Overview page does the latter; each now runs on the database that fits it best.
The rest of this blog covers how databases read data, why TimescaleDB suited one of our workloads but not the other, and what ClickHouse does differently.
Our analytics and the issue
Our dashboard serves two kinds of analytics: the Live Activity panel and the Observability Overview page. The Live Activity panel shows your individual requests with every field attached, and lets you filter by those fields. The Overview page is built from aggregations; charts and breakdowns group a few fields across every request in the selected range alongside any additional filters chosen. Both read the same traffic, yet they represent it differently.
The Overview page was never built directly on raw logs. For our largest customers, that would have meant aggregating hundreds of millions of requests every time the dashboard loaded. Instead, we maintain a summary table. As logs arrive, each one is rolled into a row keyed on customer, target, and time, incrementing counters such as request count and bytes. Charts then read from that summary rather than the raw logs.
For most customers, this worked well and likely would have for a long time; aggregating a few thousand rows is fast on almost any database. But as our largest customers’ traffic grew and diversified, these queries had to scan millions of entries, resulting in extremely poor performance.
To see why, it helps to look at how databases actually read data.
How databases read data?
Before we get to the fix, it helps to take a short detour into database fundamentals. How a database reads data comes down to two things: the workload it was built for and how it lays data out on disk. Both played a part in why our Overview page struggled
OLTP vs OLAP
Most databases are built for one of two things: Online Transaction Processing (OLTP) or Online Analytical Processing (OLAP).
OLTP is the workload most applications are built around: lots of small, concurrent reads and writes, each touching a small handful of records, like fetching a user or updating their settings.
OLAP caters to something quite different. Fewer queries, but each one touches a far larger volume of data and collates it: total requests over the last 30 days, top domains for an account, error rate by network. These queries don’t care about a singular record, and they rarely need every column, just a few being grouped or summed over many records.
| Aspect | OLTP | OLAP |
|---|---|---|
|
Typical query | Read, write, or modify a few records at a time | Aggregate many records into a summary |
| Rows per query | Few | Millions to billions |
|
Columns per query |
Usually all | Usually a few |
| Writes | Frequent inserts and updates |
Large batched inserts |
| Priority | Correctness and concurrency | Throughput |
Our two analytics pages map quite nicely onto this. Live Activity is OLTP-shaped since we are fetching whole records in a paginated format, while Overview is OLAP-shaped, aggregating a few columns across millions of rows.
Most databases fall into one of these categories because the design choices that make one performant often hurt the other. That largely comes down to how the data is stored on disk.
Row vs Columnar storage
Databases store their data on disk in blocks, with the representation differing depending on the database technology. In PostgreSQL and TimescaleDB, that means an 8KB page; in ClickHouse it’s a compressed block for each column (along with some metadata files).

A row store keeps each row together, so in PostgreSQL a page fills up with complete rows one after another. A column store, unsurprisingly, keeps every value for a single column together; a row only exists as the same offset for each column.
With this, it should start to become clear why each one works nicely for our two workloads. For live activity, a row store often means just reading a single page, so the I/O is minimal.
Aggregating data is the opposite. A query like “Most popular networks over the last 90 days” only needs the network and timestamp columns. One of the tables we use for this has 16 columns, so only paying the I/O cost for two of them is a huge improvement, and that's before accounting for the size of the types being skipped. We use plenty of UUIDs, and with each being 16 bytes and not compressing very well, skipping these can be particularly beneficial.
Column stores get some more advantages from this layout. The first is sorting. Data is kept ordered by a key, for example, customer then timestamp; meaning a query for a single customer over the past week can go straight to the blocks covering that range and skip the rest. The second is compression. Each block holds values of a single type, often repeating: network types, status codes, the same targets millions of times over. This compresses far better than a page of mixed types ever could, reducing the bytes read per query even further.
However, a major trade-off is writing. Inserting a row into a row store means adding it to a single page, while in a column store it means adding a value to a block for every column, which is why column stores prefer writes in large batches. Modifying existing data is even worse because that data is sorted and compressed - changing a single value means rewriting the blocks that hold it.
TimescaleDB and its limits for us
TimescaleDB is an extension to PostgreSQL, everything we covered about row stores applies to it. It adds features for time-series data, the most important being a form of columnar storage for older data. This puts it in the unusual position of being a hybrid of OLTP and OLAP. For many time-series workloads, including our live activity page, that’s an enticing proposition.
The foundation is the hypertable.
It looks like a regular table, but underneath it are many smaller tables, automatically partitioned by time into chunks that each cover a fixed interval. A query that filters on time can skip chunks outside its range entirely, and old data can be dropped a whole chunk at a time rather than deleted row by row.
Older chunks can also be compressed into a columnar format. Rows are grouped into batches of up to 1000, and within each batch, every column is stored as its own compressed array. For historical data this brings many of the benefits of a column store all within Postgres.
However, it isn’t true columnar storage like ClickHouse. The compressed batches are still just stored as rows in an internal Postgres table, so the columnar format sits on top of a row store rather than replacing it. For most queries, batches are decompressed back into rows and handed to Postgres’ executor, which was never designed to scan hundreds of millions of values. (Newer versions of TimescaleDB can run some vectorized operations directly on compressed batches).
While this worked on our summary table for a while, the design ran into two problems: what the reads scanned, and how the writes behaved.
Most reads need data from the hot chunk. Compression is only applied to a chunk once it stops receiving writes, so any new data always stays in row format, and the solution isn't as simple as making chunks smaller.
Chunk size is a trade-off where they must be large enough that they compress well, but not so large that the data stays uncompressed for too long. Because our pages often show the most recent data, these queries would almost always include this hot chunk, slowing the dashboard significantly.
The second problem was writing. With our network handling over a billion logs a day, that could translate to over 10,000 logs a second needing to be stored, most of them incrementing counters on the same recent rows over and over. Postgres never updates a row in place; each one writes a new copy of the row and leaves the old one behind for a vacuum to clean up later. Postgres has an optimization that avoids much of this cost through Heap-Only Tuples (HOT) updates.
Unfortunately, due to our indexes, this optimization did not apply to us, and our indexes became slower and slower. These two problems compounded. A bloated table meant more pages to read for the same data, so every write made every read slower.
Bringing ClickHouse into the fold
ClickHouse is a column store built especially for analytical queries. Its speed comes from many architectural choices: compressed columnar storage, a query engine that processes in vectorized batches across the hardware available, and finally the MergeTree. Those first choices make the large scans in queries fast
A MergeTree is a family of table engines that decides how data is written, sorted, and merged on disk. Every insert into a MergeTree table is written as a new part: an immutable set of the per-column compressed blocks we mentioned earlier, sorted by the table’s sort key. Parts are never modified once written.
Instead, ClickHouse merges them in the background into progressively larger parts. Because every part is columnar even when initially written to the database, fresh data gets the same benefits as old data, with no hot chunk waiting to be converted.
However, since every insert creates a part - whether it holds 1 entry or 10000 - we should batch them as much as we can without drastically impacting latency.
The sort key also impacts the index. Rather than indexing every row, ClickHouse instead keeps a single index entry per group of rows, called a granule. That sparse index is small enough to stay in memory, and it lets a query quickly identify which granules could contain rows that fit our query and skip the rest.
For a more in-depth explanation, I can only refer you to the documentation and blogs from the creators of ClickHouse, which cover all details, including how to best take advantage of these features depending on your use case: the MergeTree table engine docs and their practical introduction to sparse primary indexes.
No more updates
Another change which may feel unfamiliar at first is that a primary key in ClickHouse is not a uniqueness constraint. Insert two rows with the same key, and it will happily keep them both. This might sound confusing or even dangerous, but it worked perfectly to fix our writes.
SummingMergeTree is a MergeTree variant that, whenever parts merge, combines rows sharing the same sort key into one and sums their numeric columns. So instead of finding a specific row on a write, adding and rewriting it, every batch of logs is inserted as new rows, and the counting happens later, in bulk, as parts merge. Nothing is read, locked, or rewritten by the writes themselves, and no dead row versions are left to be vacuumed.
What ClickHouse isn’t good at
None of this removes the trade-offs a columnar store makes from earlier. Fetching a single request still means reading a block for every column, a lookup request ID means reading far more than a Postgres index would, and changing existing rows means rewriting entire parts. That’s why our Live Activity page stays on TimescaleDB.
What's next
A faster dashboard is just the visible part of this change, and it's only the start. Alongside the summary table, every raw request log is now written to ClickHouse too. Internally, that means we can run analytics across all of our traffic in near real time, rather than in slow intermittent batches.
Much of this runs on materialized views. In ClickHouse, these aren't periodic, scheduled refreshes; they run as data is inserted, similar to triggers in Postgres, feeding smaller tables. This means keeping track of a metric across our network is just a matter of adding another view.
The first uses are internal signals that keep the network healthy: how often accounts hit our blocklist, how the network is performing. These help us hold ourselves to the compliance standards we set. For now, we review and act on these manually, but as we build these signals and the system matures, we hope to automate more of it to catch abuse faster and keep the network safe.


