SlideShare a Scribd company logo
1 of 53
Download to read offline
Shivji Kumar Jha
Navigating Transactions
ACID Complexity in Modern Databases
1
Data Platforms & OSS
• Databases, streams, app architecture
• Loves open source software (OSS)
• And communities (meetups)
• Regular speaker ( talk # 23)
• Sta
ff
Engineer at Nutanix
Shivji Kumar Jha
https://www.linkedin.com/in/shivjijha
https://youtube.com/@ShivjiKumarJha
https://t.me/theDbShots
2
• Transactions & ACID
• Implementing Transactions
• Distributed transactions
• Cloud scale databases
Contents
3
Transactions
4
Transactions
Historical Perspective
Almost all relational and even some non relational databases
Most of them follow system R - first SQL DB by IBM in 1975.
General ideas has remained same over 45+ years
MySQL, Postgres, Oracle, SQL server have similar transactions
5
Transactions
Historical Perspective
Transactions are antithesis of
scalability
Large scale systems have to
abandon transaction
Go for good performance
and high availability
6
Transactions are essential
requirements for serious
applications with valuable data
NoSQL Camp
SQL Camp
Transactions
Historical Perspective
Transactions are antithesis of
scalability
Large scale systems have to
abandon transaction
Go for good performance
and high availability
7
Transactions are essential
requirements for serious
applications with valuable data
NoSQL Camp
SQL Camp
Both are exaggerated!
Trade-offs!
8
Coined in 1983 by Theo Harder and Andreas Reuter
Atomicity
Consistency Isolation Durability
9
Coined in 1983 by Theo Harder and Andreas Reuter
The slippery slope!
In practice, one database’s implementation of ACID does not equal
another’s implementation
For example, a lot of ambiguity in meaning of “isolation”
Devil is in details!
When a system claims ACID, unclear what guarantees it provides
ACID has unfortunately become a marketing term
Transactions
10
How about
11
• ALL OR NOTHING!
• Ability to undo (abort)
• Easy to RETRY transactions
12
Atomicity
ACID
Are retries really safe with transactions?
13
Are retries really safe with transactions?
• Network failed while server tried to acknowledge commit to client. Retrying
means executing twice. Idempotency or de-duplication required in app!
• What if the error is due to overload?
• Transient or permanent error?
• What if transaction had side e
ff
ects? Send email again?
• What if client fails while retrying? Data lost?
14
• Certain statements about data (invariants) always true
• Database can’t promise
• Application speci
fi
c guarantees
• Most weakly de
fi
ned property in ACID
15
Consistency
ACID
Isolation
ACID
• Many clients access data at the same time
• Accessing same records you can run into concurrency problems (race)
• Database guarantees concurrently executing transactions are isolated
• Textbook de
fi
nitions- serializability - same result as running serially
• In practice, serializability rarely used because of performance penalty
• Actually snapshot isolation. Much weaker guarantee!
16
• Once committed, data written will not be forgotten
• Even if there is a hardware fault or database crashes
• Single node - write to HDD or SDD
• Databases usually uses a write ahead log & dirty cached pages
• Replicated databases - written to multiple nodes, wait until that happens!
• No such thing as perfect durability
ACID
Durability
17 Picture: https://www.alphr.com/tell-regular-or-ssd-hard-drive/
Implementing Transactions
18
Implementing Transactions
Balance between two problems
Improve E
ffi
ciency Preserve Correctness
Allow transactions to
execute concurrently
Ensure concurrently executing
transactions preserve ACID properties
19
Implementing Transactions
Balance between two problems
Improve E
ffi
ciency Preserve Correctness
Allow transactions to
execute concurrently
Ensure concurrently executing
transactions preserve ACID properties
Concurrently executing transactions can cause read & write anomalies
Isolation levels
Concurrency Control
Presence or absence of read & write anomalies
How transactions are scheduled & executed
20
21
Single Node Transactions
Storage Engine’s responsibility
Distributed Transactions
22
What if multiple nodes are
involved in a Transaction?
23
Send a commit request to each node & independently commit?
24
25
Send a commit request to each node & independently commit?
• Some SUCCESS, some FAILURES!
• Inconsistency between nodes
• Abort if some FAILURES?
• But you can’t go back on a committed promise!
• How about a compensating transaction to o
ff
set changes?
• Where does this responsibility sit? DB or App?
• OR commit only if everyone promises to commit?
Atomic Commitment
26
Atomic Commitment
• A transaction will not commit even if one of the participating votes against it.
• Failed processes have to reach the same conclusion as the rest of the cohort.
• Does not work in the case of Byzantine failures- process can’t lie!
• Cohorts can not choose, in
fl
uence or change proposed transaction, they can
only vote on whether or not they are willing to execute it.
• Executed by transaction manager or coordinator
• Example: MySQL , Postgres, dynamoDB, spanner, Kafka for producer and
consumer interactions.
27
Two Phase Commit
,
28
Two Phase Commit
• Coordinator (or transaction manager) a library within database server
• When database is ready to commit, coordinator starts phase 1
• Coordinate sends prepare request to each node. Are you able to commit?
• Coordinator tracks response from each participant
• If all participants vote YES , coordinator sends COMMIT request in phase 2
• If any participant says NO, coordinator sends ABORT to all nodes in phase 2
• Coordinator must write decision in its log on disk to handle crashes
29
Two Phase Commit
,
Crash (
fi
re)
30
Coordinator Failures
Two Phase Commit
• Two points of no return
• 1. If Participant says YES, it has to commit if coordinator asks to.
• 2. If coordinator decides once, decision is irrevocable
• If participant said yes and didn’t hear back from coordinator, wait forever!
• Coordinator must persist decision before it sends participants
• If no COMMIT record persisted in coordinator, abort on recovery
31
Three Phase Commit?
• 2PC is a blocking protocol
• 3PC is non blocking
• Di
ffi
cult to implement in practice. Not well adopted!
• 2 PC quite well adopted in spite of known problems.
32
Distributed Transactions in Practice
• Carries a heavy performance penalty
• Additional fsync required for crash recovery
• Addition network round trips
• Distributed Transactions in MySQL are reported to be over 10 times slower
than single node transactions.
33
Other Choices?
• Single leader? Everyone else executes same transactions in same order!
• Manually selected leader?
• Automatic selection of leader?
• O
ffl
oaded same problem to di
ff
erent time. Well less frequently!
• Use Consensus Algorithms: Zookeeper (ZAB), etcd (Raft) , Paxos?
• Global transaction order by reaching consensus on sequencer? Calvin(FaunaDB)
• 2PC over consensus groups per shard? Enter Google’s Spanner!
34
Transactions in Modern Databases
35
Amazon Aurora
36
Quick Overview
• Fully managed relational RDS
• Service Oriented Design
• Separation of Compute, storage
• multi-tenant scale out storage
• Segmented redo log
• Throughput 5x MySQL, 3x Postgres
Amazon Aurora
37
Aurora Functional Separation
DB instance
Query Processing
Access Methods
Transactions
Locking
Page Cache
Undo Management
Storage
fl
eet
Redo logging
Materialisation of data blocks
Garbage collection
Backup / Restore
38
Aurora: Quorum Style distributed coordination
Not 2PC, to avoid network chatter!
Read set & write set must overlap on at least one copy
Write set must overlap with previous write sets
39
Amazon DynamoDB
40
Dynamo DB
Highly available, weaker consistency
• Always “on” Key Value store, single key operations
• Sacri
fi
ce consistency under failure scenarios. Eventually consistent!
• Extensive use of object versioning, branching OK, resolve on read
• Example: shopping cart; merges carts. Can’t loose write, deleted can appear
• Consistency among replicas using quorum like technique (sloppy quorum)
• Gossip based distributed failure detection (hinted hando
ff
s)
41
Dynamo DB
Sloppy Quorum & hinted hando
f
• Each data item is replicated at N hosts. N distinct physical nodes
• List of nodes storing a key is called it’s preference list
• R : minimum no of nodes in successful read operation
• W: minimum no of nodes in successful write operation
42
Dynamo DB
Sloppy Quorum & hinted hando
f
• Each data item is replicated at N hosts. N distinct physical nodes
• List of nodes storing a key is called it’s preference list
• R : minimum no of nodes in successful read operation
• W: minimum no of nodes in successful write operation
43
44
customers
inventory
orders
Transaction coordinator
DynamoDB
45 https://www.infoq.com/articles/amazon-dynamodb-transactions/
Transaction coordinator failure/recovery
DynamoDB
46 https://www.infoq.com/articles/amazon-dynamodb-transactions/
Google Spanner
47
Spanner
Google’s globally distributed SQL* database
• Also inspiration for cockroachDB and yugabyteDB
• Tables with rows, columns and versioned values
• Supports transactions and SQL based query language
• Replication con
fi
gs dynamically controlled at
fi
ne grain by apps - which data-
centre’s to use, how far from users(read latency), how far are replicas (write
latency), how many replicas
• Clients automatically failover between replicas
• Data dynamically moved between data-centres to balance resources
48
49
Span server stack & transactions
50
51
References
• Designing Data-Intensive Applications ( Chapter 7 & 9) By Martin Kleppmann
• Database Internals (Chapter 5 & 13 ) By Alex Petrov
52
Books
• Amazon Aurora: Design considerations for high throughput cloud native relational databases
• Amazon Aurora: On avoiding distributed consensus….
• Dynamo: Amazon’s highly available key value store
• Distributed Transactions at scale in Amazon DynamoDB
• Spanner : Google’s Globally Distributed Database
Whitepapers
https://www.infoq.com/articles/amazon-dynamodb-transactions/
Blog
Questions?
Staying in touch:
https://www.linkedin.com/in/shivjijha
https://youtube.com/@ShivjiKumarJha
https://www.slideshare.net/shiv4289/presentations
https://t.me/theDbShots
53

More Related Content

What's hot

Query Compilation in Impala
Query Compilation in ImpalaQuery Compilation in Impala
Query Compilation in Impala
Cloudera, Inc.
 
MariaDB Galera Cluster
MariaDB Galera ClusterMariaDB Galera Cluster
MariaDB Galera Cluster
Abdul Manaf
 

What's hot (20)

Evolution of MongoDB Replicaset and Its Best Practices
Evolution of MongoDB Replicaset and Its Best PracticesEvolution of MongoDB Replicaset and Its Best Practices
Evolution of MongoDB Replicaset and Its Best Practices
 
InnoDB Internal
InnoDB InternalInnoDB Internal
InnoDB Internal
 
Run Apache Spark on Kubernetes in Large Scale_ Challenges and Solutions-2.pdf
Run Apache Spark on Kubernetes in Large Scale_ Challenges and Solutions-2.pdfRun Apache Spark on Kubernetes in Large Scale_ Challenges and Solutions-2.pdf
Run Apache Spark on Kubernetes in Large Scale_ Challenges and Solutions-2.pdf
 
Learning from google megastore (Part-1)
Learning from google megastore (Part-1)Learning from google megastore (Part-1)
Learning from google megastore (Part-1)
 
Apache Iceberg - A Table Format for Hige Analytic Datasets
Apache Iceberg - A Table Format for Hige Analytic DatasetsApache Iceberg - A Table Format for Hige Analytic Datasets
Apache Iceberg - A Table Format for Hige Analytic Datasets
 
PostgreSQL replication
PostgreSQL replicationPostgreSQL replication
PostgreSQL replication
 
PostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized WorldPostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized World
 
The Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization OpportunitiesThe Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization Opportunities
 
PostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability MethodsPostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability Methods
 
Thoughts on kafka capacity planning
Thoughts on kafka capacity planningThoughts on kafka capacity planning
Thoughts on kafka capacity planning
 
PostgreSQL HA
PostgreSQL   HAPostgreSQL   HA
PostgreSQL HA
 
Query Compilation in Impala
Query Compilation in ImpalaQuery Compilation in Impala
Query Compilation in Impala
 
The Volcano/Cascades Optimizer
The Volcano/Cascades OptimizerThe Volcano/Cascades Optimizer
The Volcano/Cascades Optimizer
 
MariaDB Galera Cluster
MariaDB Galera ClusterMariaDB Galera Cluster
MariaDB Galera Cluster
 
InnoDB Performance Optimisation
InnoDB Performance OptimisationInnoDB Performance Optimisation
InnoDB Performance Optimisation
 
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
 
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Wars of MySQL Cluster ( InnoDB Cluster VS Galera ) Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
 
Galera cluster for high availability
Galera cluster for high availability Galera cluster for high availability
Galera cluster for high availability
 
The Impala Cookbook
The Impala CookbookThe Impala Cookbook
The Impala Cookbook
 
Hive: Loading Data
Hive: Loading DataHive: Loading Data
Hive: Loading Data
 

Similar to Navigating Transactions: ACID Complexity in Modern Databases

Intro to Big Data and NoSQL
Intro to Big Data and NoSQLIntro to Big Data and NoSQL
Intro to Big Data and NoSQL
Don Demcsak
 
Big Data (NJ SQL Server User Group)
Big Data (NJ SQL Server User Group)Big Data (NJ SQL Server User Group)
Big Data (NJ SQL Server User Group)
Don Demcsak
 

Similar to Navigating Transactions: ACID Complexity in Modern Databases (20)

Intro to Big Data and NoSQL
Intro to Big Data and NoSQLIntro to Big Data and NoSQL
Intro to Big Data and NoSQL
 
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedInJay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
 
Voldemort Nosql
Voldemort NosqlVoldemort Nosql
Voldemort Nosql
 
Geek Sync | Top 5 Tips to Keep Always On Always Humming and Users Happy
Geek Sync | Top 5 Tips to Keep Always On Always Humming and Users HappyGeek Sync | Top 5 Tips to Keep Always On Always Humming and Users Happy
Geek Sync | Top 5 Tips to Keep Always On Always Humming and Users Happy
 
Hbase hive pig
Hbase hive pigHbase hive pig
Hbase hive pig
 
A Closer Look at Apache Kudu
A Closer Look at Apache KuduA Closer Look at Apache Kudu
A Closer Look at Apache Kudu
 
Kafka at scale facebook israel
Kafka at scale   facebook israelKafka at scale   facebook israel
Kafka at scale facebook israel
 
How to Build a Compute Cluster
How to Build a Compute ClusterHow to Build a Compute Cluster
How to Build a Compute Cluster
 
Webinar: How MongoDB is Used to Manage Reference Data - May 2014
Webinar: How MongoDB is Used to Manage Reference Data - May 2014Webinar: How MongoDB is Used to Manage Reference Data - May 2014
Webinar: How MongoDB is Used to Manage Reference Data - May 2014
 
#GeodeSummit - Where Does Geode Fit in Modern System Architectures
#GeodeSummit - Where Does Geode Fit in Modern System Architectures#GeodeSummit - Where Does Geode Fit in Modern System Architectures
#GeodeSummit - Where Does Geode Fit in Modern System Architectures
 
Robust ha solutions with proxysql
Robust ha solutions with proxysqlRobust ha solutions with proxysql
Robust ha solutions with proxysql
 
Building Big Data Streaming Architectures
Building Big Data Streaming ArchitecturesBuilding Big Data Streaming Architectures
Building Big Data Streaming Architectures
 
Hbase hivepig
Hbase hivepigHbase hivepig
Hbase hivepig
 
Big Data (NJ SQL Server User Group)
Big Data (NJ SQL Server User Group)Big Data (NJ SQL Server User Group)
Big Data (NJ SQL Server User Group)
 
Scaling tappsi
Scaling tappsiScaling tappsi
Scaling tappsi
 
Patterns of Distributed Application Design
Patterns of Distributed Application DesignPatterns of Distributed Application Design
Patterns of Distributed Application Design
 
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
 
Select Stars: A DBA's Guide to Azure Cosmos DB (Chicago Suburban SQL Server U...
Select Stars: A DBA's Guide to Azure Cosmos DB (Chicago Suburban SQL Server U...Select Stars: A DBA's Guide to Azure Cosmos DB (Chicago Suburban SQL Server U...
Select Stars: A DBA's Guide to Azure Cosmos DB (Chicago Suburban SQL Server U...
 
Tech Talk Series, Part 2: Why is sharding not smart to do in MySQL?
Tech Talk Series, Part 2: Why is sharding not smart to do in MySQL?Tech Talk Series, Part 2: Why is sharding not smart to do in MySQL?
Tech Talk Series, Part 2: Why is sharding not smart to do in MySQL?
 
Reduced instruction set computers
Reduced instruction set computersReduced instruction set computers
Reduced instruction set computers
 

More from Shivji Kumar Jha

Pulsar Summit Asia 2022 - Keeping on top of hybrid cloud usage with Pulsar
Pulsar Summit Asia 2022 - Keeping on top of hybrid cloud usage with PulsarPulsar Summit Asia 2022 - Keeping on top of hybrid cloud usage with Pulsar
Pulsar Summit Asia 2022 - Keeping on top of hybrid cloud usage with Pulsar
Shivji Kumar Jha
 

More from Shivji Kumar Jha (18)

Druid Summit 2023 : Changing Druid Ingestion from 3 hours to 5 minutes
Druid Summit 2023 : Changing Druid Ingestion from 3 hours to 5 minutesDruid Summit 2023 : Changing Druid Ingestion from 3 hours to 5 minutes
Druid Summit 2023 : Changing Druid Ingestion from 3 hours to 5 minutes
 
osi-oss-dbs.pptx
osi-oss-dbs.pptxosi-oss-dbs.pptx
osi-oss-dbs.pptx
 
pulsar-platformatory-meetup-2.pptx
pulsar-platformatory-meetup-2.pptxpulsar-platformatory-meetup-2.pptx
pulsar-platformatory-meetup-2.pptx
 
Pulsar Summit Asia 2022 - Streaming wars and How Apache Pulsar is acing the b...
Pulsar Summit Asia 2022 - Streaming wars and How Apache Pulsar is acing the b...Pulsar Summit Asia 2022 - Streaming wars and How Apache Pulsar is acing the b...
Pulsar Summit Asia 2022 - Streaming wars and How Apache Pulsar is acing the b...
 
Pulsar Summit Asia 2022 - Keeping on top of hybrid cloud usage with Pulsar
Pulsar Summit Asia 2022 - Keeping on top of hybrid cloud usage with PulsarPulsar Summit Asia 2022 - Keeping on top of hybrid cloud usage with Pulsar
Pulsar Summit Asia 2022 - Keeping on top of hybrid cloud usage with Pulsar
 
Pulsar summit asia 2021: Designing Pulsar for Isolation
Pulsar summit asia 2021: Designing Pulsar for IsolationPulsar summit asia 2021: Designing Pulsar for Isolation
Pulsar summit asia 2021: Designing Pulsar for Isolation
 
Event sourcing Live 2021: Streaming App Changes to Event Store
Event sourcing Live 2021: Streaming App Changes to Event StoreEvent sourcing Live 2021: Streaming App Changes to Event Store
Event sourcing Live 2021: Streaming App Changes to Event Store
 
Apache Con 2021 Structured Data Streaming
Apache Con 2021 Structured Data StreamingApache Con 2021 Structured Data Streaming
Apache Con 2021 Structured Data Streaming
 
Apache Con 2021 : Apache Bookkeeper Key Value Store and use cases
Apache Con 2021 : Apache Bookkeeper Key Value Store and use casesApache Con 2021 : Apache Bookkeeper Key Value Store and use cases
Apache Con 2021 : Apache Bookkeeper Key Value Store and use cases
 
Pulsar Summit Asia - Structured Data Stream with Apache Pulsar
Pulsar Summit Asia - Structured Data Stream with Apache PulsarPulsar Summit Asia - Structured Data Stream with Apache Pulsar
Pulsar Summit Asia - Structured Data Stream with Apache Pulsar
 
Pulsar Summit Asia - Running a secure pulsar cluster
Pulsar Summit Asia -  Running a secure pulsar clusterPulsar Summit Asia -  Running a secure pulsar cluster
Pulsar Summit Asia - Running a secure pulsar cluster
 
lessons from managing a pulsar cluster
 lessons from managing a pulsar cluster lessons from managing a pulsar cluster
lessons from managing a pulsar cluster
 
FOSSASIA 2015: MySQL Group Replication
FOSSASIA 2015: MySQL Group ReplicationFOSSASIA 2015: MySQL Group Replication
FOSSASIA 2015: MySQL Group Replication
 
MySQL High Availability with Replication New Features
MySQL High Availability with Replication New FeaturesMySQL High Availability with Replication New Features
MySQL High Availability with Replication New Features
 
MySQL Developer Day conference: MySQL Replication and Scalability
MySQL Developer Day conference: MySQL Replication and ScalabilityMySQL Developer Day conference: MySQL Replication and Scalability
MySQL Developer Day conference: MySQL Replication and Scalability
 
MySQL User Camp: MySQL Cluster
MySQL User Camp: MySQL ClusterMySQL User Camp: MySQL Cluster
MySQL User Camp: MySQL Cluster
 
MySQL User Camp: GTIDs
MySQL User Camp: GTIDsMySQL User Camp: GTIDs
MySQL User Camp: GTIDs
 
Open source India - MySQL Labs: Multi-Source Replication
Open source India - MySQL Labs: Multi-Source ReplicationOpen source India - MySQL Labs: Multi-Source Replication
Open source India - MySQL Labs: Multi-Source Replication
 

Recently uploaded

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Recently uploaded (20)

%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 

Navigating Transactions: ACID Complexity in Modern Databases

  • 1. Shivji Kumar Jha Navigating Transactions ACID Complexity in Modern Databases 1
  • 2. Data Platforms & OSS • Databases, streams, app architecture • Loves open source software (OSS) • And communities (meetups) • Regular speaker ( talk # 23) • Sta ff Engineer at Nutanix Shivji Kumar Jha https://www.linkedin.com/in/shivjijha https://youtube.com/@ShivjiKumarJha https://t.me/theDbShots 2
  • 3. • Transactions & ACID • Implementing Transactions • Distributed transactions • Cloud scale databases Contents 3
  • 5. Transactions Historical Perspective Almost all relational and even some non relational databases Most of them follow system R - first SQL DB by IBM in 1975. General ideas has remained same over 45+ years MySQL, Postgres, Oracle, SQL server have similar transactions 5
  • 6. Transactions Historical Perspective Transactions are antithesis of scalability Large scale systems have to abandon transaction Go for good performance and high availability 6 Transactions are essential requirements for serious applications with valuable data NoSQL Camp SQL Camp
  • 7. Transactions Historical Perspective Transactions are antithesis of scalability Large scale systems have to abandon transaction Go for good performance and high availability 7 Transactions are essential requirements for serious applications with valuable data NoSQL Camp SQL Camp Both are exaggerated! Trade-offs!
  • 8. 8 Coined in 1983 by Theo Harder and Andreas Reuter
  • 9. Atomicity Consistency Isolation Durability 9 Coined in 1983 by Theo Harder and Andreas Reuter
  • 10. The slippery slope! In practice, one database’s implementation of ACID does not equal another’s implementation For example, a lot of ambiguity in meaning of “isolation” Devil is in details! When a system claims ACID, unclear what guarantees it provides ACID has unfortunately become a marketing term Transactions 10
  • 12. • ALL OR NOTHING! • Ability to undo (abort) • Easy to RETRY transactions 12 Atomicity ACID
  • 13. Are retries really safe with transactions? 13
  • 14. Are retries really safe with transactions? • Network failed while server tried to acknowledge commit to client. Retrying means executing twice. Idempotency or de-duplication required in app! • What if the error is due to overload? • Transient or permanent error? • What if transaction had side e ff ects? Send email again? • What if client fails while retrying? Data lost? 14
  • 15. • Certain statements about data (invariants) always true • Database can’t promise • Application speci fi c guarantees • Most weakly de fi ned property in ACID 15 Consistency ACID
  • 16. Isolation ACID • Many clients access data at the same time • Accessing same records you can run into concurrency problems (race) • Database guarantees concurrently executing transactions are isolated • Textbook de fi nitions- serializability - same result as running serially • In practice, serializability rarely used because of performance penalty • Actually snapshot isolation. Much weaker guarantee! 16
  • 17. • Once committed, data written will not be forgotten • Even if there is a hardware fault or database crashes • Single node - write to HDD or SDD • Databases usually uses a write ahead log & dirty cached pages • Replicated databases - written to multiple nodes, wait until that happens! • No such thing as perfect durability ACID Durability 17 Picture: https://www.alphr.com/tell-regular-or-ssd-hard-drive/
  • 19. Implementing Transactions Balance between two problems Improve E ffi ciency Preserve Correctness Allow transactions to execute concurrently Ensure concurrently executing transactions preserve ACID properties 19
  • 20. Implementing Transactions Balance between two problems Improve E ffi ciency Preserve Correctness Allow transactions to execute concurrently Ensure concurrently executing transactions preserve ACID properties Concurrently executing transactions can cause read & write anomalies Isolation levels Concurrency Control Presence or absence of read & write anomalies How transactions are scheduled & executed 20
  • 21. 21 Single Node Transactions Storage Engine’s responsibility
  • 23. What if multiple nodes are involved in a Transaction? 23
  • 24. Send a commit request to each node & independently commit? 24
  • 25. 25 Send a commit request to each node & independently commit? • Some SUCCESS, some FAILURES! • Inconsistency between nodes • Abort if some FAILURES? • But you can’t go back on a committed promise! • How about a compensating transaction to o ff set changes? • Where does this responsibility sit? DB or App? • OR commit only if everyone promises to commit?
  • 27. Atomic Commitment • A transaction will not commit even if one of the participating votes against it. • Failed processes have to reach the same conclusion as the rest of the cohort. • Does not work in the case of Byzantine failures- process can’t lie! • Cohorts can not choose, in fl uence or change proposed transaction, they can only vote on whether or not they are willing to execute it. • Executed by transaction manager or coordinator • Example: MySQL , Postgres, dynamoDB, spanner, Kafka for producer and consumer interactions. 27
  • 29. Two Phase Commit • Coordinator (or transaction manager) a library within database server • When database is ready to commit, coordinator starts phase 1 • Coordinate sends prepare request to each node. Are you able to commit? • Coordinator tracks response from each participant • If all participants vote YES , coordinator sends COMMIT request in phase 2 • If any participant says NO, coordinator sends ABORT to all nodes in phase 2 • Coordinator must write decision in its log on disk to handle crashes 29
  • 31. Coordinator Failures Two Phase Commit • Two points of no return • 1. If Participant says YES, it has to commit if coordinator asks to. • 2. If coordinator decides once, decision is irrevocable • If participant said yes and didn’t hear back from coordinator, wait forever! • Coordinator must persist decision before it sends participants • If no COMMIT record persisted in coordinator, abort on recovery 31
  • 32. Three Phase Commit? • 2PC is a blocking protocol • 3PC is non blocking • Di ffi cult to implement in practice. Not well adopted! • 2 PC quite well adopted in spite of known problems. 32
  • 33. Distributed Transactions in Practice • Carries a heavy performance penalty • Additional fsync required for crash recovery • Addition network round trips • Distributed Transactions in MySQL are reported to be over 10 times slower than single node transactions. 33
  • 34. Other Choices? • Single leader? Everyone else executes same transactions in same order! • Manually selected leader? • Automatic selection of leader? • O ffl oaded same problem to di ff erent time. Well less frequently! • Use Consensus Algorithms: Zookeeper (ZAB), etcd (Raft) , Paxos? • Global transaction order by reaching consensus on sequencer? Calvin(FaunaDB) • 2PC over consensus groups per shard? Enter Google’s Spanner! 34
  • 35. Transactions in Modern Databases 35
  • 37. Quick Overview • Fully managed relational RDS • Service Oriented Design • Separation of Compute, storage • multi-tenant scale out storage • Segmented redo log • Throughput 5x MySQL, 3x Postgres Amazon Aurora 37
  • 38. Aurora Functional Separation DB instance Query Processing Access Methods Transactions Locking Page Cache Undo Management Storage fl eet Redo logging Materialisation of data blocks Garbage collection Backup / Restore 38
  • 39. Aurora: Quorum Style distributed coordination Not 2PC, to avoid network chatter! Read set & write set must overlap on at least one copy Write set must overlap with previous write sets 39
  • 41. Dynamo DB Highly available, weaker consistency • Always “on” Key Value store, single key operations • Sacri fi ce consistency under failure scenarios. Eventually consistent! • Extensive use of object versioning, branching OK, resolve on read • Example: shopping cart; merges carts. Can’t loose write, deleted can appear • Consistency among replicas using quorum like technique (sloppy quorum) • Gossip based distributed failure detection (hinted hando ff s) 41
  • 42. Dynamo DB Sloppy Quorum & hinted hando f • Each data item is replicated at N hosts. N distinct physical nodes • List of nodes storing a key is called it’s preference list • R : minimum no of nodes in successful read operation • W: minimum no of nodes in successful write operation 42
  • 43. Dynamo DB Sloppy Quorum & hinted hando f • Each data item is replicated at N hosts. N distinct physical nodes • List of nodes storing a key is called it’s preference list • R : minimum no of nodes in successful read operation • W: minimum no of nodes in successful write operation 43
  • 46. Transaction coordinator failure/recovery DynamoDB 46 https://www.infoq.com/articles/amazon-dynamodb-transactions/
  • 48. Spanner Google’s globally distributed SQL* database • Also inspiration for cockroachDB and yugabyteDB • Tables with rows, columns and versioned values • Supports transactions and SQL based query language • Replication con fi gs dynamically controlled at fi ne grain by apps - which data- centre’s to use, how far from users(read latency), how far are replicas (write latency), how many replicas • Clients automatically failover between replicas • Data dynamically moved between data-centres to balance resources 48
  • 49. 49
  • 50. Span server stack & transactions 50
  • 51. 51
  • 52. References • Designing Data-Intensive Applications ( Chapter 7 & 9) By Martin Kleppmann • Database Internals (Chapter 5 & 13 ) By Alex Petrov 52 Books • Amazon Aurora: Design considerations for high throughput cloud native relational databases • Amazon Aurora: On avoiding distributed consensus…. • Dynamo: Amazon’s highly available key value store • Distributed Transactions at scale in Amazon DynamoDB • Spanner : Google’s Globally Distributed Database Whitepapers https://www.infoq.com/articles/amazon-dynamodb-transactions/ Blog