Softwr

Databases · head to head

Apache Spark vs TiDB

Apache Spark logo

Apache Spark

Databases

A distributed engine for batch, SQL, streaming and machine learning workloads over data that does not fit on one machine.

From
Free
Free plan
Yes
TiDB logo

TiDB

Databases

Apache 2.0 distributed SQL database with MySQL wire compatibility and a separate columnar replica for analytical queries.

From
Free
Free plan
Yes

The short version

  • Apache Spark is free; TiDB starts at $250/mo.
  • Only Apache Spark lists unified engine; only TiDB lists MySQL wire compatibility.

How do Apache Spark and TiDB differ?

Apache Spark and TiDB differ on pricing model (Open-source against Freemium), platforms and year founded (2009 against 2015). Only the attributes on which Apache Spark and TiDB actually diverge.

Attributes where Apache Spark and TiDB differ
AttributeApache SparkTiDB
Pricing modelOpen-sourceFreemium
PlatformsWebWeb, AWS, Azure, Self-managed
Founded20092015

Identical on both: starting price (Free), free tier (Yes), category (Databases).

Which features does each one have?

They share no listed features; 8 appear only for Apache Spark and 10 only for TiDB. Drawn from each product's published feature list. An absence here means we hold no record of it - not that the product lacks it.

Only in Apache Spark

  • Unified engine
  • Catalyst optimiser
  • DataFrame and SQL APIs
  • Structured Streaming
  • Spark Connect
  • Kubernetes and YARN support
  • Table format integration
  • MLlib

Only in TiDB

  • MySQL wire compatibility
  • Horizontal write scaling
  • Distributed ACID transactions
  • TiFlash columnar replica
  • Automatic rebalancing
  • Raft replication
  • Apache 2.0 licence
  • Online schema change

What is each one used for?

The jobs each tool is most often brought in to do.

Apache Spark

  • Nightly ETL over terabytes in object storage, where a single machine would take longer than the batch window allowsnot TiDB
  • Building and maintaining a lakehouse on Iceberg or Delta Lake, where Spark handles both the writes and the compactionnot TiDB
  • Feature engineering and model training across datasets too large to fit in pandas on one nodenot TiDB
  • Migrating legacy MapReduce or Hive workloads onto an engine that is still actively developed and widely supported by cloud vendorsnot TiDB

TiDB

  • A MySQL workload that has hit the write ceiling of a single primary and would otherwise need an application-level sharding layernot Apache Spark
  • Reporting that must run against current transactional data, where the columnar replica removes the delay and the cost of an ETL pipelinenot Apache Spark
  • Multi-region deployments needing a single logical database with automatic failover rather than manual primary promotionnot Apache Spark
  • Migrating off a sharded MySQL estate where the sharding logic in the application has become the main source of bugs and operational toilnot Apache Spark

Where do Apache Spark and TiDB fall short?

Documented limitations, not opinions. Every one is a constraint you would hit in normal use.

Apache Spark

  • Running it well is JVM operations work: executor sizing, shuffle partition counts, off-heap memory and serialisation all have to be tuned, and the failures you actually get are out-of-memory errors and skewed shuffles rather than wrong answers, so you need somebody who can read the Spark UI or you will scale the cluster instead of fixing the query
  • The fastest Spark is not open source. Databricks' Photon engine and comparable vendor accelerations are proprietary, so benchmark numbers quoted for Spark frequently describe a fork you can only rent, and moving off that vendor loses the performance you sized your pipelines around
  • It is a distributed system with distributed overheads, and modern single-node tools such as DuckDB and Polars finish faster on datasets up to hundreds of gigabytes with no cluster to start, so a Spark job below that threshold is paying coordination cost for nothing
  • Structured Streaming is micro-batch, which puts an end-to-end latency floor in the range of hundreds of milliseconds to seconds; workloads that need genuine per-event latency go to Flink instead, and discovering this after building on Spark means a rewrite
  • Major upgrades deliberately break jobs: Spark 4.0 turns ANSI SQL mode on by default, so silent overflow and invalid casts that previously produced nulls now raise runtime errors, and a pipeline that worked for years can start failing purely on upgrade
  • PySpark hides a process boundary, and Python UDFs serialise every row between the JVM and a Python worker; a direct translation of pandas code into PySpark UDFs can run an order of magnitude slower than the equivalent built-in expressions

TiDB

  • A production cluster needs several placement driver, storage and SQL nodes before it is fault tolerant, so the minimum viable footprint is far larger than a MySQL server and TiDB is never the economical choice for a small database
  • Every transaction takes a timestamp from the placement driver and crosses the network to storage nodes, so simple point queries are slower than on single-node MySQL and latency-sensitive paths need to be measured, not assumed
  • MySQL compatibility is at the wire and dialect level but not complete; stored procedures, triggers and events are not supported, so an application that pushed logic into the database cannot simply be repointed
  • The columnar replica is an extra full copy of the data on its own nodes, so hybrid analytics roughly doubles storage and adds hardware that must be sized and paid for separately
  • Operating it well requires cluster-specific expertise in TiUP or the Kubernetes operator, region hot spots, and rebalancing behaviour, so the licence is free but the running cost includes an engineer who understands distributed storage

