DEV Community

Cover image for DuckDB vs Spark SQL in 2026: One Laptop Ran TPC-H 17x Faster Than Spark, and the Three Places Spark Still Wins
AI Explore
AI Explore

Posted on

DuckDB vs Spark SQL in 2026: One Laptop Ran TPC-H 17x Faster Than Spark, and the Three Places Spark Still Wins

DuckDB vs Spark SQL is usually argued from priors. Spark people say DuckDB is a toy that falls over past a laptop; DuckDB people say Spark is a cluster tax on data that would fit in a phone. I wanted the number instead. So I generated TPC-H at scale factors 1 and 10 with DuckDB's own generator, wrote it to plain Parquet, and ran the same 22 queries, byte for byte, through DuckDB 2.0.1 and Apache Spark 4.3.0 on one Apple M4 Max. DuckDB finished the SF10 suite in 2.44 seconds. Spark took 42.08. Every one of the 22 queries returned the same rows on both. Then I spent the second half of this piece on the part the benchmark cannot show: the three workloads where Spark is still the engine to pick, the hard limits of each in their own documentation, and how big your data really is.

22 TPC-H queries at scale factor 10, same Parquet files, one Apple M4 Max: DuckDB 2.0.1 in 2.44 s, Spark 4.3.0 in 42.08 s, 17.2x on the suite and 4.2x to 36.1x per query. 22 of 22 identical answers at SF1 and SF10. Process start to first answer: 0.16 s against 8.36 s. Under a 4 GB memory cap DuckDB spilled and finished the suite in 4.04 s; Spark with a 4 GB driver finished all 22 too, in 53.81 s. 16 CPU cores, 64 GB unified memory; one warm-up then three timed runs a query, median; 26 November 2026.

Two things before the table. First, this is Spark in local mode on one machine, which is not the habitat Spark was designed for and is exactly the habitat most people compare it in: a laptop, a CI runner, a single-node notebook. Spark's own developers filed a design proposal in May 2026 saying that Spark's execution model "introduces noticeable overhead for small datasets (e.g., <100MB), where even simple queries can take multiple seconds", and 4.3.0 ships the first opt-in pieces of a laptop mode in response. I left those at their defaults, as a first-time user would. Second, DuckDB read Parquet through views rather than its native format, which is the slightly slower path for DuckDB and the only fair one, since both engines then scan identical bytes.

The same 22 queries, the same files, one machine

# the whole protocol, both sides read the same Parquet directories
# data: DuckDB's tpch extension -> Parquet, per-thread files, 1,048,576-row row groups
CALL dbgen(sf=10);
COPY lineitem TO 'sf10/lineitem' (FORMAT parquet, PER_THREAD_OUTPUT true, ROW_GROUP_SIZE 1048576);

# DuckDB 2.0.1: defaults, 16 threads, views over the files (not its native format)
con.execute("CREATE VIEW lineitem AS SELECT * FROM read_parquet('sf10/lineitem/*.parquet')")
rows = con.execute(q).fetchall() # 1 warm-up, then 3 timed, median

# Spark 4.3.0: local[*], OpenJDK 27, 32 g driver, AQE and ANSI at their defaults
spark = (SparkSession.builder.master("local[*]").config("spark.driver.memory", "32g").config("spark.sql.shuffle.partitions", "32").getOrCreate())
spark.read.parquet("sf10/lineitem").createOrReplaceTempView("lineitem")
rows = spark.sql(q).collect() # same query text, 1 warm-up, then 3 timed, median
Enter fullscreen mode Exit fullscreen mode

DuckDB's tpch extension carries the 22 reference queries as text. I used that text unchanged on Spark, expecting to patch a few; Spark 4.3's parser took all 22 as written, including substring(... from... for...), interval arithmetic and the extract forms. Each query ran once as a warm-up and then five times at SF1 and three times at SF10, alternating nothing, because the two engines ran in separate processes one after the other with the machine otherwise idle. The number reported is the median, measured from Python around the call that returns the rows.

