Features
- PostgreSQL-compatible distributed SQL
- Automatic sharding and rebalancing
- Serializable isolation — strongest consistency guarantee
- Multi-region deployment with locality-aware reads
Pros
- Survives node, zone, and region failures automatically
- PostgreSQL wire protocol compatibility
- Horizontal scale without application changes
Cons
- Higher latency than single-node PostgreSQL for simple queries
- Complexity overhead for small-scale applications
- Pricing can be significant at scale
Overview
CockroachDB is a distributed SQL database designed to survive failures while maintaining strong consistency. It’s PostgreSQL-compatible, meaning existing PostgreSQL tools and ORMs work without modification, but adds automatic sharding, replication, and multi-region deployment.
CockroachDB uses the Raft consensus protocol to replicate data across nodes, ensuring no single point of failure. Its serializable isolation level provides the strongest transaction guarantees available, preventing anomalies that weaker isolation levels allow.
When to Use
CockroachDB is ideal for applications that need global distribution, zero-downtime operations, and strong consistency guarantees. It’s particularly suited for financial systems, multi-region SaaS platforms, and any workload where data loss or downtime is unacceptable. For single-region applications, PostgreSQL is simpler.
Getting Started
# Docker quickstart
docker run -d --name cockroach \
-p 26257:26257 -p 8080:8080 \
cockroachdb/cockroach start-single-node --insecure
# Connect with any PostgreSQL client
psql postgresql://root@localhost:26257/defaultdb