RETURN TO INSIGHTS JOURNAL
INS-07 // DATA ANALYTICS13 MIN READ2026-08-03

Engineering Sub-Second Analytics Across 100 Million Events with ClickHouse, Kafka, and dbt

How XIYOR built a real-time telemetry pipeline capable of ingesting 50,000 events per second while maintaining instantaneous sub-second query performance for executive dashboards.

AUTHOR: DATA INFRASTRUCTURE POD // XIYOR
#ClickHouse#Apache Kafka#dbt#Real-Time Analytics#SQL#Big Data

01 // THE DEATH OF TRADITIONAL RELATIONAL ANALYTICS AT SCALE

Relational databases like PostgreSQL and MySQL are marvels of software engineering for Transactional Processing (OLTP). They excel at point lookups, ACID-compliant row updates, and enforcing foreign key relationships. However, when an enterprise system scales past 10 million telemetry events—tracking user page clicks, IoT device sensor readings, API latency metrics, or financial tick data—traditional OLTP databases hit a performance wall. Running an aggregate query like `SELECT AVG(response_time) FROM telemetry WHERE created_at >= NOW() - INTERVAL '30 days'` requires scanning millions of row records off disk, resulting in 15-40 second query delays, CPU spike lockups, and degraded application performance for end users. At XIYOR, we separate OLTP from Online Analytical Processing (OLAP) completely. By leveraging ClickHouse—an open-source column-oriented DBMS engineered specifically for high-volume analytics—we achieve sub-50ms query responses across billions of rows using fraction of the hardware cost of legacy enterprise data warehouses.
"Row-oriented databases store data line by line. Columnar databases store data column by column. When computing metrics across billions of events, columnar reads are up to 100x faster."

02 // THE HIGH-THROUGHPUT TELEMETRY INGESTION TOPOLOGY

To handle 50,000+ incoming telemetry events per second without dropping packets or blocking client HTTP connections, XIYOR deploys a decoupled, streaming ingestion pipeline: 1. Edge Collector Nodes (Next.js / Node.js): Capture incoming client events and push lightweight JSON payloads asynchronously to an Apache Kafka topic. 2. Apache Kafka Buffer: Acts as an elastic buffer queue, decoupling incoming traffic spikes from storage database engines. 3. ClickHouse Kafka Engine: Connects directly to Kafka topics, consuming event streams in batches and persisting data straight into ClickHouse MergeTree tables without custom consumer code. 4. dbt Transformation Layer: Executes materialized rollups, data transformations, and data quality assertions on a scheduled cadence.
ClickHouse Kafka Ingestion Engine & ReplacingMergeTree Schema Setupsql
-- 1. Raw Kafka Streaming Engine Table
CREATE TABLE default.kafka_telemetry_stream (
    event_id UUID,
    tenant_id UUID,
    event_type String,
    duration_ms UInt32,
    timestamp DateTime64(3, 'UTC')
) ENGINE = Kafka
SETTINGS kafka_broker_list = 'kafka-cluster:9092',
         kafka_topic_list = 'telemetry_raw',
         kafka_group_name = 'clickhouse_telemetry_consumer',
         kafka_format = 'JSONEachRow';

-- 2. Target Columnar MergeTree Table Optimized for Aggregations
CREATE TABLE default.telemetry_events (
    tenant_id UUID,
    event_type LowCardinality(String),
    event_id UUID,
    duration_ms UInt32,
    timestamp DateTime64(3, 'UTC'),
    date Date DEFAULT toDate(timestamp)
) ENGINE = MergeTree()
PARTITION BY toYYYYMM(date)
ORDER BY (tenant_id, event_type, timestamp, event_id);

-- 3. Materialized View Bridging Kafka Stream into Columnar Storage
CREATE MATERIALIZED VIEW default.mv_kafka_telemetry TO default.telemetry_events AS
SELECT tenant_id, event_type, event_id, duration_ms, timestamp, toDate(timestamp) as date
FROM default.kafka_telemetry_stream;
  • LowCardinality Optimization: Storing repetitive string values (e.g. event types) as integer dictionaries reduces memory usage by over 80%.
  • Primary Key Sorting: Sorting by (tenant_id, event_type, timestamp) allows ClickHouse to perform binary search lookups skipping 99% of unneeded disk blocks.
  • Zero Consumer Overhead: ClickHouse native Kafka engine consumes directly inside database C++ threads, eliminating custom consumer microservices.

03 // REAL-TIME AGGREGATION VIA MATERIALIZED VIEWS

In traditional data stacks, aggregate dashboards rely on heavy nightly ETL batch jobs. By the time executives review their morning performance reports, the data is already 24 hours stale. ClickHouse eliminates stale reporting through Incremental Materialized Views. As raw event logs stream into the database, ClickHouse updates aggregate statistical summaries (sums, counts, quantiles) in real time on disk. For example, computing P95 and P99 latency distributions across 50,000,000 API requests executes in just 14 milliseconds using ClickHouse aggregate state functions:
"Querying 50,000,000 rows in 14ms is not magic—it is the direct outcome of column-level compression and hardware-level SIMD vector instructions."
Sub-20ms Real-Time P95/P99 Percentile Query Across 50M Eventssql
SELECT
    tenant_id,
    event_type,
    count() AS total_events,
    quantile(0.50)(duration_ms) AS p50_latency,
    quantile(0.95)(duration_ms) AS p95_latency,
    quantile(0.99)(duration_ms) AS p99_latency
FROM default.telemetry_events
WHERE tenant_id = 'a3b8c1d2-4e5f-6a7b-8c9d-0e1f2a3b4c5d'
  AND timestamp >= NOW() - INTERVAL 7 DAY
GROUP BY tenant_id, event_type
ORDER BY total_events DESC;

04 // BENCHMARKS & COST REDUCTION vs CLOUD WAREHOUSES

When migrating an enterprise client from a popular cloud data warehouse (Snowflake / BigQuery) to a self-hosted or managed ClickHouse cluster, XIYOR achieved the following performance metrics: 1. Query Latency Improvement: Average dashboard load times dropped from 4.2 seconds to 85 milliseconds (a 49x speedup). 2. Infrastructure Cost Reduction: Monthly cloud warehouse expenditure decreased from $14,500/month to $1,800/month (an 87.5% reduction). 3. Data Freshness: Reduced latency from 1-hour batch delays to true real-time availability (<500ms end-to-end ingestion lag).

05 // ENGINEERING SUMMARY FOR CHIEF DATA OFFICERS

If your product requires high-frequency event analytics, live user activity tracking, or real-time business intelligence dashboards, adopt these sovereign principles: - Stop querying production transactional databases for analytics. Decouple reporting workloads to a columnar engine immediately. - Buffer high-volume write traffic using Apache Kafka or AWS Kinesis before persisting to database storage. - Leverage ClickHouse Materialized Views to compute complex statistical aggregations at write-time rather than query-time.