TPC-H SF10, Parquet DuckDB 2.0.1 Spark 4.3.0 Spark / DuckDB
Q1 pricing summary 0.140 s 4.525 s 32.4x
Q2 minimum cost supplier 0.035 s 0.757 s 21.7x
Q3 shipping priority 0.102 s 1.505 s 14.7x
Q4 order priority 0.068 s 1.140 s 16.8x
Q5 local supplier volume 0.107 s 2.757 s 25.7x
Q6 revenue change 0.052 s 0.221 s 4.2x
Q7 volume shipping 0.108 s 2.374 s 22.0x
Q8 market share 0.135 s 0.824 s 6.1x
Q9 product type profit 0.261 s 2.235 s 8.5x
Q10 returned items 0.124 s 1.603 s 12.9x
Q11 important stock 0.026 s 0.318 s 12.3x
Q12 shipping modes 0.073 s 0.964 s 13.2x
Q13 customer distribution 0.218 s 1.948 s 8.9x
Q14 promotion effect 0.095 s 0.438 s 4.6x
Q15 top supplier 0.065 s 0.940 s 14.5x
Q16 parts/supplier relationship 0.046 s 1.115 s 24.2x
Q17 small-quantity revenue 0.121 s 4.377 s 36.1x
Q18 large volume customer 0.186 s 6.168 s 33.2x
Q19 discounted revenue 0.098 s 0.548 s 5.6x
Q20 potential promotion 0.087 s 0.522 s 6.0x
Q21 suppliers who kept orders waiting 0.255 s 6.020 s 23.6x
Q22 global sales opportunity 0.038 s 0.779 s 20.3x
all 22, sum of medians 2.440 s 42.076 s 17.2x
the same at SF1 (5 timed runs) 0.394 s 5.734 s 14.5x

Apple M4 Max (16 CPU cores, 64 GB unified memory, macOS 27.2). TPC-H generated by DuckDB's tpch extension and written to Parquet; query text from tpch_queries() used verbatim on both engines. DuckDB 2.0.1 at defaults, 16 threads, views over Parquet; Spark 4.3.0 local[] on OpenJDK 27, 32 g driver, 32 shuffle partitions, AQE and ANSI at their defaults. Median of 3 timed runs after 1 warm-up (5 at SF1), wall clock from Python including result collection. Q11 returns no rows at SF10 on both engines because its threshold constant is written for SF1; it is timed anyway.*

Read the right-hand column as a shape rather than a figure. The narrowest gaps, 4.2x on Q6 and 4.6x on Q14, are the queries that scan one table with a filter and almost no join or aggregation state: the work is the Parquet read, and both engines read Parquet reasonably well. The widest, 32x to 36x on Q1, Q17 and Q18, are heavy aggregation and correlated subqueries over lineitem, where Spark pays for a shuffle between map-side and final aggregation and DuckDB does the whole thing in one pipeline on 16 threads. Q21, the four-way self-join with EXISTS and NOT EXISTS, was Spark's slowest query at 6.0 s and DuckDB's second slowest at 0.26 s. The ratio grew from 14.5x at SF1 to 17.2x at SF10, which is the opposite of what the cluster-tax argument predicts; between 6,000,000 and 60,000,000 rows, Spark was not yet amortising anything.

$ python compare.py res_duckdb_sf10.json res_spark_sf10.json
 Q DuckDB s Spark s Spark/Duck rows same?
 1 0.140 4.525 32.4x True (4)
 6 0.052 0.221 4.2x True (1)
 17 0.121 4.377 36.1x True (1)
 18 0.186 6.168 33.2x True (100)
 21 0.255 6.020 23.6x True (100)...
TOTAL 2.440 42.076 17.2x
duckdb ready 0.013 s first answer 0.156 s after process start peak RSS 3,666 MB
spark ready 3.148 s first answer 8.357 s after process start JVM RSS 25,561 MB

$ DUCK_MEM=4GB python run_duckdb.py sf10... # memory_limit='4GB', spill to NVMe
TOTAL median 4.038 s; peak RSS 3,286 MB
$ python run_spark.py sf10... 4g # spark.driver.memory=4g
TOTAL median 53.806 s; JVM RSS 6,585 MB; errors 0

$ # a cold process, one query (Q6 over 60,000,000 rows), three times each
duckdb cold process -> Q6 answer: 0.114 s 0.112 s 0.113 s
spark cold process -> Q6 answer: 4.014 s 4.118 s 3.963 s (session ready at about 2.0 s)
Enter fullscreen mode Exit fullscreen mode

