Chapter V: NoSQL Databases
Types
Architectures
Examples (HBase, Cassandra, MongoDB)
Hamdi KCHAOU – Course 3 Computer Science IIT 1
NOSQL and RDB
Comparaison (1/3)
• Choice of NOSQL as opposed to relational databases driven by market
constraints and technical needs
• BigData
§ Adapting NOSQL DBs to Big Data
o Velocity: Much data comes in quickly, from multiple sources
o Variety—Structured, semi-structured, or unstructured data
o Volume—Massive data (TB and PB)
o Complexity: Data stored and managed in multiple locations and data centers.
• Continuous data availability
§ Lack of availability can be fatal for a company
§ BD NOSQL use a highly distributed architecture: no SPOF (Single Point Of
Failure)
§ Data redundancy and processing: fault tolerance
§ Hence: continuous availability across data centers, and the cloud
§ Any updates or modifications are made without disconnecting the database
Hamdi KCHAOU – Course 3 Computer Science IIT 2
NOSQL and RDB
Comparaison (2/3)
• Location independence
§ Ability to view and modify a database without knowing where these
operations are actually taking place
§ Any write functionality propagated from one location, to be available to
users from other sites
§ Difficult to apply to RDBs, especially for writing
• Flexible data models
§ One of the major reasons
§ In the relational model, the relationships between tables are predefined,
fixed, and organized in a strict and uniform scheme
o Scalability and performance issues when managing large volumes of data
§ NOSQL databases can accept any type of data (structured, semi-
structured or unstructured) more easily
§ In BDRs, performance is a problem, especially when "wide" lines are
used and there are many modification actions
Hamdi KCHAOU – Course 3 Computer Science IIT 3
NOSQL and RDB
Comparaison (3/3)
• Business Intelligence and Analytics
§ Ability of NOSQL databases to use the data collected to derive ideas
§ Extract actionable insights from a large volume of data, difficult to
obtain with relational databases
§ NoSQL databases allow the storage and management of
§ business applications, and provide an ability to understand complex
data, and make decisions
• Modern transactional capabilities
§ New Definition of the Transaction Principle
§ Using BASE Properties Instead of ACID Properties
Hamdi KCHAOU – Course 3 Computer Science IIT 4
NOSQL and RDB
ACID Properties
• ACID Properties: Atomicity, Consistency, Isolation, and Durability
§ RDB transaction properties
§ Atomicity: Either all instructions are executed or none
§ Consistency: any transaction brings the DB from one valid state to
another
→ Reinforced by integrity constraints and foreign keys
§ Isolation: Even though multiple transactions can be executed by one
or more users simultaneously, a transaction should not see the
effects of other competing transactions
§ Durability: Once the transaction is recorded in the database (commit),
these changes are persistent.
• All RDBs support ACID transactions
• But:
§ Growing Data + Need for Scalable Systems
§ Need for network-based DBs for horizontal scalability
Hamdi KCHAOU – Course 3 Computer Science IIT 5
2
0
NOSQL and RDB
CAP theorem
• Intended to evaluate distributed storage systems
• CAP theorem: "It is impossible to satisfy all three CAP properties at the same time”
• Propriétés CAP : Consistency, Availability, Partition tolerance
§ Consistency: If I write a piece of data in one node and read
it from another node in a distributed system, I find what I
wrote on the first one.
§ High availability: At all times, for each request, the
answer is guaranteed. Even in the event of a breakdown,
the data remains accessible
§ Partition tolerance: Data can be partitioned across different
media without any need for localization. Activities continue
uninterrupted when the system is modified (in case of
addition or removal of nodes) and in the event of a network
fall
Hamdi KCHAOU – Course 3 Computer Science IIT 6
NOSQL and RDB
CAP theorem
• Why is it impossible to satisfy all 3 CAP properties at the same
time?
• Let us say a distributed system. We are modifying a piece of data on
node N1 and trying to read it from node N2
§ N2 can return the last good value it has, which violates the Consistency
§ N2 is waiting for the new value to reach him. As it is a distributed system, the
chances of a transmission failure are quite high, which will cause an infinite
wait for N2. Hence, a violation of the Availability
§ If consistency and availability are to be met, the storage system should not
be partitioned. Hence, the violation of the Partition Tolerance.
• For NOSQL DBs, there are no more joins
§ → The property of consistency is no longer ensured in the same way
• Consistency in NOSQL: Immediate and eventual consistency of data
across distributed database nodes
Hamdi KCHAOU – Course 3 Computer Science IIT 7
NOSQL and RDB
Propriétés BASE
• BASE : Basically Available, Soft-state, Eventual
consistency
• Basically Available
§ The system guarantees availability, as defined in the CAP
theorem
• Soft-State
§ The state of the system can change over time, even without
new entries, because of the principle of eventual consistency
• Eventual Consistency
§ The changes will eventually arrive at all servers, if given enough
time
• BASE is more flexible than ACID, accepts certain
errors, the occurrence of which is quite rare
Hamdi KCHAOU – Course 3 Computer Science IIT 8
NOSQL and RDB
Synthesis
• NOSQL databases
§ Performance on large volumes of data
§ Performance on unstructured data
§ Very high scalability, even for small volumes
• However:
§ Fairly young technology→ Lack of tools to support it
§ Still evolving, no standards
§ No common query language like SQL, but diverse:
o Language-specific queries (Java, Python...)
o Special queries for the database (Cassandra Query Language)
o Map Reduce or object graph-based API
§ More work needs to be done at the code level, which can affect
performance
Hamdi KCHAOU – Course 3 Computer Science IIT 9
NOSQL and RDB
When to use NOSQL?
• If scalability is a concern
§ But beware, this is not always a MUST: Flickr and Wikipedia use
RDBMS (relational database management system).
• If the lack of a schema is a concern
• If being IN and FASHION is a concern
§ For a significant number of people, the use of a new paradigm or
technology is a MUST!
Hamdi KCHAOU – Course 3 Computer Science IIT 10
NOSQL Databases
Definition
• Not Only SQL (NOSQL) Databases:
§ It's not No SQL (no SQL)
§ So choose NOSQL rather than No SQL
• Non-relational and widely distributed databases
• Enables fast, ad-hoc analysis and organization of data of huge volumes
and disparate data types
• Also known as
§ Cloud Databases
§ Non-Relational Databases
§ Big Data Databases
§ …
• Developed in response to the exponential increase in data generated,
saved, and analyzed by modern users and their applications
Hamdi KCHAOU – Course 3 Computer Science IIT 11
1
1
NOSQL Databases
Assets
• Key Strengths
§ Scalability
§ Availability
§ Fault tolerance
• Characteristics
§ Schema-free data model
§ Distributed architecture
§ Use of languages and interfaces that are not just SQL
Hamdi KCHAOU – Course 3 Computer Science IIT 12
1
2
NOSQL Databases
NOSQL et Big Data
• From a business perspective, using a BigData and NOSQL
environment provides a competitive advantage
• Importance of data:
§ «If your data isn't growing, then neither is your business»
Hamdi KCHAOU – Course 3 Computer Science IIT 13
1
3
NOSQL Databases
Types
• Types of NOSQL databases
§ Key/Value
§ Column-oriented
§ Document-oriented
§ Graph-oriented
• Properties of RDBs
§ ACID : Atomicity, Consistency, Isolation, and Durability
§ Using SQL
Id Nom Humeur Date_naissance Couleur
12 Stella Heureuse 2007-04-01 NULL
13 Wimma Faim NULL Noire
9 Ninja NULL NULL NULL
Hamdi KCHAOU – Course 3 Computer Science IIT 14
1
4
Types of NOSQL Databases
1. Key/Value Store
• One of the simplest types, a kind of distributed hashmap
• Designed to back up data without defining a schema
• All data is in key/value form
§ The value can be a string, a serialized object, a blob…
§ The data is opaque to the system: it is not possible to access it without using the key
• Lack of typing has an impact on the query: all the intelligence carried before by the
queries will have to be taken by the application that queries the database
• Communications mostly boiled down to PUT, GET, and DELETE operations
• Objective: to provide quick access to information, to keep the session of a website…
• Example: DynamoDB (Amazon), Azure Table Storage (ATS), Redis,
BerkeleyDB, Voldemort (LinkedIn)
Hamdi KCHAOU – Course 3 Computer Science IIT 15
1
5
Types of NOSQL Databases
1. Key/Value Store
Id Nom Humeur Date_naissance Couleur
12 Stella Heureuse 2007-04-01 NULL
13 Wimma Faim NULL Noire
9 Ninja NULL NULL NULL
Value
Key
Nom_$#_Stella~~Humeur_$#_Heureuse
Chien_12 ~~Date_naissance_$#_2007-04-01…
Hamdi KCHAOU – Course 3 Computer Science IIT 16
1
6
Types of NOSQL Databases
2. Document Database
• Extend the key/value paradigm, with more complex "documents" instead of simple
data, and a unique key for each of them
• JSON or XML documents
• Each document is an object, contains one or more fields, and each field contains a
typed value (string, date, binary, or array)
• Store, retrieve, and manage document-oriented information (semi-
structured data)
• Advantage: to be able to retrieve, via a single key, a set of hierarchically structured
information
§ In relational databases, this would involve multiple joins
• Examples: MongoDB (SourceForge), CouchDB (Apache), RavenDB (Intended for
platforms .NET/Windows, query via LINQ)
Hamdi KCHAOU – Course 3 Computer Science IIT 17
1
7
Types of NOSQL Databases
2. Document Database
Id Nom Humeur Date_naissance Couleur
12 Stella Heureuse 2007-04-01 NULL
13 Wimma Faim NULL Noire
9 Ninja NULL NULL NULL
Document(V2)
{
type : « Chien »,
nom : « Stella »,
Document(V1) humeur : « Heureuse »,
date_naissance : 2007-04-01
{ aboiement : [
{ texte : « j’ai mangé de la pâtée
Key type : « Chien »,
» commentaires : [
nom : « Stella », { id_chien : « chien_4 »,
Chien_12 humeur : « Heureuse », texte : « on s’en fout!
}
»
date_naissance : 2007-04-01 }]
]
} }
Hamdi KCHAOU – Course 3 Computer Science IIT 18
1
8
Types of NOSQL Databases
3. Column Store
• Evolution of the DB key/value
• Similar to RDBMSs, but with a dynamic number of columns, different from
record to record (no columns with NULL values)
• Deliver very high performance and highly scalable architecture
• Examples: Hbase (Hadoop), Cassandra (Facebook, Twitter), BigTable
(Google)
A B C D E
1 A Foo B Bar C Hello
1 Foo Bar Hello 2 B Tom
2 Tom 3 C Java D Scala E Cobol
3 Java Scala Cobol
Hamdi KCHAOU – Course 3 Computer Science IIT 19
10
Types of NOSQL Databases
3. Column Store
Id Nom Humeur Date_naissance Couleur
12 Stella Heureuse 2007-04-01 NULL
13 Wimma Faim NULL Noire
9 Ninja NULL NULL NULL
Requête: clef/ famille:titre[/time]
Exp: "chien_12"/"Chien":"Nom" → Stella
Colonnes
Famille Titre Temps Valeur
Chien Date_naissance 15 2007-04-01
Chien Humeur 11 En Colère
Clef Chien Humeur 45 Heureuse
Chien Nom 25 Stella
Chien_12
Chien Couleur 34
Noire
Aboiement Text 11 J’ai mangé de la pâtée
Hamdi KCHAOU – Course 3 Computer Science IIT 20
Types of NOSQL Databases
3. Column Store
Cassandra Example: Column / Super Column / Column Family
Hamdi KCHAOU – Course 3 Computer Science IIT 21
Types of NOSQL Databases
4. Graph Database
• Based on graph theories
• Relies on the notions of nodes, relationships and the properties
attached to them
• Designed for data whose relationships are represented as graphs,
and having interconnected elements, with an indeterminate number
of relationships between them
• Suitable for social media data processing
• Examples: Neo4J et InfiniteGraph, OrientDB
Hamdi KCHAOU – Course 3 Computer Science IIT 22
Types of NOSQL Databases
4. Graph Database
Id Nom Humeur Date_naissance Couleur
12 Stella Heureuse 2007-04-01 NULL
13 Wimma Faim NULL Noire
9 Ninja NULL NULL NULL
Chien_4
commente
Chien Commentaire_
83
Stella type Commentaire_à texte
nom
humeur aboiements Aboiement_5
Heureuse Chien_12 « On s’en
9
fout! »
date_naissance
texte
« J’ai mangé de
2007-04-01
la pâtée! »
Hamdi KCHAOU – Course 3 Computer Science IIT 23