
Your product manager just dropped a new requirement: a real-time analytics dashboard for user engagement metrics, directly in the application. The dataset is currently 500GB of event logs in Parquet files on S3 and is growing by 10GB daily. The C-suite wants sub-second query latency on interactive charts. Your team is now at a critical architectural crossroads. Do you reach for DuckDB, the lightning-fast in-process engine promising zero-copy reads on your Parquet data? Or do you deploy ClickHouse, the distributed columnar powerhouse built for high-throughput ingestion and massive scale? This isn't just a choice between two tools; it's a fundamental decision between two distinct philosophies of data processing: embedded, single-node parallelism versus distributed, real-time persistence. Choosing incorrectly can lead to spiraling operational costs, missed latency targets, and a painful re-architecture down the line.
At a surface level, both ClickHouse and DuckDB are columnar, vectorized analytical databases. They both use Single Instruction, Multiple Data (SIMD) instructions to process data in batches, avoiding the row-by-row overhead that cripples traditional OLTP databases in analytical workloads. But this is where the similarities end. Their design goals, execution models, and storage engines are fundamentally different, optimized for entirely separate corners of the data engineering universe.
DuckDB: The SQLite for Analytics
DuckDB is an in-process OLAP database. It's not a server you connect to; it's a library (libduckdb) you link against your application. There's no separate process to manage, no network overhead for local queries, and no complex configuration. Its primary design goals are:
pip install duckdb is all you need.This makes DuckDB a titan in interactive data analysis (the replacement for Pandas' slower operations), embedded application analytics (powering a dashboard within a Node.js or Python app), and efficient ETL/data transformation tasks on a single node.
ClickHouse: The Distributed Real-Time OLAP Engine ClickHouse is a full-fledged, distributed database management system (DBMS) that runs as a separate server process. It was built at Yandex to power their real-time web analytics platform, a use case that demands:
ClickHouse is the weapon of choice for large-scale log analytics, real-time business intelligence, user-facing analytical dashboards, and any scenario involving terabyte-to-petabyte scale datasets with high concurrency requirements.
The most profound difference lies in how they store data on disk.
ClickHouse's power comes from its MergeTree family of storage engines. This isn't your standard B-Tree. It's a variation of a Log-Structured Merge-Tree, optimized for columnar data and bulk inserts.
When you insert data, ClickHouse writes it into a new "data part" on disk - an immutable set of columnar files. A background process continuously merges these small parts into larger, more optimized ones.
The magic is the sparse primary index. When you define a table, you specify an ORDER BY clause. This is not just for sorting results; it is the physical sort key for your data on disk.
CREATE TABLE user_events (
`event_time` DateTime,
`user_id` UInt64,
`event_type` String,
`payload` Map(String, String)
) ENGINE = MergeTree()
PARTITION BY toYYYYMM(event_time)
ORDER BY (user_id, event_time);
Here, data is physically sorted by user_id, then event_time. ClickHouse creates a sparse primary index on this key. It doesn't index every row; instead, it records the key value for the start of every Nth block of data (a "granule," typically 8,192 rows).
When you run a query like WHERE user_id = 123, ClickHouse does a binary search on the small primary index file to find the few granules that could contain this user_id. It then reads only those granules from disk, skipping terabytes of irrelevant data. This is why ClickHouse is unbelievably fast for queries that filter on its sort key, especially time-series data.
DuckDB's native storage format consists of columnar data blocks. For each column, it stores a set of blocks on disk. The key innovation is its use of Zone Maps for each block. A zone map is lightweight metadata that stores the minimum and maximum value for that data chunk.
When a query contains a predicate like WHERE column_a > 100, DuckDB first checks the zone maps. If a block's zone map indicates its maximum value is 99, the entire block is skipped without ever being read from disk. This is a form of predicate pushdown.
Furthermore, DuckDB builds adaptive Radix Tree (ART) indexes on primary keys or for internal join operations, providing fast point lookups.
But DuckDB's killer feature is its ability to apply these same principles directly to external data formats. When you run SELECT COUNT(*) FROM 'data.parquet' WHERE ..., DuckDB doesn't naively scan the file. It leverages the internal metadata within the Parquet file itself - specifically, the row group statistics (which are essentially zone maps) - to skip massive sections of the file. This makes ad-hoc analysis on existing data lakes incredibly fast.
Both engines are vectorized, but they parallelize execution very differently on a single machine.
ClickHouse uses a traditional pull-based vectorized model, heavily influenced by the Volcano/MonetDB paradigm. Each query is transformed into a pipeline of operators (e.g., Scan -> Filter -> Aggregate). During execution, the top-level operator requests a block of data from its child, which in turn requests from its child, and so on.
Parallelism is achieved by duplicating this pipeline for multiple worker threads. The data source is split, and each thread works on its own segment of the data, processing full blocks at each stage. This is highly efficient for simple, straight-line queries but can introduce synchronization overhead and load imbalance in more complex plans with joins and high-cardinality aggregations.
DuckDB implements a more modern and flexible model called "Morsel-Driven Parallelism."
This approach provides significant advantages on a single node:
This is a key reason why DuckDB often outperforms other engines on complex TPC-H queries on a single powerful machine.
Query Execution Model Comparison
Talk is cheap. Let's benchmark these engines on a common analytical workload. We use a TPC-H dataset at Scale Factor 100 (~100GB of raw data) on an AWS m6i.8xlarge instance (32 vCPU, 128 GiB RAM, NVMe storage).
The Queries:
SUM, AVG, COUNT operations and a GROUP BY. Tests raw aggregation and scanning speed.WHERE clause. Tests pure scan speed and predicate pushdown.Here, we query the 100GB of TPC-H data stored as Parquet files directly from disk. ClickHouse uses its s3 table function, while DuckDB queries the files natively.
# DuckDB Direct Parquet Query
import duckdb
con = duckdb.connect()
# For multi-file datasets
con.execute("SET a_fancy_option=42;")
result = con.execute("""
SELECT
l_returnflag,
l_linestatus,
SUM(l_quantity) AS sum_qty,
SUM(l_extendedprice) AS sum_base_price,
SUM(l_extendedprice * (1 - l_discount)) AS sum_disc_price,
SUM(l_extendedprice * (1 - l_discount) * (1 + l_tax)) AS sum_charge,
AVG(l_quantity) AS avg_qty,
AVG(l_extendedprice) AS avg_price,
AVG(l_discount) AS avg_disc,
COUNT(*) AS count_order
FROM 'lineitem.parquet'
GROUP BY l_returnflag, l_linestatus
ORDER BY l_returnflag, l_linestatus;
""").fetchall()
-- ClickHouse S3 Table Function Query
SELECT
l_returnflag,
l_linestatus,
... -- same aggregations as above
FROM s3('https://my-bucket.s3.amazonaws.com/tpc-h-100/lineitem.parquet', 'Parquet')
GROUP BY l_returnflag, l_linestatus
ORDER BY l_returnflag, l_linestatus;
| Engine | TPC-H Q1 (s) | TPC-H Q6 (s) | Notes |
|---|---|---|---|
| DuckDB 0.10.0 | 2.98s | 0.51s | Reads Parquet metadata to prune row groups. Exceptional performance. |
| ClickHouse 23.8 | 12.45s | 2.89s | Higher overhead for remote object reads. Not its primary use case. |
Analysis: DuckDB is the undisputed champion of ad-hoc queries on Parquet files. Its deep integration with the Parquet format, allowing it to push down predicates and skip entire row groups based on file metadata, gives it a massive edge. ClickHouse's s3 function is powerful but is treated more like a foreign data wrapper; it can't match the native performance of DuckDB in this scenario.
Now, we first ingest the data into each database's native format. This is how you would use these systems in a production application where data is persistently managed.
MergeTree table, ORDER BY (l_shipdate).CREATE TABLE lineitem AS SELECT * FROM 'lineitem.parquet'.| Operation | DuckDB 0.10.0 | ClickHouse 23.8 | Notes |
|---|---|---|---|
| Ingestion Time (100GB) | 78s | 45s | ClickHouse's MergeTree is optimized for high-throughput writes. |
| TPC-H Q1 (Native) | 2.15s | 3.80s | DuckDB's morsel-driven parallelism shines on this complex agg. |
| TPC-H Q6 (Native) | 0.45s | 0.18s | ClickHouse sparse index prunes 95% of granules. Blazingly fast. |
Analysis: The results are now far more nuanced.
MergeTree structure is purpose-built for absorbing high-velocity streams of data, and it easily wins the ingestion benchmark.l_shipdate, the Q6 query (WHERE l_shipdate >= '1994-01-01' AND l_shipdate < '1995-01-01') can use the sparse primary index to locate and scan only the relevant data parts and granules. It reads a fraction of the data from disk, resulting in a sub-200ms query time on a 100GB dataset. DuckDB, while still fast due to zone maps, must scan more data.This test is more conceptual. We simulate 100 concurrent clients running a simple aggregation query (SELECT COUNT(*) FROM lineitem WHERE <random_filter>).
This is not a competition where one engine is "better." They are specialists designed for different tasks on the data processing spectrum.
Choose DuckDB when:
# A typical DuckDB use case: data wrangling in Python
import duckdb
import pandas as pd
# Zero-copy read from Pandas DataFrame
df = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]})
con = duckdb.connect()
# Query the DataFrame directly using SQL
result_df = con.execute("""
SELECT a, b * 2 AS b_doubled
FROM df
WHERE a > 1
""").fetch_df()
print(result_df)
# Or perform a complex aggregation on a massive Parquet file
# that would crash Pandas
con.execute("SELECT COUNT(DISTINCT user_id) FROM 'events.parquet'")
Choose ClickHouse when:
-- A typical ClickHouse use case: real-time analytics table
-- DDL for a table to store website page views
CREATE TABLE page_views (
`view_time` DateTime,
`url` String,
`user_id` String,
`device_type` LowCardinality(String), -- Special optimization for few distinct values
`response_ms` UInt16
)
ENGINE = MergeTree()
PARTITION BY toYYYYMM(view_time)
ORDER BY (device_type, url, view_time); -- Sort key for fast filtering
-- Example Query for a dashboard: Get 95th percentile response time by device
SELECT
device_type,
quantile(0.95)(response_ms) AS p95_response
FROM page_views
WHERE view_time >= now() - INTERVAL 1 DAY
GROUP BY device_type;
The rise of both ClickHouse and DuckDB signals a paradigm shift in data analytics. The one-size-fits-all database is dead. We are now in an era of specialized tools, and knowing the architectural trade-offs is critical for any senior engineer.
The intelligent data engineer doesn't see them as competitors. They see them as two essential, complementary tools in a modern data stack. You might use DuckDB in your dbt transformation pipeline to process Parquet files on S3, and then load the final, cleaned-up data models into ClickHouse to power your company's fastest and most critical dashboards.
Related Technical Reading:
Your team needs to build a real-time analytics dashboard for user engagement metrics. The dataset is currently 500GB of event logs in Parquet files on S3, growing by 10GB daily. The C-suite demands sub-second query latency on interactive charts. Given these requirements, which database technology is the most appropriate choice for this scenario, and why?
Clean AI CLI logs, build cron expressions, decode JWTs, and calculate chmod permissions offline.

Building real-time event analytics with ClickHouse Materialized Views and ReplacingMergeTree: deduplication patterns and sub-second aggregation queries.
Read more
Real-time analytics benchmark comparing ClickHouse vs Snowflake: P95 query latencies, compression ratios, compute costs, and when to migrate from cloud warehouses.
Read more
Building sub-second interactive analytics dashboards with DuckDB-Wasm and Apache Arrow: streaming Parquet datasets entirely in the client browser.
Read more