SlideShare a Scribd company logo
1 of 36
Download to read offline
Franz Wimmer
franz.wimmer@qaware.de
@zalintyre
Consistency, Availability and
Partition tolerance in practice
A deep dive into CockroachDB
15.01.2020
Franz Wimmer
Software Engineer
2019
2018
2017
- No Backend, no Problem! Static Websites with Jekyll
- Offensive Security – The Metasploit Framework
@QAware
- Evaluating private APIs with Apache Ignite
@MRMCD, Darmstadt
- Leveraging the power of SolrCloud and Spark with OpenShift
@Munich Kubernetes / Cloud Native Meetup
- Ransomware vs. Antivirus
@ MRMCD, Darmstadt
1. Introduction
2. CAP Theorem
3. CockroachDB
4. Live Demo
5. Summary
Introduction
Many database systems offer some sort of distribution or replication. Choose wisely:
Distribution / Sharding:
Data is partitioned across multiple nodes.
Less availability in case of outages.
Reads are quite fast and easy to achieve.
Replication:
Data is copied to multiple nodes.
More availability in case of outages.
Writes are difficult to replicate consistently.
Examples:
MySQL Master / Slave (replicated, slave read only)
PostgreSQL High Availability / Load Balancing / Replication (replicated)
MongoDB, CouchDB (Shards & Replicas)
Solr Cloud (Shards & Replicas)
Introduction – Distributed / Replicated Databases
CAP Theorem
“In a network subject to communication failures, it
is impossible for any web service to implement an
atomic read/write shared memory that
guarantees a response to every request” 1
1
Gilbert, Seth, and Nancy Lynch. "Perspectives on the CAP Theorem." Computer 45.2 (2012): 30-36.
The CAP Theorem
8
Consistency Availability
Partition tolerance
x
All nodes see the exact
same copies of data at a
given time.
C A
P
The system is still available, even if
nodes or communication paths go
offline.
The system works even if messages are lost.
It can deal with the network splitting up in
several partitions.
AP: DNS
Highly available
Arbitrary servers can go offline
Consistency takes a long time (up to 24 hours)
CP: (Online) Banking
Consistency is key, even when the network is down
Availability is secondary
CA: RDBMS with highly available servers and networks
Consistent (transactions) and highly available
Fail when outages occur
Examples
“CockroachDB chooses
consistency.”
“CockroachDB chooses consistency”
As a CP system, is CockroachDB not available? No!
Every piece of data (“range”) is replicated to at least 3 nodes.
In this setup, up to 2 nodes can go offline / be partitioned away.
But: Writes require a majority of replicas to be available.
CockroachDB and the CAP Theorem
In the cloud, communication failures are
common. So basically, you have the choice
between CP and AP.
The CAP Theorem (2)
Consistency Availability
Partition tolerance
x
C A
P
2PC2PC
GossipGossipConsensusConsensus
CockroachDB uses RAFT as consensus protocol.
RAFT
CockroachDB
CockroachDB is …
A distributed SQL database
Every SQL query operates on key-value data.
Data is persisted using RocksDB key-value store.
Raft is the central consensus algorithm to manage the database cluster.
CockroachDB architecture defines layers:
SQL
Transaction
Distribution
Replication
Storage
CockroachDB Architecture
Range: A chunk of data. Think of “SQL Table”.
Replica: Each range is copied to (at least) 3 different nodes.
Leaseholder: The replica that coordinates reads and writes for a range.
Glossary
SQL – Read data
SQL – Read data
SQL – Write data
SQL – Write data
CockroachDB supports ACID transactions.
Atomicity
Writes are performed to the whole cluster at once.
If anything fails, the transaction is rolled back.
Consistency
Incomplete write operations are at no time served to reading clients.
Isolation
All CockroachDB transactions are upgraded to SERIALIZABLE.
Durability
Every successful transaction has been persisted to a majority of replicas (see: Raft).
Transactions
Distribution & Replication
Distribution & Replication
Distribution & Replication
CockroachDB was built around …
… the SQL network protocol (“pgwire”)
… the SQL syntax (“using the PostgreSQL syntax parser”)
… and the SQL dialect semantics
of PostgreSQL.
This means that you can …
… use a standard PostgreSQL driver
… build the same SQL Queries you always did
… or use a SQL framework of your choice (Hibernate, EclipseLink, …)
… well, that’s not entirely true.
CockroachDB doesn’t support some PostgreSQL features
… and might implement own features in the future.
PostgreSQL compatibility
Deploying is easy with various cloud providers
YAML files for every occasion
Different Helm charts available
Deployment
$ wget -qO- https://binaries.cockroachdb.com/cockroach-v19.2.4.linux-amd64.tgz | tar xvz
$ cp -i cockroach-v19.2.4.linux-amd64/cockroach /usr/local/bin/
$ cockroach start
Deployment – the easiest way
Demo time!
Source Code
available here:
https://github.com/zalintyre/cockroach-demo.git
Summary
Performance
Performance
Easy to install
Easy to use (Postgres driver!)
Don‘t worry about consistency, but prepare for occasional waits
Open Source
Free (if you don‘t need enterprise features)
Maybe this is the PostgreSQL database you always wanted.
Summary
QAware 34
Core Edition
Licensed under Apache 2.0 until version 19.1
From 19.2: Business Source License (BSL)
Forbids you to host CockroachDB as a Service.
Converts to Apache 2.0 license three years after release
Enterprise Edition: Geo partitioning, RBAC, Follower Reads, Encryption at Rest...
There are a lot more features not covered by this talk!
Licensing and features
CockroachDB docs: https://www.cockroachlabs.com/docs/stable
RAFT visualization: http://thesecretlivesofdata.com/raft/
See also
twitter.com/zalintyre github.com/zalintyreFranz Wimmer
franz.wimmer@qaware.de

