Skip to main content
CockroachDB

What is CockroachDB?

CockroachDB is a distributed SQL database built on a transactional and strongly-consistent key-value store. It combines the familiarity of SQL with the scale and resilience of NoSQL systems.

Horizontal Scalability

Scales horizontally by adding nodes to the cluster, supporting up to 4 exabytes of logical data

High Availability

Survives disk, machine, rack, and datacenter failures with minimal latency disruption and no manual intervention

Strong Consistency

Provides strongly-consistent ACID transactions using distributed consensus (Raft)

SQL Interface

Familiar SQL API for structuring, manipulating, and querying data with PostgreSQL compatibility

Core Features

Distributed Architecture

CockroachDB implements a layered architecture where:
  • SQL Layer: Provides familiar relational concepts like schemas, tables, columns, and indexes
  • Distributed KV Store: Handles range addressing to provide a single, monolithic key-value store abstraction
  • Raft Consensus: Ensures data replication and consistency across nodes
  • Storage Engine: Uses RocksDB (a variant of LevelDB) for local storage
Every node in a CockroachDB cluster is symmetric - any node can act as a SQL gateway, making the cluster truly decentralized.

How It Works

The database is logically a single, monolithic sorted map from key to value. Internally, this map is divided into ranges (default 64MB each):
  1. Each range is replicated to a configurable number of nodes (default: 3)
  2. Ranges use the Raft consensus algorithm for synchronous replication
  3. Ranges automatically split and merge to maintain optimal size
  4. Data is automatically rebalanced across the cluster

Transaction Guarantees

CockroachDB provides two isolation levels:
  • Serializable Snapshot Isolation (SSI): The default, provides full serializability with no anomalies
  • Snapshot Isolation (SI): Higher performance but allows write skew in rare cases
CockroachDB uses a non-locking distributed commit protocol and hybrid logical clocks (HLC) to maintain consistency without atomic clocks.

Key Design Goals

CockroachDB was built with three primary goals:
1

Scalability

Horizontal scaling by adding more nodes increases both capacity and throughput linearly
2

Strong Consistency

All operations maintain ACID guarantees across distributed transactions
3

Survivability

Tolerates datacenter failures with minimal latency disruption and zero manual intervention

Use Cases

CockroachDB excels at:
  • Cloud-native applications requiring global distribution
  • Multi-region deployments with data locality requirements
  • Mission-critical systems that cannot tolerate downtime
  • Applications migrating from PostgreSQL (wire protocol compatible)
  • High-scale OLTP workloads with strong consistency needs

Get Started

Quick Start

Get CockroachDB running in minutes with our step-by-step tutorial

Installation

Install CockroachDB on your preferred platform

Architecture Guide

Deep dive into how CockroachDB works internally

SQL Reference

Learn about supported SQL statements and syntax

PostgreSQL Compatibility

CockroachDB supports the PostgreSQL wire protocol, which means:
  • You can use existing PostgreSQL client drivers
  • Most PostgreSQL applications work with minimal changes
  • Standard ORMs (Hibernate, Django, ActiveRecord) are supported
  • SQL syntax is largely compatible with PostgreSQL
While highly compatible, some PostgreSQL features are not supported. Check the SQL Feature Support documentation for details.

Next Steps

Ready to get started?
  1. Follow the Quick Start Guide to run your first cluster
  2. Review Installation Options for production deployments
  3. Explore the official documentation for in-depth guides

Build docs developers (and LLMs) love