How much do Apache Spark and TiDB cost?

Apache Spark is free to use; TiDB has a free plan, with paid plans from $250/mo. Plan by plan below, from each vendor's own pricing page.

Apache Spark

Free
  • Open source (self-hosted)Free

TiDB

Free
  • ServerlessFree
    • 5GB storage
    • 50M request units
    • Free forever tier
  • Dedicated$250/mo
    • Dedicated resources
    • SLA guarantees
    • Enterprise support

Which should you pick?

Choose Apache Spark if

  • You need unified engine.
  • You want to start without paying.
  • You also want catalyst optimiser.

Choose TiDB if

  • You need mysql wire compatibility.
  • You want to start without paying.
  • You work on Web, AWS, Azure, Self-managed.
  • You also want horizontal write scaling.

Questions people ask

Is Apache Spark or TiDB better?
It depends on the job. Apache Spark fits nightly ETL over terabytes in object storage, where a single machine would take longer than the batch window allows; TiDB fits a MySQL workload that has hit the write ceiling of a single primary and would otherwise need an application-level sharding layer. Apache Spark starts at Free and TiDB at Free.
Which is cheaper, Apache Spark or TiDB?
Apache Spark starts at Free and TiDB at Free.
Does Apache Spark or TiDB run on more platforms?
Apache Spark runs on Web. TiDB runs on Web, AWS, Azure, Self-managed.
Can I use Apache Spark for free?
Both have a free tier, so you can try either at no cost before committing.
What is Apache Spark best used for?
Apache Spark is most often used for nightly etl over terabytes in object storage, where a single machine would take longer than the batch window allows, building and maintaining a lakehouse on iceberg or delta lake, where spark handles both the writes and the compaction, feature engineering and model training across datasets too large to fit in pandas on one node, migrating legacy mapreduce or hive workloads onto an engine that is still actively developed and widely supported by cloud vendors. Of those, nightly etl over terabytes in object storage, where a single machine would take longer than the batch window allows and building and maintaining a lakehouse on iceberg or delta lake, where spark handles both the writes and the compaction are not what TiDB is typically brought in for.
What can Apache Spark do that TiDB cannot?
Apache Spark covers Unified engine, Catalyst optimiser, DataFrame and SQL APIs, Structured Streaming. TiDB covers MySQL wire compatibility, Horizontal write scaling, Distributed ACID transactions, TiFlash columnar replica.

Answered from the vendors’ own pages

Apache Spark: When is Spark the wrong choice?

When your data fits comfortably on one machine. DuckDB or Polars will process hundreds of gigabytes on a single large node faster than a Spark cluster, without a scheduler, a driver or a shuffle. Spark earns its overhead when the data genuinely does not fit.

TiDB: Is TiDB a drop-in replacement for MySQL?

At the protocol and dialect level it is close, and most applications connect unchanged. Stored procedures, triggers and events are not supported, and latency characteristics differ, so it needs testing rather than assumption.

Apache Spark: Is Spark the same on Databricks as the open source version?

No. Databricks runs its own runtime including the proprietary Photon engine and its own optimisations, so performance figures and some behaviours do not carry over to open source Spark on EMR, Dataproc or your own Kubernetes cluster.

TiDB: What licence is it under?

Apache 2.0, for both TiDB and the underlying TiKV storage engine. TiKV is a graduated CNCF project, which is a meaningful governance signal in a market where several competitors moved to source-available licences.

Apache Spark: Can I use Spark for real-time processing?

For near-real-time, yes, with Structured Streaming's micro-batch model, which lands in the sub-second to seconds range. For true per-event latency in the low milliseconds, Flink is the usual choice.

TiDB: Do I need TiFlash?

Only for analytical queries. It is an optional columnar replica; without it TiDB is a distributed transactional database. With it you get analytics on live data at the cost of an additional full copy.

Apache Spark: Does upgrading between major versions break things?

Yes, by design in some cases. Spark 4.0 makes ANSI SQL mode the default, which converts previously silent overflow and cast failures into runtime errors. Upgrades need a testing pass over production pipelines rather than a version bump.

TiDB: Is the managed cloud the same software?

TiDB Cloud runs the same engine, with the control plane, scaling and operational tooling provided as a service. The entry tier is metered differently from a dedicated cluster, so the cost model rather than the engine is what changes.

Apache Spark: Do I need to know Scala?

No. Python covers the vast majority of work and PySpark is the most common interface. Scala still helps when reading the source, writing custom data sources or diagnosing errors that surface as JVM stack traces.

TiDB: When is TiDB the wrong choice?

When the database is small enough for one server, when latency on single-row lookups is the primary constraint, or when the application depends on MySQL stored procedures and triggers.

Share

Related pages

Other head to heads