More Related Content

More from QAware GmbH

Migration von stark regulierten Anwendungen in die Cloud: Dem Teufel die See...
 Migration von stark regulierten Anwendungen in die Cloud: Dem Teufel die See... Migration von stark regulierten Anwendungen in die Cloud: Dem Teufel die See...
Migration von stark regulierten Anwendungen in die Cloud: Dem Teufel die See...
QAware GmbH
 

More from QAware GmbH (20)

Cloud Migration mit KI: der Turbo
Cloud Migration mit KI: der Turbo Cloud Migration mit KI: der Turbo
Cloud Migration mit KI: der Turbo
 
Migration von stark regulierten Anwendungen in die Cloud: Dem Teufel die See...
 Migration von stark regulierten Anwendungen in die Cloud: Dem Teufel die See... Migration von stark regulierten Anwendungen in die Cloud: Dem Teufel die See...
Migration von stark regulierten Anwendungen in die Cloud: Dem Teufel die See...
 
Aus blau wird grün! Ansätze und Technologien für nachhaltige Kubernetes-Cluster
Aus blau wird grün! Ansätze und Technologien für nachhaltige Kubernetes-Cluster Aus blau wird grün! Ansätze und Technologien für nachhaltige Kubernetes-Cluster
Aus blau wird grün! Ansätze und Technologien für nachhaltige Kubernetes-Cluster
 
Endlich gute API Tests. Boldly Testing APIs Where No One Has Tested Before.
Endlich gute API Tests. Boldly Testing APIs Where No One Has Tested Before.Endlich gute API Tests. Boldly Testing APIs Where No One Has Tested Before.
Endlich gute API Tests. Boldly Testing APIs Where No One Has Tested Before.
 
Kubernetes with Cilium in AWS - Experience Report!
Kubernetes with Cilium in AWS - Experience Report!Kubernetes with Cilium in AWS - Experience Report!
Kubernetes with Cilium in AWS - Experience Report!
 
50 Shades of K8s Autoscaling
50 Shades of K8s Autoscaling50 Shades of K8s Autoscaling
50 Shades of K8s Autoscaling
 
Kontinuierliche Sicherheitstests für APIs mit Testkube und OWASP ZAP
Kontinuierliche Sicherheitstests für APIs mit Testkube und OWASP ZAPKontinuierliche Sicherheitstests für APIs mit Testkube und OWASP ZAP
Kontinuierliche Sicherheitstests für APIs mit Testkube und OWASP ZAP
 
Service Mesh Pain & Gain. Experiences from a client project.
Service Mesh Pain & Gain. Experiences from a client project.Service Mesh Pain & Gain. Experiences from a client project.
Service Mesh Pain & Gain. Experiences from a client project.
 
50 Shades of K8s Autoscaling
50 Shades of K8s Autoscaling50 Shades of K8s Autoscaling
50 Shades of K8s Autoscaling
 
Blue turns green! Approaches and technologies for sustainable K8s clusters.
Blue turns green! Approaches and technologies for sustainable K8s clusters.Blue turns green! Approaches and technologies for sustainable K8s clusters.
Blue turns green! Approaches and technologies for sustainable K8s clusters.
 
