SlideShare a Scribd company logo
1 of 49
The Dude’s
guide to
database
consistency
Has this ever happened to you before?
Well It has happened to me
Database Consistency
Consistency and Histories
Invariants are your fixed set of requirements that system should not violate.
For example: client should never see an older copy of data.
When a system holds true for all the assumed invariants the system is said to be
consistent.
A consistency model is set of all allowed histories.
Example
What is the output?
How will you validate the system is correct?
A consistency
model is set of
all allowed
histories.
How does history look like?
Consistency Models
Source https://jepsen.io/consistency
They are used to solve some
problems.
They are often organized in
terms of “anomalies” that they
avoid.
What are these problems?
Consistency Model What problems it
solves? And what it
won’t solve.
Read Uncommitted
Source https://jepsen.io/consistency
Antidote to dirty writes
In a transaction when a value is changed meanwhile other transaction overwrites
it and commits it.
What happens if T1 wants to rollback? Should x = 0 or x = 2?
What are dirty writes?
Read Uncommitted Solves dirty writes
Still allows dirty
reads
Read Committed
Source https://jepsen.io/consistency
Antidote to dirty writes and
dirty reads
In a transaction when an uncommitted value is observed.
What are dirty reads?
Read Committed Solves dirty writes
and dirty reads
It is the most widely used lowest level
consistency model.
Chaos Read
Uncommitted
Read
Committed
Cursor Stability
Source https://jepsen.io/consistency
Antidote to dirty writes, dirty
reads and lost updates
There is no Dirty Write since T2 commits before T1 writes x. There is no Dirty
Read since there is no read after a write. Nevertheless, at the end of this
sequence T2‘s update will be lost, even if T2 commits.
What are lost updates?
It introduces the concept of a cursor, which refers to a particular object being
accessed by a transaction.
Transactions may have multiple cursors.
When a transaction reads an object using a cursor, that object cannot be modified
by any other transaction until the cursor is released, or the transaction commits.
How lost updates are mitigated by Cursor Stability?
Cursor stability Solves dirty writes,
dirty reads and lost
updates
Monotonic Atomic
View
Source https://jepsen.io/consistency
Provides the A in the ACID.
How much should I observe
from other transactions?
Once some effects of a txn A are observed by txn B, then all effects of A are
visible to B. Also if another later version is observed then all the versions from that
transaction will be visible.
Only committed values are observed as monotonic atomic views implies read
committed.
Isolation effect of “Atomicity” in ACID — how much of a committed transaction
should be visible to others — all or nothing.
What is monotonic atomic views?
Repeatable Read
Source https://jepsen.io/consistency
Antidote to dirty writes, dirty
reads, lost updates, non-
repeatable reads, read skew
and write skew
When a transaction reads something and later the same read returns different
value.
What are non-repeatable reads?
You started transaction from your spring boot application
Default level was set to READ COMMITTED.
You read a value and took some decision. This triggered an update.
In the validation phase you did another read.
Values mismatched.
Someone changed your value and the decision you took was wrong.
Remedy, Use higher consistency level or use SELECT FOR UPDATE
Real life use case
Snapshot Isolation
Source https://jepsen.io/consistency
Antidote to dirty writes, dirty
reads, lost updates, non-
repeatable reads, read skew
and write skew
In a snapshot isolated system, each transaction appears to operate on an
independent, consistent snapshot of the database. Its changes are visible only to
that transaction until commit time, when all changes become visible atomically. If
transaction T1 has modified an object x, and another transaction T2 committed a
write to x after T1’s snapshot began, and before T1’s commit, then T1 must abort.
What is snapshot isolation?
Serializable
Source https://jepsen.io/consistency
Antidote to dirty writes, dirty
reads, lost updates, non-
repeatable reads, read skew,
write skew and phantom
reads
A Phantom occurs when a transaction does a predicate-based read (e.g.
SELECT… WHERE P) and another transaction writes a data item matched by that
predicate while the first transaction is still in flight.
What are phantom reads?
If each transaction is correct by itself, then a schedule that comprises any serial
execution of these transactions is correct: "Serial" means that transactions do not
overlap in time and cannot interfere with each other, i.e, complete isolation
between each other exists. Any order of the transactions is legitimate, if no
dependencies among them exist. As a result, a schedule that comprises any
execution (not necessarily serial) that is equivalent (in its outcome) to any serial
execution of these transactions, is correct.
What is serializable isolation level?
As serializability does not involve any transaction interleaving, any transaction
doing predicate queries won’t get affected by other transactions.
Other option is index crabbing.
How phantom reads are handled?
Linearizable
Source https://jepsen.io/consistency
strongest single-object
consistency model
Implies that every operation appears to take place atomically, in some order,
consistent with the real-time ordering of those operations: e.g., if operation A
completes before operation B begins, then B should logically take effect after A.
Points to note:
1. One object
2. Atomic, indivisible steps, all or nothing
3. Real time constraint if something happens before another then it should
reflect accordingly
4. Usually for single object using one key or set of keys
What is linearizability?
1. Multi object.
2. Multi operations.
3. Arbitrary Order.
4. No overlap in time.
5. No real time constraint.
6. Desired by database
community
1. Single object.
2. Single operation.
3. Real time Order.
4. No overlap in time.
5. Real time constraint.
6. Desired by distributed
systems community
Strict Serializable
Source https://jepsen.io/consistency
Implies Serializability and
Linearizability
Baseball as an example for
Replicated database consistency
Source https://jepsen.io/consistency
Source https://www.microsoft.com/en-
us/research/wp-
content/uploads/2011/10/ConsistencyAndBaseball
Report.pdf
The game starts with the score of 0-0. The visitors bat first and remain at bat until
they make three outs. Then the home team bats until it makes three outs.
Baseball
7th Innings
Different role players in baseball
Different consistency levels for different role
players in baseball
We saw different consistency models ...
But, what is the point dude?
What is the point dude?
Identify various actors of the system.
Based on the actors identify the problems that different actors of the
system can live with and the problems that are bad for business.
Then, please use the suitable database.
Convert the needed invariants of your system and the anomalies the
system can live with into a consistency model.
Thank You Dudes
If after so many slides. If you still feel like saying ….
You: I will just use MongoDB. It is a web scale database.
Dude:
Dude: Thank You

