System Design Space
Knowledge graphSettings

Updated: March 2, 2026 at 7:37 AM

CockroachDB: distributed SQL database and architecture

mid

Distributed SQL DBMS: SQL + ACID on top of distributed KV, ranges/leaseholders, Raft replication, multi-region locality, and automatic rebalancing.

Source

Wikipedia: CockroachDB

CockroachDB timeline, release milestones, and broad context for its distributed SQL positioning.

Open article

Official website

CockroachDB Product Overview

Product-level overview of resilience, horizontal scaling, locality controls, and target workloads.

Open page

CockroachDB is a distributed SQL DBMS focused on strong consistency, fault tolerance, and horizontal scale. In system design, CockroachDB is commonly evaluated for business-critical OLTP services where multi-region deployment, automatic failover, and SQL semantics without manual sharding are key requirements.

History and context

2014design draft

Initial project concept

Spencer Kimball publishes the early design of a distributed SQL system that later becomes CockroachDB.

2015Cockroach Labs

Company foundation

Cockroach Labs is founded to develop the product as a distributed SQL platform for fault-tolerant services.

2017v1.0.0

First production-ready release

The 1.0 line establishes SQL interface, transactional guarantees, and cluster deployment for production workloads.

2019Business Source License

Shift to source-available licensing

Project licensing changes from Apache 2.0 to the Business Source License (BuSL).

2025v25.1.4

Stable 25.1 release line

25.1 branch continues enterprise-focused improvements in performance, scale behavior, and operational maturity.

Core architecture elements

SQL gateway + PostgreSQL compatibility

Any node can accept SQL traffic over PostgreSQL wire protocol and serve as a gateway for distributed execution.

Ranges, leaseholder, and Raft

Global keyspace is split into ranges; leaseholder coordinates access while replication and consensus are handled by Raft.

ACID transactions and Parallel Commits

Transaction layer uses write intents and atomic commit protocol to provide strong consistency in distributed execution.

Geo-locality and auto-rebalancing

Cluster supports multi-region placement, automatic data rebalancing, and horizontal growth without manual sharding.

Data model and transaction contour

Interactive section below explains how CockroachDB combines SQL semantics with a distributed KV core: ranges, replicas, write intents, isolation modes, and locality controls.

CockroachDB data model: ranges, replicas, transactions

CockroachDB builds SQL semantics on top of a distributed KV engine where data is split into ranges and replicated via Raft.

Why CockroachDB differs from classic single-node SQL

  • Tables and indexes map to a distributed KV keyspace that auto-splits into ranges.
  • Each range has replicas; leaseholder coordinates reads/writes for that range.
  • Transactions rely on write intents, lock table, and atomic commit protocol (Parallel Commits).
  • Multi-region locality controls are available for data placement and latency goals.

SQL -> KV keyspace

Table rows and secondary index entries are stored as key-value pairs in a global keyspace.

Key elements

Primary index keysSecondary index keysRange boundariesAutomatic split/merge

Typical use cases

  • Horizontal growth
  • Hot key isolation
  • Large table partitioning

Example

CREATE TABLE orders (
  id UUID PRIMARY KEY,
  tenant_id UUID,
  status STRING,
  created_at TIMESTAMPTZ
);

High-Level Architecture

High-level CockroachDB flow: SQL gateway, transaction layer, range distribution, Raft replication, and storage/locality mechanics.

Clients and SQL access
PostgreSQL wire protocolDrivers + ORMSQL shellCloud/self-hosted
Layer transition
SQL and transaction layer
Cost-based optimizerDistributed tx coordinatorSerializable / Read CommittedParallel Commits
Layer transition
Ranges and replicas
KV keyspaceRange splits/mergesLeaseholderAuto-rebalancing
Layer transition
Consensus and replication
Raft per rangeMajority commit3 replicas by defaultQuorum reads/writes
Layer transition
Storage and locality
MVCC valuesWrite intentsZone/region placementMulti-AZ resilience
Layer transition
Operations
Online schema changesNode add/removeBackupsObservability

System view

Distributed SQLStrong consistency focusCloud-native resilience

Workload profile

Transactional OLTPGeo-distributed servicesOperational analytics (limited)

Operational trade-offs

Cross-range tx overheadSchema/key design criticalHigher complexity than single-node SQL

Read / Write Path through components

Unified diagram combines write/read paths with explanations: request moves through gateway, range routing, leaseholder handling, Raft consensus, and transaction commit/response.

Read/Write Path Explorer

Interactive walkthrough of CockroachDB requests through gateway, leaseholder, Raft, and transaction layer.

1
Client Tx
INSERT UPDATE UPSERT
2
Range Routing
meta lookup
3
Write Intents
provisional values
4
Raft Replication
majority quorum
5
Commit + Resolve
txn record
Write path: transaction lays down write intents on leaseholders, replicates through Raft quorum, and commits via transaction record/Parallel Commits.

Write path

  1. Tables/indexes are split into ranges; transaction keys decide single-range vs multi-range execution.
  2. Writes are first recorded as intents (provisional values with lock semantics).
  3. Commit requires Raft majority per affected range plus transaction-layer coordination.
  4. Under contention, retryable errors are expected and clients should retry transactions.

When to choose CockroachDB

Good fit

  • Mission-critical OLTP systems that require strong consistency, ACID semantics, and cross-zone/region survivability.
  • Products with growing load where reads/writes must scale by adding nodes without manual shard management.
  • Global SaaS and fintech workloads that need locality controls, failover readiness, and SQL continuity.
  • Teams ready to invest in schema/index/key design and distributed SQL operational discipline.

Avoid when

  • Simple single-node applications where a classic local SQL database is enough and cheaper to run.
  • Heavy analytical scan workloads better served by specialized OLAP engines.
  • Systems that cannot tolerate retry-oriented transaction handling under contention.
  • Teams without capacity to operate multi-node infrastructure and deep observability practices.

Practice: DDL and DML

Below are practical CockroachDB SQL examples: DDL for schema/index and multi-region settings, plus DML for transactions, UPSERT, and concurrent row access.

DDL and DML examples in CockroachDB

DDL controls schema/indexes; DML handles transactional and distributed read/write paths.

CockroachDB supports PostgreSQL-like SQL DDL with online schema changes, but key/index design is critical for distributed performance.

Create table with primary key

CREATE TABLE

Primary key shape influences distribution in keyspace/ranges.

CREATE TABLE accounts (
  id UUID PRIMARY KEY,
  tenant_id UUID NOT NULL,
  balance DECIMAL(18,2) NOT NULL,
  status STRING NOT NULL,
  created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);

Covering secondary index

CREATE INDEX ... STORING

Helps avoid extra lookups for hot read endpoints.

CREATE INDEX idx_accounts_tenant_status
ON accounts (tenant_id, status)
STORING (balance, created_at);

Configure multi-region database

ALTER DATABASE ... REGION

Multi-region SQL features support locality and survivability goals.

ALTER DATABASE appdb PRIMARY REGION "us-east1";
ALTER DATABASE appdb ADD REGION "eu-west1";
ALTER DATABASE appdb ADD REGION "ap-southeast1";

Related materials

Related chapters

Enable tracking in Settings

System Design Space

© 2026 Alexander Polomodov