dbstack

← All tools

CockroachDB

A distributed, strongly-consistent SQL database with Postgres-wire compatibility, designed to survive failures.

distributed relational sql postgres-compatible

What it is

CockroachDB is a distributed SQL database that aims for the operational properties of a NoSQL system (horizontal scaling, fault tolerance, geographic distribution) with the data model and consistency of a traditional relational database. It speaks the Postgres wire protocol, so most Postgres client libraries connect without modification.

It was started in 2014 by Spencer Kimball, Peter Mattis, and Ben Darnell — all ex-Googlers, drawing inspiration from Google’s Spanner. The first production release came in 2017. Cockroach Labs is the steward.

In August 2024, Cockroach Labs announced a significant license change. From version 24.3 onward (released October 2024), CockroachDB is distributed under a single proprietary license (the Cockroach Software License) — no longer BSL with a conversion to Apache 2. Self-hosting in production now requires a paid Enterprise license. Older versions retain their original BSL terms.

Why people use it

  • Global ACID transactions. CockroachDB serializes transactions across regions using a variant of Spanner’s TrueTime approach (without GPS clocks). You get strong consistency without sacrificing horizontal scale.
  • Postgres wire compatibility. Most clients, ORMs, and tools that speak Postgres work without changes. SQLAlchemy, Prisma, Drizzle, Hibernate — all fine.
  • Survives failures by design. Region failures, zone failures, individual node failures — the cluster keeps serving traffic with no manual recovery, as long as a majority of replicas survive.
  • Geo-partitioning. You can pin specific data to specific regions for latency or compliance. A user in Europe gets their data served from Europe.
  • Horizontal write scaling. Unlike traditional Postgres replicas (which only scale reads), CockroachDB shards data across nodes for write parallelism.

When to use CockroachDB

  • Apps that need global deployment with strong consistency, where eventual consistency would create bugs.
  • Workloads that outgrew single-node Postgres on write throughput and need horizontal scale-out without giving up ACID.
  • Multi-region apps where data residency or latency requires placing data in specific regions.
  • Financial, regulatory, or other domains where strict consistency is non-negotiable.

When not to use CockroachDB

  • Single-region workloads. For most apps, vanilla Postgres is simpler, faster, and cheaper.
  • Cost-sensitive workloads. Distributed SQL has overhead. Per-query latency is higher than a tuned single-node Postgres on equivalent hardware. CockroachDB Cloud is not cheap.
  • Workloads needing Postgres extensions. CockroachDB does not support PostGIS, pgvector, TimescaleDB, or most extensions. “Postgres-compatible” means the wire protocol and most SQL — not the extension ecosystem.
  • Apps where eventual consistency is fine. Cassandra, DynamoDB, or a simpler Postgres + replica setup will be cheaper and lower-latency.

Notable trade-offs

  • 2024 license change. CockroachDB is no longer open source. Production self-hosting now requires an Enterprise license. This is a significant shift in posture and a real factor for new adoptions. Evaluate carefully.
  • Per-query latency is higher than single-node Postgres. Consensus and range routing add overhead — typically a few milliseconds even within a region. For high-throughput point queries, this is real.
  • “Postgres-compatible” has limits. Stored procedures, some advanced SQL features, and the entire extension ecosystem differ. Don’t assume drop-in compatibility — test your specific queries.
  • Operational complexity. Even managed via CockroachDB Cloud, distributed systems have more moving parts. Range splits, replica placement, and zone configs are concepts you have to understand at scale.
  • Cost at scale. Distributed SQL has more replicas, more network traffic, more coordination — all of which cost money. CockroachDB Cloud is priced accordingly.

Ecosystem

  • CockroachDB Cloud. The strategic product — managed CockroachDB with Serverless (free tier available) and Dedicated tiers.
  • CockroachDB Self-Hosted. Source-available; production use requires an Enterprise license post-2024.
  • Postgres-wire-compatible so most ORMs, BI tools, and drivers work.

Alternatives to consider

  • YugabyteDB — similar distributed-SQL architecture, Apache 2 licensed, PostgreSQL-compatible. Genuinely open source.
  • Google Cloud Spanner — the system CockroachDB is modeled on. GCP only.
  • TiDB — distributed SQL, MySQL-compatible, with a strong analytical story (TiFlash). Apache 2 licensed.
  • Vanilla Postgres + Citus — if you don’t need geo-distribution, this is much simpler.