More Related Content

Similar to The dude's guide to database consistency

Transactions and Concurrency Control
Transactions and Concurrency ControlTransactions and Concurrency Control
Transactions and Concurrency ControlDilum Bandara
 
Transactional OSGi Applications Done Right
Transactional OSGi Applications Done RightTransactional OSGi Applications Done Right
Transactional OSGi Applications Done RightClément Escoffier
 
Svetlin Nakov - Database Transactions
Svetlin Nakov - Database TransactionsSvetlin Nakov - Database Transactions
Svetlin Nakov - Database TransactionsSvetlin Nakov
 
How does ethereum work, anyway?
How does ethereum work, anyway?How does ethereum work, anyway?
How does ethereum work, anyway?philrussell001
 
DC_M5_L2_Data Centric Consistency (1).pdf
DC_M5_L2_Data Centric Consistency (1).pdfDC_M5_L2_Data Centric Consistency (1).pdf
DC_M5_L2_Data Centric Consistency (1).pdfDhruvSingh266810
 
Synchronous Reads Asynchronous Writes RubyConf 2009
Synchronous Reads Asynchronous Writes RubyConf 2009Synchronous Reads Asynchronous Writes RubyConf 2009
Synchronous Reads Asynchronous Writes RubyConf 2009pauldix
 
Hibernate concurrency
Hibernate concurrencyHibernate concurrency
Hibernate concurrencypriyank09
 
Distributed Database Design and Relational Query Language
Distributed Database Design and Relational Query LanguageDistributed Database Design and Relational Query Language
Distributed Database Design and Relational Query LanguageAAKANKSHA JAIN
 
Transactions in dbms
Transactions in dbmsTransactions in dbms
Transactions in dbmsNancy Gulati
 
Beyond the RTOS: A Better Way to Design Real-Time Embedded Software
Beyond the RTOS: A Better Way to Design Real-Time Embedded SoftwareBeyond the RTOS: A Better Way to Design Real-Time Embedded Software
Beyond the RTOS: A Better Way to Design Real-Time Embedded SoftwareMiro Samek
 
Transaction management DBMS
Transaction  management DBMSTransaction  management DBMS
Transaction management DBMSMegha Patel
 
