Lecture 27 (Week 16) -NOSQL Part 2
Lecture 27 (Week 16) -NOSQL Part 2
CS-222
CONTENTS
• Previous Lecture
• CAP Theorem
• SQL vs NOSQL
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: NOSQL
Cheaper to be managed
Scaling is easy
3
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: NOSQL
CAP Theorem
• Suppose three properties A
of a distributed system (sharing data) C
• Consistency:
• all copies have same value P
• Availability:
• reads and writes always succeed
• Partition-tolerance:
• system properties (consistency and/or availability) hold even when network failures
prevent some machines from communicating with others
4
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: NOSQL
CAP Theorem
• Brewer’s CAP Theorem:
• For any system sharing data, it is “impossible” to guarantee simultaneously
all of these three properties
• You can have at most two of these three properties for any shared-data system
• Very large systems will “partition” at some point:
• That leaves either C or A to choose from (traditional DBMS prefers C over A
and P )
• In almost all cases, you would choose A over C (except in specific
applications such as order processing)
5
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: NOSQL
CAP Theorem
Consistency: All client
always have the same view of
Availability the data
Consistency
Partition
tolerance
6
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: NOSQL
CAP Theorem
• Consistency
• 2 types of consistency:
1. Strong consistency – ACID (Atomicity, Consistency, Isolation, Durability)
2. Weak consistency – BASE (Basically Available Soft-state Eventual
consistency)
7
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: NOSQL
CAP Theorem
• ACID
• A DBMS is expected to support “ACID transactions,” processes that are:
• Atomicity: either the whole process is done or none is
• Consistency: only valid data are written
• Isolation: one operation at a time
• Durability: once committed, it stays that way
• CAP
• Consistency: all data on cluster has the same copies
• Availability: cluster always accepts reads and writes
• Partition tolerance: guaranteed properties are maintained even when network
failures prevent some machines from communicating with others
8
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: NOSQL
CAP Theorem
• A consistency model determines rules for visibility and apparent order of
updates
• Example:
• Row X is replicated on nodes M and N
• Client A writes row X to node N
• Some period of time t elapses
• Client B reads row X from node M
• Does client B see the write from client A?
• Consistency is a field with tradeoffs
• For NOSQL, the answer would be: “maybe”
• CAP theorem states: “strong consistency can't be achieved at the same time as
availability and partition-tolerance”
9
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: NOSQL
CAP Theorem
• Eventual consistency
• When no updates occur for a long period of time, eventually all updates will propagate
through the system and all the nodes will be consistent
• Cloud computing
• ACID is hard to achieve, moreover, it is not always required, e.g. for blogs,
status updates, product listings, etc.
10
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: NOSQL
CAP Theorem
Availability:
Each client always can read
Availability and write.
Consistency
Partition
tolerance
11
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: NOSQL
CAP Theorem
Partition Tolerance:
A system can continue to
operate in the presence of
Availability a network partitions
Consistency
Partition
tolerance
12
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: NOSQL
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: NOSQL
14
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: NOSQL
Development Year It was developed in the 1970s to deal Developed in the late 2000s to overcome issues
with issues with flat file storage and limitations of SQL databases.
Consistency It should be configured for strong It depends on DBMS as some offers strong
consistency. consistency like MongoDB, whereas others offer
only offers eventual consistency, like Cassandra.
Best Used for RDBMS database is the right option for NoSQL is a best used for solving data availability
solving ACID problems. problems
15
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: NOSQL
16
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
THANKS
Course: Database Management Systems (CS222)
Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST
Email: muneer.umar@kust.edu.pk