ADVANCED DATABASE MANAGEMENT
SYSTEM
MODULE 9 – NOSQL
Lecture 5 – Consistency
01
Consistency
Consistency
● Consistency, states that data cannot be written that would violate the rules for valid data.
● If a certain action occurs that attempts to introduce inconsistent data, the entire action is
rolled back and an error returned to the user, and there are many types for consistency like
strong consistency and eventual consistency.
02
Update Consistency
Update Consistency
Write-write conflict
● Person x and person y want to update telephone number on website. Both will
have update rights
● Both person uses different format but at the same time they are updating phone
number.
● This issue is called write-write conflict (i.e.) two people updating same data item at
the same time.
● When these write reaches to server, the server will serialize them after one another.
● Server will use alphabetical order then x person’s update will done first then y
person’s update will done.
● So x person’s update is overwritten by y person’s update and the x person’s update
became the lost update.
Update Consistency
● Pessimistic Approach
○ It works by preventing conflicts from occurring by having locks
○ In order to change a value you need to acquire a lock and the system ensures that only
one client can get a lock at a time.
○ So person Y will see result of person x and then he will decide whether to make update or
not.
● Optimistic Approach
○ Let conflicts occur, detect them and take action to sort them out.
○ A common optimistic approach is a conditional update where any client that does an
update tests the value just before updating it to see if it’s changed since his last read.
○ In this case, X’s update would succeed but Y’s would fail.
○ The error would let Y know that he should look at the value again and decide whether to
attempt a further update.
Update Consistency
● Replication makes it much more likely to run into write-write conflicts.
● If different nodes have different copies of some data which can be independently updated,
then you’ll get conflicts unless you take specific measures to avoid them.
● Using a single node as the target for all writes for some data makes it much easier to
maintain update consistency.
03
Read Consistency
Read Consistency
● Having a data store that maintains update consistency is one thing, but it doesn’t guarantee
that readers of that data store will always get consistent responses to their requests.
● Let’s imagine we have an order with line items and a shipping charge. The shipping charge is
calculated based on the line items in the order.
● If we add a line item, we thus also need to recalculate and update the shipping charge.
● In a relational database, the shipping charge and line items will be in separate tables.
● The danger of inconsistency is that Martin adds a line item to his order, Pramod then reads the
line items and shipping charge, and then Martin updates the shipping charge.
● This is an inconsistent read or read-write conflict
Read Consistency
● We refer to this type of consistency as logical consistency: ensuring that different data items
make sense together.
● To avoid a logically inconsistent read-write conflict, relational databases support the notion of
transactions.
● A common claim we hear is that NoSQL databases don’t support transactions and thus can’t be
consistent.
● Secondly, aggregate-oriented databases do support atomic updates, but only within a single
aggregate.
● This means that you will have logical consistency within an aggregate but not between
aggregates.
Read Consistency
● This is another inconsistent read—but it’s a breach of a different form of consistency we call
replication consistency: ensuring that the same data item has the same value when read
from different replicas
04
Relaxing Consistency
Relaxing Consistency
● Consistency is a Good Thing—but, sadly, sometimes we have to sacrifice it.
● It is always possible to design a system to avoid inconsistencies, but often impossible to do
so without making unbearable sacrifices in other characteristics of the system
● Trading off consistency is a familiar concept even in single-server relational database
systems.
● Here, our principal tool to enforce consistency is the transaction, and transactions can
provide strong consistency guarantees.
● However, transaction systems usually come with the ability to relax isolation levels, allowing
queries to read data that hasn’t been committed yet.
Relaxing Consistency
● CAP Theorem
○ NoSQL can not provide consistency and high availability together.
○ This was first expressed by Eric Brewer in CAP Theorem.
○ CAP theorem states that we can only achieve at most two out of three guarantees for
a database: Consistency, Availability, and Partition Tolerance.
○ Consistency means that all nodes in the network see the same data at the same time.
○ Availability is a guarantee that every request receives a response about whether it was
successful or failed.
○ Partition Tolerance is a guarantee that the system continues to operate despite
arbitrary message loss or failure of part of the system.
Relaxing Consistency
05
Relaxing Durability
Relaxing Durability
● Most people would laugh at relaxing durability—after all, what is the point of a data store if it
can lose updates?
● There are cases where you may want to trade off some durability for higher performance.
● A failure of replication durability occurs when a node processes an update but fails before
that update is replicated to the other nodes.
● A simple case of this may happen if you have a master-slave distribution model where the
slaves appoint a new master automatically should the existing master fail.
● If a master does fail, any writes not passed onto the replicas will effectively become lost.
● So, as user will think update is succeeded as master have acknowledged it but due to failure
of master node updates are lost.
06
Quorums
Quorums
● One piece of data is stored in multiple nodes. So we need some sort of mechanism so that nodes
agree on a particular return value.
● Suppose we replicate the data on 3 nodes. Node 0,1 and 2.
● We made a written request to node 0. Data is written on Node 0 and Node 1 and 2 are waiting for
the data.
● Meanwhile, we have a read request for the newly inserted data but Node 0 fails.
● Since Node 0 fails it checks in Node 1 and 2. But the replicas are still not inserted in these nodes.
● So our database sends a data not found error which is false.
● Instead, the database should have sent database error.
● To avoid such issues we need a distributed consensus and one way to implement that is through
Quorum.
● If we have data on multiple nodes then we take the data with the latest timestamp. So even if one
of our nodes fails users can still read the data.