Per Anhalter zu Cloud Nativen API Gateways
Per Anhalter zu Cloud Nativen API GatewaysPer Anhalter zu Cloud Nativen API Gateways
Per Anhalter zu Cloud Nativen API Gateways
 
Aus blau wird grün! Ansätze und Technologien für nachhaltige Kubernetes-Cluster
Aus blau wird grün! Ansätze und Technologien für nachhaltige Kubernetes-Cluster Aus blau wird grün! Ansätze und Technologien für nachhaltige Kubernetes-Cluster
Aus blau wird grün! Ansätze und Technologien für nachhaltige Kubernetes-Cluster
 
How to speed up Spring Integration Tests
How to speed up Spring Integration TestsHow to speed up Spring Integration Tests
How to speed up Spring Integration Tests
 
Aus blau wird grün! Ansätze und Technologien für nachhaltige Kubernetes-Cluster
Aus blau wird grün! Ansätze und Technologien für nachhaltige Kubernetes-ClusterAus blau wird grün! Ansätze und Technologien für nachhaltige Kubernetes-Cluster
Aus blau wird grün! Ansätze und Technologien für nachhaltige Kubernetes-Cluster
 
Cloud Migration – Eine Strategie die funktioniert
Cloud Migration – Eine Strategie die funktioniertCloud Migration – Eine Strategie die funktioniert
Cloud Migration – Eine Strategie die funktioniert
 
Policy Driven Microservices mit Open Policy Agent
Policy Driven Microservices mit Open Policy AgentPolicy Driven Microservices mit Open Policy Agent
Policy Driven Microservices mit Open Policy Agent
 
Make Developers Fly: Principles for Platform Engineering
Make Developers Fly: Principles for Platform EngineeringMake Developers Fly: Principles for Platform Engineering
Make Developers Fly: Principles for Platform Engineering
 
Security Lab: OIDC in der Praxis
Security Lab: OIDC in der PraxisSecurity Lab: OIDC in der Praxis
Security Lab: OIDC in der Praxis
 
Die nächsten 100 Microservices
Die nächsten 100 MicroservicesDie nächsten 100 Microservices
Die nächsten 100 Microservices
 
Enterprise-level Kubernetes Security mit Open Source Tools - geht das?
Enterprise-level Kubernetes Security mit Open Source Tools - geht das?Enterprise-level Kubernetes Security mit Open Source Tools - geht das?
Enterprise-level Kubernetes Security mit Open Source Tools - geht das?
 

Recently uploaded

Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
only4webmaster01
 
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
amitlee9823
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
amitlee9823
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
amitlee9823
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
amitlee9823
 
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men 🔝Thrissur🔝 Escor...
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men  🔝Thrissur🔝   Escor...➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men  🔝Thrissur🔝   Escor...
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men 🔝Thrissur🔝 Escor...
amitlee9823
 
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...
amitlee9823
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
amitlee9823
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
karishmasinghjnh
 
Probability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter LessonsProbability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter Lessons
JoseMangaJr1
 

Recently uploaded (20)

Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
 
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
 
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men 🔝Thrissur🔝 Escor...
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men  🔝Thrissur🔝   Escor...➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men  🔝Thrissur🔝   Escor...
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men 🔝Thrissur🔝 Escor...
 
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
hybrid Seed Production In Chilli & Capsicum.pptx
hybrid Seed Production In Chilli & Capsicum.pptxhybrid Seed Production In Chilli & Capsicum.pptx
hybrid Seed Production In Chilli & Capsicum.pptx
 
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
 
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24  Building Real-Time Pipelines With FLaNKDATA SUMMIT 24  Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
 
Probability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter LessonsProbability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter Lessons
 
Anomaly detection and data imputation within time series
Anomaly detection and data imputation within time seriesAnomaly detection and data imputation within time series
Anomaly detection and data imputation within time series
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
 