Three numbers from that card deserve a sentence each. Time to the first answer: DuckDB imported, planned and returned Q1 at SF10 in 0.156 s after the Python process started; Spark's session took 3.1 s to come up and its first Q1, cold JIT included, finished at 8.36 s. For a dashboard, a CLI, a test suite or an agent calling a tool, that difference is the product. Memory: DuckDB peaked at 3.7 GB of resident memory for the SF10 run; the Spark JVM sat at 25.6 GB, because I allowed it 32 GB and the JVM keeps what it is given. That is not what Spark needed, it is what it took, and the 4 GB run below says what it needed. Correctness: row counts matched on every query at both scale factors, and the values I spot-checked, the Q1 sums to the cent, Q6 revenue, the Q18 top customer, were identical to the printed digits, with Spark rounding decimals where DuckDB prints more places.

The same machine with 4 GB

A 64 GB laptop is a generous box. The more common box is a 4 GB CI runner or a small container, so I capped both. DuckDB's memory_limit='4GB' turned the SF10 suite into 4.04 s, 1.7x slower than uncapped, with every query still answering: the out-of-core grouping, joining and sorting that DuckDB's performance guide describes did the work from the NVMe. Resident memory peaked at 3.3 GB. Spark, given spark.driver.memory=4g, also finished all 22 queries with no errors, in 53.81 s against 42.08 s uncapped, 1.3x slower, and its JVM settled at 6.6 GB resident instead of 25.6. That is the fairer picture of what Spark needs on this data: a few gigabytes, not thirty. Under the same cap the gap between the engines was 13.3x. A third measurement belongs here because it is the one a developer feels: a fresh process answering a single query, Q6 over 60,000,000 rows, took DuckDB 0.11 s from the first line of Python to the number, and Spark 4.0 s, half of it starting the session. The install behind each is 17 MB of wheel for DuckDB (49 MB unpacked) and, for Spark, a 374 MB JDK plus 489 MB of pyspark.

The guide is worth reading before trusting that on your own hardware: DuckDB recommends "1-4 GB memory per thread", warns that "some aggregate functions, such as string_agg(), do not support offloading to disk", and says a query with several blocking operators "may still throw an out-of-memory exception" despite spilling. Those are the honest edges of a single-node engine. Spark's tuning guide has its own: Java objects "can easily consume a factor of 2-5x more space than the 'raw' data inside their fields", a 10-character string "can easily consume 60 bytes", and garbage collection cost "is proportional to the number of Java objects". Spark runs comfortably on far less memory than it took here, but getting there is configuration work that DuckDB never asks for.

Why the gap is this big

It is not that Spark is badly engineered. It is that the two engines are built around different assumptions about where the data is. DuckDB is a library: it runs inside your process, plans a query into a pipeline of vectorized operators, and runs that pipeline across every core with no serialization, no network and no scheduler between operators. Spark is a distributed runtime: a driver turns the plan into stages, stages into tasks, tasks go to executors, and every aggregation or join that changes the partitioning key is a shuffle that writes to disk and reads back. In a cluster that machinery is the point. On one machine it is overhead on every query, and the adaptive query execution that has been on by default since 3.2 can shrink the shuffles but cannot remove the stage boundaries.

The published record agrees with the shape of my table, at least on a single node. ClickBench, run by ClickHouse on a 16-vCPU instance, has a DuckDB result file whose hot runs sum to 25.35 s and a Spark one summing to 332.37 s over the same 43 queries; two independent practitioners this autumn measured 21x on a 4-core runner and 5x to 12x under a 4.5 GiB cap. The crossover exists too, and it is in the one benchmark run by people who sell distributed computing: Coiled's TPC-H sweep found Spark about 10x behind at small scale and 5x ahead of DuckDB at 10 TB and up, "at a 10x hardware cost difference".