More Related Content

PPTX
UNIT II (1).pptx
PPTX
Replication in Distributed Systems
PPTX
Polyglot Persistence
PPTX
U1-NOSQL.pptx DIFFERENT TYPES OF NOSQL DATABASES
PPTX
NOSQL DATABASES UNIT-3 FOR ENGINEERING STUDENTS
PPTX
Consistency in NoSQL
PDF
Scaling a Core Banking Engine Using Apache Kafka | Peter Dudbridge, Thought M...
PDF
When NOT to use MongoDB
UNIT II (1).pptx
Replication in Distributed Systems
Polyglot Persistence
U1-NOSQL.pptx DIFFERENT TYPES OF NOSQL DATABASES
NOSQL DATABASES UNIT-3 FOR ENGINEERING STUDENTS
Consistency in NoSQL
Scaling a Core Banking Engine Using Apache Kafka | Peter Dudbridge, Thought M...
When NOT to use MongoDB

Similar to jjjjjjjjjjjjjjjjjjjjjjjjjjjjlecture 27.pptx (20)

PPT
ds7_con.ppt
PDF
Tech Winter Break @gdgkiit | System Design Essentials
PPTX
Module 2_ Distribution Model.pptx Notes
PPTX
Introduction to mongodb
PPTX
Storing the real world data
PPTX
Relational and non relational database 7
PPTX
Distribution Models.pptxgdfgdfgdfgfdgdfg
PPTX
Eventual consistency vs Strong consistency what is the difference
PPTX
CAP: Scaling, HA
PPTX
Chapter Introductionn to distributed system .pptx
PDF
Rails DB migrate SAFE.pdf
PPTX
MODULE 2 PPT distribution models, sharding,msp
PDF
System design fundamentals CAP.pdf
PDF
Lecture-04-Principles of data management.pdf
PDF
What could possibly go wrong
PDF
Scaling systems using change propagation across data stores
DOC
Software architecture case study - why and why not sql server replication
PPTX
Hbase hive pig
PPTX
NServiceBus - building a distributed system based on a messaging infrastructure
PDF
Kafka Reliable Data Delivery
ds7_con.ppt
Tech Winter Break @gdgkiit | System Design Essentials
Module 2_ Distribution Model.pptx Notes
Introduction to mongodb
Storing the real world data
Relational and non relational database 7
Distribution Models.pptxgdfgdfgdfgfdgdfg
Eventual consistency vs Strong consistency what is the difference
CAP: Scaling, HA
Chapter Introductionn to distributed system .pptx
Rails DB migrate SAFE.pdf
MODULE 2 PPT distribution models, sharding,msp
System design fundamentals CAP.pdf
Lecture-04-Principles of data management.pdf
What could possibly go wrong
Scaling systems using change propagation across data stores
Software architecture case study - why and why not sql server replication
Hbase hive pig
NServiceBus - building a distributed system based on a messaging infrastructure
Kafka Reliable Data Delivery
Ad

More from webinartrainer (8)