Reliable Distributed Computing: The Price of Mastering Churn in Distributed S...
Reliable Distributed Computing: The Price of Mastering Churn in Distributed S...Reliable Distributed Computing: The Price of Mastering Churn in Distributed S...
Reliable Distributed Computing: The Price of Mastering Churn in Distributed S...Roberto Baldoni
 

Similar to The dude's guide to database consistency (20)

Transactions and Concurrency Control
Transactions and Concurrency ControlTransactions and Concurrency Control
Transactions and Concurrency Control
 
Transactional OSGi Applications Done Right
Transactional OSGi Applications Done RightTransactional OSGi Applications Done Right
Transactional OSGi Applications Done Right
 
24904 lecture11
24904 lecture1124904 lecture11
24904 lecture11
 
Svetlin Nakov - Database Transactions
Svetlin Nakov - Database TransactionsSvetlin Nakov - Database Transactions
Svetlin Nakov - Database Transactions
 
Sql server concurrency
Sql server concurrencySql server concurrency
Sql server concurrency
 
How does ethereum work, anyway?
How does ethereum work, anyway?How does ethereum work, anyway?
How does ethereum work, anyway?
 
Concurrency control
Concurrency controlConcurrency control
Concurrency control
 
DC_M5_L2_Data Centric Consistency (1).pdf
DC_M5_L2_Data Centric Consistency (1).pdfDC_M5_L2_Data Centric Consistency (1).pdf
DC_M5_L2_Data Centric Consistency (1).pdf
 
09 workflow
09 workflow09 workflow
09 workflow
 
Transactions
TransactionsTransactions
Transactions
 
Synchronous Reads Asynchronous Writes RubyConf 2009
Synchronous Reads Asynchronous Writes RubyConf 2009Synchronous Reads Asynchronous Writes RubyConf 2009
Synchronous Reads Asynchronous Writes RubyConf 2009
 
Unit06 dbms
Unit06 dbmsUnit06 dbms
Unit06 dbms
 
Hibernate concurrency
Hibernate concurrencyHibernate concurrency
Hibernate concurrency
 
Dbms voc 5 unit
Dbms voc 5 unitDbms voc 5 unit
Dbms voc 5 unit
 
Distributed Database Design and Relational Query Language
Distributed Database Design and Relational Query LanguageDistributed Database Design and Relational Query Language
Distributed Database Design and Relational Query Language
 
Transactions in dbms
Transactions in dbmsTransactions in dbms
Transactions in dbms
 
Beyond the RTOS: A Better Way to Design Real-Time Embedded Software
Beyond the RTOS: A Better Way to Design Real-Time Embedded SoftwareBeyond the RTOS: A Better Way to Design Real-Time Embedded Software
Beyond the RTOS: A Better Way to Design Real-Time Embedded Software
 
Transaction management DBMS
Transaction  management DBMSTransaction  management DBMS
Transaction management DBMS
 
Reliable Distributed Computing: The Price of Mastering Churn in Distributed S...
Reliable Distributed Computing: The Price of Mastering Churn in Distributed S...Reliable Distributed Computing: The Price of Mastering Churn in Distributed S...
Reliable Distributed Computing: The Price of Mastering Churn in Distributed S...
 
Transaction
TransactionTransaction
Transaction
 

Recently uploaded

100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptxAnupama Kate
 
VidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxVidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxolyaivanovalion
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsappssapnasaifi408
 
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls DubaiDubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls Dubaihf8803863
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts ServiceSapana Sha
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfMarinCaroMartnezBerg
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingNeil Barnes
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptSonatrach
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxJohnnyPlasten
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxStephen266013
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfLars Albertsson
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxolyaivanovalion
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptxthyngster
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusTimothy Spann
 
Introduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptxIntroduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptxfirstjob4
 

Recently uploaded (20)

100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx
 
VidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxVidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptx
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
 
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls DubaiDubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts Service
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdf
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data Storytelling
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
 
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptx
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docx
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdf
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptx
 
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in  KishangarhDelhi 99530 vip 56974 Genuine Escort Service Call Girls in  Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
 
E-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptxE-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptx
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and Milvus
 
Introduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptxIntroduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptx
 

