cockroach process as a means of explanation.
However, you definitely do not need to understand the underlying architecture to use CockroachDB. These pages give serious users and database enthusiasts a high-level framework to explain what’s happening under the hood.
Using this guide
This guide is broken out into pages detailing each layer of CockroachDB. We recommended reading through the layers sequentially, starting with this overview and then proceeding to the SQL layer. If you’re looking for a high-level understanding of CockroachDB, you can read the Overview section of each layer. For more technical detail — for example, if you’re interested in contributing to the project — you should read the Components sections as well.This guide details how CockroachDB is built, but does not explain how to build an application using CockroachDB. For more information about how to develop applications that use CockroachDB, check out our Developer Guide.
Goals of CockroachDB
CockroachDB was designed to meet the following goals:- Make life easier for humans. This means being low-touch and highly automated for operators and simple to reason about for developers.
- Offer industry-leading consistency, even on massively scaled deployments. This means enabling distributed transactions, as well as removing the pain of eventual consistency issues and stale reads.
- Create an always-on database that accepts reads and writes on all nodes without generating conflicts.
- Allow flexible deployment in any environment, without tying you to any platform or vendor.
- Support familiar tools for working with relational data (i.e., SQL).
Overview
CockroachDB starts running on machines with two commands:cockroach startwith a--joinflag for all of the initial nodes in the cluster, so the process knows all of the other machines it can communicate with.cockroach initto perform a one-time initialization of the cluster.
- Continuing to serve reads and writes.
- Consistently replicating the data to other nodes.
AS OF SYSTEM TIME clause, letting you find historical data for a period of time.
While the high-level overview above gives you a notion of what CockroachDB does, looking at how CockroachDB operates at each of these layers will give you much greater understanding of our architecture.
Layers
At the highest level, CockroachDB converts clients’ SQL statements into key-value (KV) data, which is distributed among nodes and written to disk. CockroachDB’s architecture is manifested as a number of layers, each of which interacts with the layers directly above and below it as relatively opaque services. The following pages describe the function each layer performs, while mostly ignoring the details of other layers. This description is true to the experience of the layers themselves, which generally treat the other layers as black-box APIs. There are some interactions that occur between layers that require an understanding of each layer’s function to understand the entire process.Database terms
Consistency
The requirement that a transaction must change affected data only in allowed ways. CockroachDB uses “consistency” in both the sense of ACID semantics and the CAP theorem, albeit less formally than either definition.Isolation
The degree to which a transaction may be affected by other transactions running at the same time. CockroachDB provides theSERIALIZABLE and READ COMMITTED isolation levels. For more information, see Isolation levels.
Consensus
The process of reaching agreement on whether a transaction is committed or aborted. CockroachDB uses the Raft consensus protocol. In CockroachDB, when a range receives a write, a quorum of nodes containing replicas of the range acknowledge the write. This means your data is safely stored and a majority of nodes agree on the database’s current state, even if some of the nodes are offline. When a write does not achieve consensus, forward progress halts to maintain consistency within the cluster.Replication
The process of creating and distributing copies of data, as well as ensuring that those copies remain consistent. CockroachDB requires all writes to propagate to a quorum of copies of the data before being considered committed. This ensures the consistency of your data.Transaction
A set of operations performed on a database that satisfy the requirements of ACID semantics. This is a crucial feature for a consistent system to ensure developers can trust the data in their database. For more information about how transactions work in CockroachDB, see Transaction Layer.Transaction contention
A state of conflict that occurs when:- A transaction is unable to complete due to another concurrent or recent transaction attempting to write to the same data. This is also called lock contention.
- A transaction is automatically retried because it could not be placed into a serializable ordering among all of the currently executing transactions. This is also called a serialization conflict. If the automatic retry is not possible or fails, a transaction retry error is emitted to the client, requiring a client application running under
SERIALIZABLEisolation to retry the transaction.

