@@ -4,23 +4,44 @@ summary: CockroachDB implements consistent replication via majority consensus be
4
4
toc : false
5
5
---
6
6
7
- CockroachDB replicates your data multiple times and guarantees consistency between replicas
8
- using the [ Raft consensus algorithm] ( https://raft.github.io/ ) , a popular alternative to
9
- [ Paxos] ( http://research.microsoft.com/en-us/um/people/lamport/pubs/paxos-simple.pdf ) .
10
- A consensus algorithm guarantees that any majority of replicas together can always provide
11
- the most recently written data on reads. Writes must reach a majority of replicas (2 out of
12
- 3 by default) before they are considered committed. If a write does not reach a majority of
13
- replicas, it will fail, not be permanent, and will never be visible to readers. This means
14
- that clients always see serializable consistency when viewing data (i.e., stale reads are
15
- not possible).
7
+ CockroachDB replicates your data multiple times and guarantees consistency between replicas.
16
8
9
+ Key properties:
10
+
11
+ - CockroachDB guarantees serializable SQL transactions
12
+ [ as long as system clocks are synchronized with NTP] ( https://www.cockroachlabs.com/blog/living-without-atomic-clocks/ )
17
13
- No downtime for server restarts, machine failures, or datacenter outages
18
14
- Local or wide-area replication with no stale reads on failover
19
15
- Employs Raft, a popular successor to Paxos
20
16
17
+ How does this work?
18
+
19
+ - Stored data is versioned with MVCC, so reads simply limit
20
+ their scope to the data visible at the time the read transaction started.
21
+
22
+ - Writes are serviced using the
23
+ [ Raft consensus algorithm] ( https://raft.github.io/ ) , a popular
24
+ alternative to
25
+ [ Paxos] ( http://research.microsoft.com/en-us/um/people/lamport/pubs/paxos-simple.pdf ) .
26
+ A consensus algorithm guarantees that any majority of replicas
27
+ together always agree on whether an update was committed
28
+ successfully. Updates (writes) must reach a majority of replicas (2
29
+ out of 3 by default) before they are considered committed.
30
+
31
+ To ensure that a write transaction does not interfere with
32
+ read transactions that start after it, CockroachDB also uses
33
+ a [ timestamp cache] ( https://www.cockroachlabs.com/blog/serializable-lockless-distributed-isolation-cockroachdb/ )
34
+ which remembers when data was last read by ongoing transactions.
35
+
36
+ This ensures that clients always observe serializable consistency
37
+ with regards to other concurrent transactions.
38
+
21
39
<img src =" images/2strong-consistency.png " alt =" Strong consistency in CockroachDB " style =" width : 400px " />
22
40
23
41
## See Also
24
42
43
+ - [ Serializable, Lockless, Distributed: Isolation in CockroachDB] ( https://www.cockroachlabs.com/blog/serializable-lockless-distributed-isolation-cockroachdb/ )
25
44
- [ Consensus, Made Thrive] ( https://www.cockroachlabs.com/blog/consensus-made-thrive/ )
26
45
- [ Trust, But Verify: How CockroachDB Checks Replication] ( https://www.cockroachlabs.com/blog/trust-but-verify-cockroachdb-checks-replication/ )
46
+ - [ Living Without Atomic Clocks] ( https://www.cockroachlabs.com/blog/living-without-atomic-clocks/ )
47
+ - [ The CockroachDB Architecture Document] ( https://github.com/cockroachdb/cockroach/blob/master/docs/design.md )
0 commit comments