The dude's guide to database consistency

  • 2. Has this ever happened to you before?
  • 3. Well It has happened to me
  • 5. Consistency and Histories Invariants are your fixed set of requirements that system should not violate. For example: client should never see an older copy of data. When a system holds true for all the assumed invariants the system is said to be consistent. A consistency model is set of all allowed histories.
  • 6. Example What is the output? How will you validate the system is correct?
  • 7. A consistency model is set of all allowed histories.
  • 8. How does history look like?
  • 9. Consistency Models Source https://jepsen.io/consistency They are used to solve some problems. They are often organized in terms of “anomalies” that they avoid.
  • 10. What are these problems?
  • 11. Consistency Model What problems it solves? And what it won’t solve.
  • 13. In a transaction when a value is changed meanwhile other transaction overwrites it and commits it. What happens if T1 wants to rollback? Should x = 0 or x = 2? What are dirty writes?
  • 14. Read Uncommitted Solves dirty writes Still allows dirty reads
  • 16. In a transaction when an uncommitted value is observed. What are dirty reads?
  • 17. Read Committed Solves dirty writes and dirty reads It is the most widely used lowest level consistency model.
  • 19. Cursor Stability Source https://jepsen.io/consistency Antidote to dirty writes, dirty reads and lost updates
  • 20. There is no Dirty Write since T2 commits before T1 writes x. There is no Dirty Read since there is no read after a write. Nevertheless, at the end of this sequence T2‘s update will be lost, even if T2 commits. What are lost updates?
  • 21. It introduces the concept of a cursor, which refers to a particular object being accessed by a transaction. Transactions may have multiple cursors. When a transaction reads an object using a cursor, that object cannot be modified by any other transaction until the cursor is released, or the transaction commits. How lost updates are mitigated by Cursor Stability?
  • 22. Cursor stability Solves dirty writes, dirty reads and lost updates
  • 23. Monotonic Atomic View Source https://jepsen.io/consistency Provides the A in the ACID. How much should I observe from other transactions?
  • 24. Once some effects of a txn A are observed by txn B, then all effects of A are visible to B. Also if another later version is observed then all the versions from that transaction will be visible. Only committed values are observed as monotonic atomic views implies read committed. Isolation effect of “Atomicity” in ACID — how much of a committed transaction should be visible to others — all or nothing. What is monotonic atomic views?
  • 25. Repeatable Read Source https://jepsen.io/consistency Antidote to dirty writes, dirty reads, lost updates, non- repeatable reads, read skew and write skew
  • 26. When a transaction reads something and later the same read returns different value. What are non-repeatable reads?
  • 27. You started transaction from your spring boot application Default level was set to READ COMMITTED. You read a value and took some decision. This triggered an update. In the validation phase you did another read. Values mismatched. Someone changed your value and the decision you took was wrong. Remedy, Use higher consistency level or use SELECT FOR UPDATE Real life use case
  • 28. Snapshot Isolation Source https://jepsen.io/consistency Antidote to dirty writes, dirty reads, lost updates, non- repeatable reads, read skew and write skew
  • 29. In a snapshot isolated system, each transaction appears to operate on an independent, consistent snapshot of the database. Its changes are visible only to that transaction until commit time, when all changes become visible atomically. If transaction T1 has modified an object x, and another transaction T2 committed a write to x after T1’s snapshot began, and before T1’s commit, then T1 must abort. What is snapshot isolation?
  • 30. Serializable Source https://jepsen.io/consistency Antidote to dirty writes, dirty reads, lost updates, non- repeatable reads, read skew, write skew and phantom reads
  • 31. A Phantom occurs when a transaction does a predicate-based read (e.g. SELECT… WHERE P) and another transaction writes a data item matched by that predicate while the first transaction is still in flight. What are phantom reads?
  • 32. If each transaction is correct by itself, then a schedule that comprises any serial execution of these transactions is correct: "Serial" means that transactions do not overlap in time and cannot interfere with each other, i.e, complete isolation between each other exists. Any order of the transactions is legitimate, if no dependencies among them exist. As a result, a schedule that comprises any execution (not necessarily serial) that is equivalent (in its outcome) to any serial execution of these transactions, is correct. What is serializable isolation level?
  • 33. As serializability does not involve any transaction interleaving, any transaction doing predicate queries won’t get affected by other transactions. Other option is index crabbing. How phantom reads are handled?
  • 35. Implies that every operation appears to take place atomically, in some order, consistent with the real-time ordering of those operations: e.g., if operation A completes before operation B begins, then B should logically take effect after A. Points to note: 1. One object 2. Atomic, indivisible steps, all or nothing 3. Real time constraint if something happens before another then it should reflect accordingly 4. Usually for single object using one key or set of keys What is linearizability?
  • 36. 1. Multi object. 2. Multi operations. 3. Arbitrary Order. 4. No overlap in time. 5. No real time constraint. 6. Desired by database community 1. Single object. 2. Single operation. 3. Real time Order. 4. No overlap in time. 5. Real time constraint. 6. Desired by distributed systems community
  • 38. Baseball as an example for Replicated database consistency Source https://jepsen.io/consistency Source https://www.microsoft.com/en- us/research/wp- content/uploads/2011/10/ConsistencyAndBaseball Report.pdf
  • 39. The game starts with the score of 0-0. The visitors bat first and remain at bat until they make three outs. Then the home team bats until it makes three outs. Baseball
  • 41. Different role players in baseball
  • 42. Different consistency levels for different role players in baseball
  • 43. We saw different consistency models ...
  • 44. But, what is the point dude?
  • 45. What is the point dude? Identify various actors of the system. Based on the actors identify the problems that different actors of the system can live with and the problems that are bad for business. Then, please use the suitable database. Convert the needed invariants of your system and the anomalies the system can live with into a consistency model. Thank You Dudes
  • 46. If after so many slides. If you still feel like saying ….
  • 47. You: I will just use MongoDB. It is a web scale database.
  • 48. Dude:

