Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions frequently-asked-questions.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ For short-term failures, such as a server restart, CockroachDB uses Raft to cont

## How is CockroachDB strongly-consistent?

CockroachDB replicates your data multiple times and guarantees consistency between replicas using the [Raft consensus algorithm](https://raft.github.io/), a popular alternative to [Paxos](http://research.microsoft.com/en-us/um/people/lamport/pubs/paxos-simple.pdf). A consensus algorithm guarantees that any majority of replicas together can always provide the most recently written data on reads. Writes must reach a majority of replicas (2 out of 3 by default) before they are considered committed. If a write does not reach a majority of replicas, it will fail, not be permanent, and will never be visible to readers. This means that clients always see serializable consistency when viewing data (i.e., stale reads are not possible).

For a detailed look at how we've tested CockroachDB for correctness and consistency, see [DIY Jepsen Testing of CockroachDB](https://www.cockroachlabs.com/blog/diy-jepsen-testing-cockroachdb/).
CockroachDB guarantees the SQL isolation level "serializable", the highest defined by the SQL standard.
It does so by combining the Raft consensus algorithm for writes and a custom time-based synchronization algorithms for reads.
See our description of [strong consistency](strong-consistency.html) for more details.

## Why is CockroachDB SQL?

Expand Down
31 changes: 30 additions & 1 deletion strong-consistency.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,44 @@ summary: CockroachDB implements consistent replication via majority consensus be
toc: false
---

CockroachDB replicates your data multiple times and guarantees consistency between replicas using the [Raft consensus algorithm](https://raft.github.io/), a popular alternative to [Paxos](http://research.microsoft.com/en-us/um/people/lamport/pubs/paxos-simple.pdf). A consensus algorithm guarantees that any majority of replicas together can always provide the most recently written data on reads. Writes must reach a majority of replicas (2 out of 3 by default) before they are considered committed. If a write does not reach a majority of replicas, it will fail, not be permanent, and will never be visible to readers. This means that clients always see serializable consistency when viewing data (i.e., stale reads are not possible).
CockroachDB replicates your data multiple times and guarantees consistency between replicas.

Key properties:

- CockroachDB guarantees serializable SQL transactions
[as long as system clocks are synchronized with NTP](https://www.cockroachlabs.com/blog/living-without-atomic-clocks/)
- No downtime for server restarts, machine failures, or datacenter outages
- Local or wide-area replication with no stale reads on failover
- Employs Raft, a popular successor to Paxos

How does this work?

- Stored data is versioned with MVCC, so reads simply limit
their scope to the data visible at the time the read transaction started.

- Writes are serviced using the
[Raft consensus algorithm](https://raft.github.io/), a popular
alternative to
[Paxos](http://research.microsoft.com/en-us/um/people/lamport/pubs/paxos-simple.pdf).
A consensus algorithm guarantees that any majority of replicas
together always agree on whether an update was committed
successfully. Updates (writes) must reach a majority of replicas (2
out of 3 by default) before they are considered committed.

To ensure that a write transaction does not interfere with
read transactions that start after it, CockroachDB also uses
a [timestamp cache](https://www.cockroachlabs.com/blog/serializable-lockless-distributed-isolation-cockroachdb/)
which remembers when data was last read by ongoing transactions.

This ensures that clients always observe serializable consistency
with regards to other concurrent transactions.

<img src="images/2strong-consistency.png" alt="Strong consistency in CockroachDB" style="width: 400px" />

## See Also

- [Serializable, Lockless, Distributed: Isolation in CockroachDB](https://www.cockroachlabs.com/blog/serializable-lockless-distributed-isolation-cockroachdb/)
- [Consensus, Made Thrive](https://www.cockroachlabs.com/blog/consensus-made-thrive/)
- [Trust, But Verify: How CockroachDB Checks Replication](https://www.cockroachlabs.com/blog/trust-but-verify-cockroachdb-checks-replication/)
- [Living Without Atomic Clocks](https://www.cockroachlabs.com/blog/living-without-atomic-clocks/)
- [The CockroachDB Architecture Document](https://github.com/cockroachdb/cockroach/blob/master/docs/design.md)