tezvyn:

CockroachDB: A SQL Database That Survives Disasters

AI-drafted, machine-checkedSource: cockroachlabs.comadvanced
CockroachDB: A SQL Database That Survives Disasters

CockroachDB is a distributed SQL database designed to be unkillable. Use it for global apps needing strong consistency and high availability, like financial ledgers or identity systems. The footgun: ignoring network latency between nodes can kill performance.

WHY IT EXISTS: Traditional single-node databases are a single point of failure and don't scale well globally. Manually sharding a relational database is complex and brittle. CockroachDB was built to provide the scalability and resilience of NoSQL systems with the strong consistency and familiarity of SQL.

THE MENTAL MODEL: Think of it as a single, logical PostgreSQL-compatible database that has been shattered into pieces and scattered across a cluster of servers. These servers, or nodes, constantly talk to each other to keep data consistent and available, even if some of them fail. You can connect to any node and see the entire database as a unified whole.

HOW IT WORKS: CockroachDB stores all data in a giant sorted map of key-value pairs. This map is partitioned into contiguous blocks called "ranges." Each range is replicated across at least three nodes using the Raft consensus protocol. This ensures that if a node holding one copy goes down, the system can continue reading and writing by using another copy. It uses a distributed transaction protocol on top of this foundation to provide full ACID guarantees across any set of data, no matter where it's stored.

WHEN TO USE IT: Use CockroachDB when your application requires strong consistency (ACID transactions), high availability, and horizontal scalability, especially across different geographic regions. It is a strong fit for financial services, global e-commerce, IoT platforms, and other mission-critical systems where data integrity and uptime are non-negotiable.

WHEN NOT TO USE IT: Avoid CockroachDB for simple, single-region applications where a standard PostgreSQL instance would suffice; the added operational complexity isn't justified. It is also not the best choice for heavy analytical workloads (OLAP), which are better served by specialized data warehouses. Its performance is sensitive to network latency, making it a poor fit for applications that cannot tolerate higher write latencies in a geo-distributed setup.

ONE CANONICAL EXAMPLE: A global online bank needs to store user account balances. The system must be available 24/7, even if a datacenter in one region goes offline, and needs strict transactional consistency to prevent double-spending. CockroachDB can be deployed across three continents, ensuring that transactions are ACID-compliant and that the service remains fully operational during a regional outage.

Read the original → cockroachlabs.com

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.