PPTX
jjjjjjjjjjjjjjjjjjjjjjjjjjjLecture 11.pptx
PPT
Game theory.pdf textbooks content Artificical
PDF
Game theory.pdf textbooks content Artificical
PPT
Python.pdf textbooks content Artificical
PPT
Machine Learning Neural Networks Artificial
PPT
cps170_logic.ppt Propositional Logic Discrete
PPT
Py-Slides-10.ppt Python Programming AIML
PPT
Machine Learning Neural Networks Artificial Intelligence
jjjjjjjjjjjjjjjjjjjjjjjjjjjLecture 11.pptx
Game theory.pdf textbooks content Artificical
Game theory.pdf textbooks content Artificical
Python.pdf textbooks content Artificical
Machine Learning Neural Networks Artificial
cps170_logic.ppt Propositional Logic Discrete
Py-Slides-10.ppt Python Programming AIML
Machine Learning Neural Networks Artificial Intelligence
Ad

Recently uploaded (20)

PDF
English Textual Question & Ans (12th Class).pdf
DOCX
Cambridge-Practice-Tests-for-IELTS-12.docx
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
PDF
fundamentals-of-heat-and-mass-transfer-6th-edition_incropera.pdf
PDF
Journal of Dental Science - UDMY (2021).pdf
PDF
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
PDF
LIFE & LIVING TRILOGY- PART (1) WHO ARE WE.pdf
PDF
Everyday Spelling and Grammar by Kathi Wyldeck
PDF
Environmental Education MCQ BD2EE - Share Source.pdf
PPTX
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
PPTX
MICROPARA INTRODUCTION XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PDF
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
PPTX
Core Concepts of Personalized Learning and Virtual Learning Environments
PDF
IP : I ; Unit I : Preformulation Studies
PPTX
INSTRUMENT AND INSTRUMENTATION PRESENTATION
PDF
Skin Care and Cosmetic Ingredients Dictionary ( PDFDrive ).pdf
PPTX
Climate Change and Its Global Impact.pptx
English Textual Question & Ans (12th Class).pdf
Cambridge-Practice-Tests-for-IELTS-12.docx
FORM 1 BIOLOGY MIND MAPS and their schemes
fundamentals-of-heat-and-mass-transfer-6th-edition_incropera.pdf
Journal of Dental Science - UDMY (2021).pdf
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
LIFE & LIVING TRILOGY- PART (1) WHO ARE WE.pdf
Everyday Spelling and Grammar by Kathi Wyldeck
Environmental Education MCQ BD2EE - Share Source.pdf
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
MICROPARA INTRODUCTION XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
AI-driven educational solutions for real-life interventions in the Philippine...
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
Core Concepts of Personalized Learning and Virtual Learning Environments
IP : I ; Unit I : Preformulation Studies
INSTRUMENT AND INSTRUMENTATION PRESENTATION
Skin Care and Cosmetic Ingredients Dictionary ( PDFDrive ).pdf
Climate Change and Its Global Impact.pptx