benchmark result who ran it
ClickBench, c6a.4xlarge (16 vCPU, 32 GiB), 43 queries over 99,997,497 rows DuckDB hot runs sum to 25.35 s (12 Nov 2026 result file); Spark hot runs sum to 332.37 s (11 May 2026 file): 13.1x on the sum ClickHouse runs it; the two result files are public JSON and the ratio is my arithmetic on them
TPC-H-like SF10 on a 4-vCPU, 16 GB CI runner DuckDB 2.0.0-dev 21.3 s warm; Spark 4.1.3 454.9 s warm Independent practitioner (datamonkeysite, Sep 2026), mean of 3 runs, single-node JVM
150,000,000-row star schema, 8 vCPU, 4.5 GiB RSS cap DuckDB 2.0.0 0.87 s to 7.92 s per query; PySpark 4.2.0 local[8] 10.77 s to 46.29 s; one Spark run blew through the cap Independent practitioner (dev.to, Oct 2026), medians, code public
TPC-H from 10 GB to 10 TB on m6i instances Spark about 10x behind everyone at small scale; at 10 TB and up, Dask and Spark 5x faster than DuckDB on 10x the hardware Coiled, who sell Dask; the one comparison that shows the crossover
TPC-H SF1000 on a 2012 MacBook Pro versus an M3 Max Geometric mean 218 s versus 12 s; Q18 2,076 s versus 47.6 s DuckDB Labs; the point was that one laptop's capacity grew 18x in a decade

Third-party and vendor numbers, each labelled with who produced it. None is an audited TPC result, including mine.

Where Spark still wins

I count three places, and none of them is "big data" in the vague sense.

One query that needs more than one machine. DuckDB's FAQ says it plainly: "DuckDB is a single-node database system, hence it makes use of vertical scalability." Vertical scalability goes a long way now, further than most people's intuition, which is the point of DuckDB Labs' Lost Decade of Small Data post and their 27 TB TPC-H run in a single file. But when a join needs 2 TB of working memory, or a scan needs 100 disks of bandwidth, Spark can add machines to the query and DuckDB cannot. MotherDuck, DuckDB's own cloud, draws the same line: each query runs on one node, and "if your job needs more memory than a Giga instance provides, distributed execution is the right tool."

Streaming. DuckDB has no streaming engine; 2.0 added triggers, which is a different thing. Spark's Structured Streaming runs micro-batches at about 100 ms with exactly-once guarantees, 4.1 added Real-Time Mode for stateless work at single-digit milliseconds, and 4.3 extended it to streaming aggregation, deduplication and arbitrary state "with end-to-end latency on the order of 100 milliseconds". If events arrive continuously and the answer must update as they do, this is not a comparison.

The platform around a shared lakehouse. Spark reads and writes Iceberg, Delta and Hudi in full, MERGE included, and 4.2 added a SQL CHANGES clause and Auto CDC in Declarative Pipelines. DuckDB's Iceberg extension writes fully only through an attached REST catalog, and its Delta extension can create and append but "does not support UPDATE, DELETE, MERGE INTO". Add hundreds of users and jobs sharing one governed engine, Spark Connect's thin clients, and, on Databricks, Photon's native C++ execution that claims up to 5x price-performance on TPC-DS, and the platform case is real. It is also a case for an organisation, not for a query.

Capabilities, side by side

DuckDB 2.0 Apache Spark 4.3
Execution model In-process library, vectorized, one node; parallel across every core of that node Driver plus executors across a cluster; Standalone, YARN or Kubernetes; one JVM in local mode
Largest comfortable data Terabytes on one box with planning; DuckDB's own SF100,000 TPC-H run is 27 TB in one file on a 192-core machine Petabytes across nodes; the only one of the two that can add machines to a query
When memory runs out Spills grouping, joins, sorts and windows to disk; 1 to 4 GB per thread recommended; some aggregates cannot spill Spills shuffle and sort to local disk; JVM objects cost 2x to 5x their raw size; tuning is on you
Concurrency One writer process, many readers; MVCC inside the process; the Quack protocol in 2.0 serves one database to many clients Many concurrent jobs and users through the cluster manager and Spark Connect; the natural multi-tenant engine
Lakehouse tables Reads Iceberg and Delta; full Iceberg writes through a REST catalog; Delta writes are create and append only; DuckLake is its own format Full read and write on Iceberg, Delta and Hudi, including MERGE; connectors lag the newest Spark by a version or two
Streaming None; batch over files, with triggers added in 2.0 Structured Streaming: micro-batch at about 100 ms, Real-Time Mode with stateful operators at about 100 ms in 4.3
SQL dialect PostgreSQL-flavoured plus friendly extensions: FROM-first, GROUP BY ALL, EXCLUDE, COLUMNS(), PIVOT, ASOF joins, SWITCH ANSI mode by default since 4.0; VARIANT, SQL scripting, recursive CTEs, pipe syntax, ASOF JOIN and JSON_TABLE in 4.3
Languages Python, R, Java, Node, Rust, Go, Swift, C and the browser via Wasm; SQL is the engine Scala, Java, Python, R; SQL plus DataFrame and Dataset APIs; thin clients through Spark Connect
GPU Sirius, a core extension since 2.0.1, on NVIDIA; third-party Metal extensions on Apple silicon RAPIDS Accelerator on NVIDIA; Photon is Databricks-only and not a GPU; a Metal extension exists for Apple silicon
Install and start One 17 MB wheel, 49 MB unpacked; a cold process answered Q6 over 60,000,000 rows in 0.11 s A 374 MB JDK plus 489 MB of pyspark; the same cold Q6 took 4.0 s, 2.0 s of it starting the session
Licence and stewardship MIT; DuckDB Foundation Apache 2.0; Apache Software Foundation

