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.
Interview question
What is the primary performance challenge when deploying CockroachDB across geographically distant regions?
- a.The overhead of maintaining full ACID transactions across distributed data.
- b.The impact of network latency on write operations due to distributed consensus.Correct
- c.Managing the complexity of its PostgreSQL-compatible interface.
- d.Ensuring data is sharded correctly across all nodes.
Why? this is the answer
The card explicitly states that CockroachDB's performance is sensitive to network latency, making it a poor fit for applications that cannot tolerate higher write latencies in a geo-distributed setup. This is a direct consequence of its strong consistency model enforced by distributed consensus. While ACID transactions do incur overhead, the card specifically highlights network latency as the 'footgun' for geo-distributed performance.
Just read this? Test yourself on what you have been reading.
Read the original → cockroachlabs.com
- #databases
- #distributed systems
- #sql
- #high availability
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on databases — each one lists the topics its interview covers.
See open roles