Editor's Notes

  1. Slides are pretty heavy. Atleast I thought the first slide should be good.
  2. All references are from the movie The Big Lebowski movie from which the philosophy of dudeism started.
  3. Over a year ago when I joined TW I was more interested in database. I wanted to enroll into courses and deeper my understanding about databases and in general distributed systems. Started enrolling into courses and realized the vocabulary used in academic courses is bizarre. What you think you know is always different from what you really know. It might make you feel perplexed
  4. These words in database academic papers are like street codes man without them you cannot hustle.
  5. We all know databases. I’m sure at least I hope so. I do not want to pull out wikipedia on you all.
  6. If I want to design a system I will have an objective for this system. There are certain things it must do and certain things it should not and there are other things it should not do but it might be outside the scope. Invariants are the requirements that a system should not violate.. For last defination we will understand in next slide.
  7. Simple ruby program. Output? How to validate it is correct? Could be seen as single register r/w with no concurrency Only one client in above history.
  8. HIstory is through which we validate our distributed systems or databases.
  9. From top to bottom. More consistency from bottom to top. Implies. Network Partition Explain Legend
  10. Dirty writes the anomaly no one wants.
  11. How can some other transaction overwrite the uncommitted value from another transaction?
  12. First transaction showed the first interest in the value. It should be locked.
  13. The bare minimum you could except from a database. <Show meme>
  14. T1 is working to withdraw 40 from x and deposit to y it will eventually comes 10 + 90 to satisfy x+y=100 constraint but T2 is able to observe the intermediate inconsistent state.
  15. Cursor stability is a consistency model which strengthens read committed by preventing lost updates. It introduces the concept of a cursor, which refers to a particular object being accessed by a transaction. Transactions may have multiple cursors. When a transaction reads an object using a cursor, that object cannot be modified by any other transaction until the cursor is released, or the transaction commits.
  16. SELECT FOR UPDATE
  17. First transaction showed the first interest in the value. It should be locked.
  18. All the previous anomalies were due to the fact that transactions saw something that they are not supposed to see or saw something from future or past. Let’s break the word.
  19. Give an example. Transaction saw something and things changed.
  20. First transaction showed the first interest in the value. It should be locked.
  21. Give brief explanation. Timestamps and stuff. <Show meme>
  22. How many of us remember this from college? It provides higher isolation as it only interleave unrelated transactions. The transactions appear to be in some serial order. But what order? To which linearizability will say <show meme> It solves phantom reads
  23. Serializability: different kind of operations multi-operation, multi-object, arbitrary total order, If order’s result is equivalent to serial order it is correct.
  24. Serializability: Give me real time constraint Linearizability: Give me multi object