Consistency, Availability and Partition tolerance in practice

  • 1. Franz Wimmer franz.wimmer@qaware.de @zalintyre Consistency, Availability and Partition tolerance in practice A deep dive into CockroachDB 15.01.2020
  • 2. Franz Wimmer Software Engineer 2019 2018 2017 - No Backend, no Problem! Static Websites with Jekyll - Offensive Security – The Metasploit Framework @QAware - Evaluating private APIs with Apache Ignite @MRMCD, Darmstadt - Leveraging the power of SolrCloud and Spark with OpenShift @Munich Kubernetes / Cloud Native Meetup - Ransomware vs. Antivirus @ MRMCD, Darmstadt
  • 3. 1. Introduction 2. CAP Theorem 3. CockroachDB 4. Live Demo 5. Summary
  • 5. Many database systems offer some sort of distribution or replication. Choose wisely: Distribution / Sharding: Data is partitioned across multiple nodes. Less availability in case of outages. Reads are quite fast and easy to achieve. Replication: Data is copied to multiple nodes. More availability in case of outages. Writes are difficult to replicate consistently. Examples: MySQL Master / Slave (replicated, slave read only) PostgreSQL High Availability / Load Balancing / Replication (replicated) MongoDB, CouchDB (Shards & Replicas) Solr Cloud (Shards & Replicas) Introduction – Distributed / Replicated Databases
  • 7. “In a network subject to communication failures, it is impossible for any web service to implement an atomic read/write shared memory that guarantees a response to every request” 1 1 Gilbert, Seth, and Nancy Lynch. "Perspectives on the CAP Theorem." Computer 45.2 (2012): 30-36.
  • 8. The CAP Theorem 8 Consistency Availability Partition tolerance x All nodes see the exact same copies of data at a given time. C A P The system is still available, even if nodes or communication paths go offline. The system works even if messages are lost. It can deal with the network splitting up in several partitions.
  • 9. AP: DNS Highly available Arbitrary servers can go offline Consistency takes a long time (up to 24 hours) CP: (Online) Banking Consistency is key, even when the network is down Availability is secondary CA: RDBMS with highly available servers and networks Consistent (transactions) and highly available Fail when outages occur Examples
  • 11. “CockroachDB chooses consistency” As a CP system, is CockroachDB not available? No! Every piece of data (“range”) is replicated to at least 3 nodes. In this setup, up to 2 nodes can go offline / be partitioned away. But: Writes require a majority of replicas to be available. CockroachDB and the CAP Theorem
  • 12. In the cloud, communication failures are common. So basically, you have the choice between CP and AP. The CAP Theorem (2) Consistency Availability Partition tolerance x C A P 2PC2PC GossipGossipConsensusConsensus
  • 13. CockroachDB uses RAFT as consensus protocol. RAFT
  • 15. CockroachDB is … A distributed SQL database Every SQL query operates on key-value data. Data is persisted using RocksDB key-value store. Raft is the central consensus algorithm to manage the database cluster. CockroachDB architecture defines layers: SQL Transaction Distribution Replication Storage CockroachDB Architecture
  • 16. Range: A chunk of data. Think of “SQL Table”. Replica: Each range is copied to (at least) 3 different nodes. Leaseholder: The replica that coordinates reads and writes for a range. Glossary
  • 17. SQL – Read data
  • 18. SQL – Read data
  • 21. CockroachDB supports ACID transactions. Atomicity Writes are performed to the whole cluster at once. If anything fails, the transaction is rolled back. Consistency Incomplete write operations are at no time served to reading clients. Isolation All CockroachDB transactions are upgraded to SERIALIZABLE. Durability Every successful transaction has been persisted to a majority of replicas (see: Raft). Transactions
  • 25. CockroachDB was built around … … the SQL network protocol (“pgwire”) … the SQL syntax (“using the PostgreSQL syntax parser”) … and the SQL dialect semantics of PostgreSQL. This means that you can … … use a standard PostgreSQL driver … build the same SQL Queries you always did … or use a SQL framework of your choice (Hibernate, EclipseLink, …) … well, that’s not entirely true. CockroachDB doesn’t support some PostgreSQL features … and might implement own features in the future. PostgreSQL compatibility
  • 26. Deploying is easy with various cloud providers YAML files for every occasion Different Helm charts available Deployment
  • 27. $ wget -qO- https://binaries.cockroachdb.com/cockroach-v19.2.4.linux-amd64.tgz | tar xvz $ cp -i cockroach-v19.2.4.linux-amd64/cockroach /usr/local/bin/ $ cockroach start Deployment – the easiest way
  • 33. Easy to install Easy to use (Postgres driver!) Don‘t worry about consistency, but prepare for occasional waits Open Source Free (if you don‘t need enterprise features) Maybe this is the PostgreSQL database you always wanted. Summary
  • 34. QAware 34 Core Edition Licensed under Apache 2.0 until version 19.1 From 19.2: Business Source License (BSL) Forbids you to host CockroachDB as a Service. Converts to Apache 2.0 license three years after release Enterprise Edition: Geo partitioning, RBAC, Follower Reads, Encryption at Rest... There are a lot more features not covered by this talk! Licensing and features
  • 35. CockroachDB docs: https://www.cockroachlabs.com/docs/stable RAFT visualization: http://thesecretlivesofdata.com/raft/ See also