jjjjjjjjjjjjjjjjjjjjjjjjjjjjlecture 27.pptx

  • 1. ADVANCED DATABASE MANAGEMENT SYSTEM MODULE 9 – NOSQL Lecture 5 – Consistency
  • 3. Consistency ● Consistency, states that data cannot be written that would violate the rules for valid data. ● If a certain action occurs that attempts to introduce inconsistent data, the entire action is rolled back and an error returned to the user, and there are many types for consistency like strong consistency and eventual consistency.
  • 5. Update Consistency Write-write conflict ● Person x and person y want to update telephone number on website. Both will have update rights ● Both person uses different format but at the same time they are updating phone number. ● This issue is called write-write conflict (i.e.) two people updating same data item at the same time. ● When these write reaches to server, the server will serialize them after one another. ● Server will use alphabetical order then x person’s update will done first then y person’s update will done. ● So x person’s update is overwritten by y person’s update and the x person’s update became the lost update.
  • 6. Update Consistency ● Pessimistic Approach ○ It works by preventing conflicts from occurring by having locks ○ In order to change a value you need to acquire a lock and the system ensures that only one client can get a lock at a time. ○ So person Y will see result of person x and then he will decide whether to make update or not. ● Optimistic Approach ○ Let conflicts occur, detect them and take action to sort them out. ○ A common optimistic approach is a conditional update where any client that does an update tests the value just before updating it to see if it’s changed since his last read. ○ In this case, X’s update would succeed but Y’s would fail. ○ The error would let Y know that he should look at the value again and decide whether to attempt a further update.
  • 7. Update Consistency ● Replication makes it much more likely to run into write-write conflicts. ● If different nodes have different copies of some data which can be independently updated, then you’ll get conflicts unless you take specific measures to avoid them. ● Using a single node as the target for all writes for some data makes it much easier to maintain update consistency.
  • 9. Read Consistency ● Having a data store that maintains update consistency is one thing, but it doesn’t guarantee that readers of that data store will always get consistent responses to their requests. ● Let’s imagine we have an order with line items and a shipping charge. The shipping charge is calculated based on the line items in the order. ● If we add a line item, we thus also need to recalculate and update the shipping charge. ● In a relational database, the shipping charge and line items will be in separate tables. ● The danger of inconsistency is that Martin adds a line item to his order, Pramod then reads the line items and shipping charge, and then Martin updates the shipping charge. ● This is an inconsistent read or read-write conflict
  • 10. Read Consistency ● We refer to this type of consistency as logical consistency: ensuring that different data items make sense together. ● To avoid a logically inconsistent read-write conflict, relational databases support the notion of transactions. ● A common claim we hear is that NoSQL databases don’t support transactions and thus can’t be consistent. ● Secondly, aggregate-oriented databases do support atomic updates, but only within a single aggregate. ● This means that you will have logical consistency within an aggregate but not between aggregates.
  • 11. Read Consistency ● This is another inconsistent read—but it’s a breach of a different form of consistency we call replication consistency: ensuring that the same data item has the same value when read from different replicas
  • 13. Relaxing Consistency ● Consistency is a Good Thing—but, sadly, sometimes we have to sacrifice it. ● It is always possible to design a system to avoid inconsistencies, but often impossible to do so without making unbearable sacrifices in other characteristics of the system ● Trading off consistency is a familiar concept even in single-server relational database systems. ● Here, our principal tool to enforce consistency is the transaction, and transactions can provide strong consistency guarantees. ● However, transaction systems usually come with the ability to relax isolation levels, allowing queries to read data that hasn’t been committed yet.
  • 14. Relaxing Consistency ● CAP Theorem ○ NoSQL can not provide consistency and high availability together. ○ This was first expressed by Eric Brewer in CAP Theorem. ○ CAP theorem states that we can only achieve at most two out of three guarantees for a database: Consistency, Availability, and Partition Tolerance. ○ Consistency means that all nodes in the network see the same data at the same time. ○ Availability is a guarantee that every request receives a response about whether it was successful or failed. ○ Partition Tolerance is a guarantee that the system continues to operate despite arbitrary message loss or failure of part of the system.
  • 17. Relaxing Durability ● Most people would laugh at relaxing durability—after all, what is the point of a data store if it can lose updates? ● There are cases where you may want to trade off some durability for higher performance. ● A failure of replication durability occurs when a node processes an update but fails before that update is replicated to the other nodes. ● A simple case of this may happen if you have a master-slave distribution model where the slaves appoint a new master automatically should the existing master fail. ● If a master does fail, any writes not passed onto the replicas will effectively become lost. ● So, as user will think update is succeeded as master have acknowledged it but due to failure of master node updates are lost.
  • 19. Quorums ● One piece of data is stored in multiple nodes. So we need some sort of mechanism so that nodes agree on a particular return value. ● Suppose we replicate the data on 3 nodes. Node 0,1 and 2. ● We made a written request to node 0. Data is written on Node 0 and Node 1 and 2 are waiting for the data. ● Meanwhile, we have a read request for the newly inserted data but Node 0 fails. ● Since Node 0 fails it checks in Node 1 and 2. But the replicas are still not inserted in these nodes. ● So our database sends a data not found error which is false. ● Instead, the database should have sent database error. ● To avoid such issues we need a distributed consensus and one way to implement that is through Quorum. ● If we have data on multiple nodes then we take the data with the latest timestamp. So even if one of our nodes fails users can still read the data.