Each cell is from the project's own documentation or release notes, linked in the text and the references. "Comfortable" means documented and demonstrated, not theoretical.

A few cells deserve expansion. DuckDB's concurrency model is one writing process per database, with MVCC inside it, and that is the single most common reason a team outgrows a plain DuckDB file; 2.0's Quack protocol answers it by letting any DuckDB process serve its databases to other clients, and DuckLake answers it differently, by putting the metadata in a real SQL database and the data in Parquet. DuckDB's friendly SQL is not a gimmick once you have used GROUP BY ALL, SELECT * EXCLUDE (id) or COLUMNS('.*_at$') for a week. Spark's 4.x line, in turn, has been shipping real SQL: 4.0 made ANSI mode the default and added VARIANT, 4.1 made SQL scripting and recursive CTEs general, 4.2 added native geometry types, and 4.3 added ASOF JOIN and JSON_TABLE. On the GPU, both engines now have a path: DuckDB 2.0.1 ships Sirius as a core extension for NVIDIA, Spark has had the RAPIDS Accelerator for years, and on Apple silicon there are Metal extensions for DuckDB and, as of last week, for Spark.

the drawbacks
DuckDB No distributed execution: a query runs on one node, full stop. One writer per database file unless you put Quack or DuckLake in front of it. Delta tables cannot be updated or deleted from DuckDB. Checkpointing a multi-terabyte file is slow (about 5 s on SF1000 after a few rows). A query with several blocking operators can still run out of memory despite spilling, and string_agg cannot spill at all. Nothing for streaming. The PySpark-compatible API is bug-fix only and headed for deprecation.
Spark Fixed overhead that small data cannot amortise: Spark's own 2026 design proposal says queries over less than 100 MB can take multiple seconds. JVM memory accounting: objects cost 2x to 5x their raw bytes, a 10-character string about 60 bytes, and garbage collection scales with object count. Shuffle partitions default to 200 regardless of data. Operating a cluster is a job: memory fractions, executor sizing, serializer choice, GC tuning. Table-format connectors trail new Spark releases. Spark Connect ships without built-in authentication. Photon, the fast engine, is not open source.

Quotations and figures from the DuckDB performance guide and FAQ, the Spark tuning guide, the May 2026 Spark design proposal on laptop mode, and the connector release pages, all in the references.

How big is your data, really

The benchmark only matters if your workload looks like it, so here is the fleet evidence. Amazon's own analysis of the Redshift fleet, published at VLDB 2024, found that more than half of queries finish in under 100 ms and the 99th percentile finishes within a minute; MotherDuck's cut of the same Redset data puts 75% of queries under 1 GB scanned and 0.03% over 10 TB. Jordan Tigani's Big Data is Dead, written from inside BigQuery, said the vast majority of customers held under 1 TB and that among paying customers "90% of queries processed under 100 MB". None of those numbers say Spark is wrong. They say that the query Spark was built for is roughly one in a thousand, and the other 999 are paying its fixed cost. Databricks' own guidance on small jobs concedes the mechanism: "the time and the fixed overhead per operation add up."

