1
NoSQL
MOHAMMAD HOSSEIN SHOJAEINIA
2
History of databases(a little basics)
Flatfile model (from beginning of innovation of hard
disks)
Nowadays is being used
Hierarchical model of databases (by IBM in early 1960)
E.g. IMS
A tree-like structure
One-to-one and one-to-many relations
Anomaly in insertion, deletion and update
Lots of redundancy
3
History of databases(a little basics),
cont’d
Network model of databases (late 1960s)
E.g. CODASYL
Creates a graph of data
No anomaly
Less redundancy
Very complicated
4
History of databases(a little basics),
cont’d
Relational model of databases ()
IBM DB2, Microsoft SQLServer, Oracle, PostgreSQL, MySQL, ..
Based on mathematical relational algebra
Simple
No support of multimedia storage (bare relational DBMS)
Needs powerful computer for large-scale usage
Distributed computing and CAP (later we’ll talk)
5
ACID
Atomicity
All of a transaction will be done, or nothing of it
Consistency
Any transaction that is done, must be valid (transmit DB from a valid state, to
another)
Isolation
Concurrent transactions must not affect each other
Durability
Makes sure if a transaction is committed, the result will remain at any
circumstances
6
What?
Pros?
NoSQL Cons?
[Link] Object-Oriented model!!!
7
NoSQL
After problems of RDBMSs, NoSQL introduced
Different meanings of NoSQL
No use of SQL! Instead, UNIX commands (Carlo Strozzi 1998, first
time)
Not-only-SQL (Johan Oskarsson, since 2009)
8
NoSQL
Types (classifying by data model)
Column
Cassandra, Vertica, HBase
Document
MongoDB, Apache CouchDB, IBM Domino
Key/Value
Amazon DynamoDB, Oracle NoSQL DB, Redis
Graph
Apache Giraph, Neo4J, ArangoDB
9
NoSQL
10
NoSQL vs Relational
NoSQL maps real world to objects better than Relational
Relational only accepts data with structure, but not about
NoSQL
Usage: data gathering in web
NoSQL can support both schema-base and document
data, but not about Relational
Relational is a subset of NoSQL (that’s why we call it not-only-SQL)
11
NoSQL vs Relational
NoSQL is less powerful in join in comparison of Relational
Solution: Nested Design!
Faster queries in NoSQL in comparison by traditional SQL
Additional queries are acceptable
12
Design in NoSQL
Simple comparison:
NoSQL Relational
Schema Free(optional) Static Schema
Linear Scalability Non-linear Scalability
Database Database
Collection Table
Embedding and Linking Join
ODM ORM
13
ORM? ODM?
14
Class like!
class User{
int id;
String name;
ArrayList<Post> posts;
ArrayList<Like> likes;
ArrayList<Comments> comments;
}
15
Database like!(Relational)
16
Database like!(NoSQL)
{
"_id" : ObjectId("58e38f64308976031f2eb4e1"),
“name”:”Mohammad Hossein Shojaeinia” ,
“posts”:[
…
]
“likes”:[
…
]
…
}
17
Which one?
NoSQL? Relational?
Distributed Systems Why?
Google Maps
Microsoft Maps
…
18
CAP theorem
Consistency
Every read gets the most recent write (or an error)
Availability
Every request gets a response(not error, response!)
Partitioning-tolerance
System continues working even if any number of messages being
dropped or delayed
19
CAP theorem, cont’d
C A
P
20
CAP theorem, cont’d
There’s no distributed system to have all three
parts at once
Proof:
In distributed systems, you must choose Partitioning!
If you choose Availability, the system will search for most recent available
answer, even if it isn’t the most recent answer, due to network
partitioning. So there’s no Consistency! (AP)
If you choose Consistency, the system will search for most recent answer
to return. If not, an error or time-out will be returned if data is not
guaranteed to be up to date due to network partitioning. So there’s no
Availability! (CP)
21
So! How about distributed systems?
NoSQL
Relational databases, choose Consistency according to
ACID!
So,system not always returns a true value, even not most
value.
Therefor, seems Consistency is better for distributed
systems.
An old answer in most distributed systems, is much better than an error!
Imagine in Google Maps!
22
Let’s design!
23
24
25
“
Questions?
”
26
“
Thanks for attention!
”
Provided by AytenSoft
[Link]