The market has noticed. PyPI counted 88.9 million DuckDB downloads in the last 30 days against 48.2 million for PySpark; on GitHub the two repositories are within 1,300 stars of each other, 43,392 to 44,637; and DuckDB appeared in 5.7% of database answers in the 2026 Stack Overflow survey, up from 1.4% two years earlier. Downloads are not deployments, and Spark is installed on clusters that never touch PyPI, so read those as direction, not share.

Cost, in one sentence each

A single r7i.16xlarge, 64 vCPUs and 512 GiB, is $4.23 an hour on demand, and DuckDB will use all of it. EMR adds a per-instance surcharge on top of EC2 and bills EMR Serverless at $0.052624 per vCPU-hour plus $0.0057785 per GB-hour, with a one-minute minimum; AWS's own example prices a modest three-node cluster running all month at $1,101.57. The honest comparison is not those two numbers, it is the engineer-hours: a DuckDB job is a file and a Python process, and a Spark job is a cluster, a configuration, a serializer and a tuning guide.

How to pick, and how to use both

Pick DuckDB when the working set of a query fits one machine with room to spill, when latency to first answer matters, when the consumer is a notebook, a service, a test suite, a CLI or an agent, when you want SQL without a JVM, or when the job runs on a laptop or a CI box. That is most analytical queries in most companies, by the fleet numbers above. Pick Spark when one query genuinely needs several machines' memory or bandwidth, when the workload is a stream, when the data lives in Delta or Iceberg tables that many jobs mutate and you need MERGE and CDC, or when your organisation already runs its governed platform on it and the question is "should this one job move", in which case the answer is often no.

And the two are easier to combine than the argument suggests. Spark 4.2 made Arrow the default path from the JVM to Python, so a DataFrame streams into DuckDB without a Pandas copy. DuckDB writes Parquet and Iceberg that Spark reads natively, and DuckLake stores plain Parquet. SQLFrame runs PySpark DataFrame code on DuckDB with no cluster, which is how several teams presented their migrations at DuckCon this year; DuckDB's own experimental Spark API is now bug-fix only and points at SQLFrame. Sail goes the other way, speaking the Spark Connect protocol from a Rust engine, which Spark Connect's plan-based design made possible. The pattern that falls out is the one I would recommend: Spark for the cluster-sized jobs and the streams, DuckDB for everything that fits one box, and a table format both can read in the middle.

What I wanted from this was a number I could stand behind and the context that keeps it honest. The number is 17.2x on 22 queries at 60,000,000 rows, with identical answers, on a machine most engineers already own. The context is that Spark was never trying to win that race, and that it still wins three others. Choosing between them is not a matter of taste. It is a matter of whether your query fits.

FAQ: DuckDB vs Spark SQL

Is DuckDB faster than Spark SQL?

On one machine, by a wide margin. On an Apple M4 Max with 64 GB, DuckDB 2.0.1 ran all 22 TPC-H queries at scale factor 10 in 2.44 seconds and Spark 4.3.0 in local mode took 42.08 seconds, with identical answers, a 17.2x difference on the suite and 4.2x to 36.1x per query. Spark is not built for one machine; its advantage begins when the data no longer fits one.

When should I use Spark instead of DuckDB?

When a single query must span more than one machine, when you need streaming with stateful operators and sub-second latency, when many users and jobs share one governed engine and lakehouse tables with full MERGE support, or when your platform is Databricks and Photon is doing the work. Those are Spark's three real wins: scale-out, streaming, and the multi-tenant platform around it.

How much data can DuckDB handle on one machine?

More than most teams have. DuckDB's own documentation says most databases are well under 1 TB but the format scales to multiple terabytes with planning, it spills grouping, joins, sorts and windows to disk, and DuckDB Labs ran TPC-H at 27 TB in a single file on a 192-core machine. The guidance is 1 to 4 GB of memory per thread and an NVMe disk. In this test a 4 GB memory cap slowed the SF10 suite from 2.44 s to 4.04 s.

Can DuckDB and Spark work together?

Yes. Spark 4.2 made Arrow the default path to Python, so a Spark DataFrame can stream into DuckDB without a Pandas copy; DuckDB writes Parquet and Iceberg that Spark reads natively; SQLFrame runs PySpark DataFrame code on DuckDB; and Sail speaks the Spark Connect protocol from a non-JVM engine. The common pattern is Spark for the cluster-sized jobs and DuckDB for everything that fits one box, which is most queries.

Top comments (0)