Professional Documents
Culture Documents
NoSQL MongoDB HBase Cassandra
NoSQL MongoDB HBase Cassandra
NoSQL
“Towards the end of RDBMS ?”
Database Categories
OLTP Database
OLTP Database
No SQL Databases
What is RDBMS
2
Attributes
Tuples
Name
Issues with RDBMS- Scalability
3
Master-Slave Sharding
All writes are written to the master. Scales well for both reads
All reads are performed against and writes.
the replicated slave databases. Not transparent, application needs
Critical reads may be incorrect as to be partition-aware.
writes may not have been Can no longer have relationships or
propagated down. joins across partitions.
Large data sets can pose Loss of referential integrity across
problems as master needs to shards.
duplicate data to slaves.
What is NoSQL?
5
Stands for Not Only SQL. Term was redefined by Eric Evans after Carlo Strozzi.
Class of non-relational data storage systems.
Do not require a fixed table schema nor do they use the concept of joins.
Relaxation for one or more of the ACID properties (Atomicity, Consistency,
Isolation, Durability) using CAP theorem.
What is NoSQL?
What is NoSQL?
Why NoSQL?
Why NoSQL?
Need of NoSQL
6
Explosion of social media sites (Facebook, Twitter, Google etc.) with large data
needs. (Sharding is a problem)
We would avoid it for systems that need complex transactions spanning multiple operations or
Graph Based
11
We can have at most two of these three properties for any shared-data system
Joins
Group by
ACID transactions
SQL
Integration with applications that are based on SQL
Where to use NoSQL
15
All the choices provided by the rise of NoSQL databases does not mean
the demise of RDBMS databases as Relational databases are a powerful
tool.
CNN Turk uses MongoDB for its infrastructure and content management system,
including the tv.cnnturk.com.
Foursquare uses MongoDB to store venues and user ‘check-ins’ into venues, sharing
the data over more than 25 machines on Amazon EC2.
Justin.tv is the easy, fun, and fast way to share live video online. MongoDB powers
Justin.tv’s internal analytics tools for virality, user retention, and general usage stats
that out-of-the-box solutions can’t provide.
Ibibo (“I build, I Bond”) is a social network using MongoDB for its dashboard feeds.
Each feed is represented as a single document containing an average of 1000 entries;
the site currently stores over two million of these documents in MongoDB
Financial Services
Portfolio Management
Order Capture
Content Archiving
Retail
New Services
Digital Coupons
Consumer Cloud
Product Catalog
mongod
mongos
mongo
m0ng0d.exe
m0ng0s.exe
mongodump
mongorestore
bsondump
mongooplog
mongoimport
mongoexport
mongostat
mongotop
mongosniff
mongoperf
mongofiles
MongoDB Package Components (Tools)
MongoDB Database
Each database gets its own set of files on the file system.
purpose.
MongoDB Document
timestamp
Data type is Long
Value (Cell)
Byte array
Notes on Data Model
2
Cache priority
CFs stored seperately on disk: access one without wasting IO on the other
HBase Regions
2
One master
The HRegionServer
Many region servers
Region
A subset of a table’s rows, like horizontal range partitioning
Automatically done
Master
Responsible for coordinating the slaves
Admin functions
Big Picture
2
ZooKeeper
2
ZooKeeper
HMaster and HRegionServers
register themselves with
ZooKeeper
Creating a Table
2
Time
Row key Column “anchor:”
Stamp
t12
“com.apache.www” t11
t9 “anchor:cnnsi.com” “CNN”
t8 “anchor:my.look.ca” “CNN.com”
“com.cnn.www”
t6
t5
t3
Select value from table where
Scan() anchor=‘cnnsi.com’
Time
Row key Column “anchor:”
Stamp
t12
“com.apache.www” t11
Master
node
Slave
nodes
HBase vs. HDFS
HBase vs. RDBMS
When to use HBase
Thank you
Presentation on
Cassandra
“Handle massive transactional data and never go down”
History of Cassandra
2
Cluster
Schema Architecture
Memtables Partitioning
Compaction Replication
SStables Gossip
Commit Log Anti-Entropy
Hints
What is Cassandra?
2
Distributed Database
✓ Working in a cluster
C*
✓ Nothing is shared
Why Cassandra?
2
It’s Always On
Why Cassandra?
2
Operational Simplicity
OR
San Stockholm
Francisco
New York
Why Cassandra?
2
C*
How Does The Database Work in Cassandra? - The Basics
2
read
Each Cassandra node is…
write
Fully functional database data tables
memory
Very fast (low latency)
disk or SSD
In-memory and/or persistent
storage data tables
One machine or Virtual
Machine
How Does The Database Work in Cassandra? - The Basics
2
read
Why is Cassandra so fast?
Low Latency Nodes write
Distributed Workload
data tables
memory
Writes
Durable write to log file (fast) disk or SSD
No db file read or lock needed data tables
Reads
Get data from memory first
Optimize storage layer IO
No locking or two phase commit
Multi-data center deployment
2
read or
A Cassandra Cluster write
Nodes in a peer-to-peer cluster
No single point of failure
✔
Failure avoidance
Multi-data center deployment
2
C*
Amazon
C* C*
San Francisco UK
C*
New York
Multi-data center deployment
2
Amazon
UK
San Francisco
New York
Multi-data center deployment
2
Amazon
UK
San Francisco C*
New York
Cassandra Cluster Architecture
2
80
Each Node ~ box or VM
70 10 (technically it’s a JVM)
Each node has same Cassandra
database functionality
60 20 System/hardware failures happen
Snitch – topology (DC and rack)
Gossip – state of each node
50 30
40
Transaction Load Balancing
2
Application
driver
Driver manages connection pool
80
60 Data Center 1 20
Each transaction has a different
connection point in the cluster
50 30
Asynch operations are faster
40
Data Partitioning
Application insert
driver
key=‘x’;
hash(key)
=> Driver selects the Coordinator
80
token(43) node per operation via load
70 10 balancing
50 30
Each entire row lives on a node
40
Replication
Application insert
driver
key=‘x’;
hash(key)
=> Driver selects the Coordinator
80
token(43) node per operation via load
70 10 balancing
replication 50 30
factor = 3 Each entire row lives on a node
40
Replication
Application insert
driver
key=‘x’;
hash(key)
=> Replication Factor = # of copies
80
token(43)
71 11
70 10
61 21
60 20
51 31
replication 50 30
factor = 3 replication 41
40
factor = 3
Consistency
Application insert
driver
key=‘x’; hash(key)
80
=> Replication Factor = ?
token(43)
Consistency Level = # of nodes to
70 10
acknowledge an operation
read and write “consistency”
per operation
60 20 CL(write) + CL(read) > RF
➔ consistency
Data Center 1
If needed, tune consistency for
replication 50 30 performance
factor = 3
40
Netflix Replication Experiment
Slow Node Anti-Entropy: Hints
Application insert
driver
key=‘x’; hash(key) IF Node 60 is:
80
=> Slow enough to timeout ops
token(43) Down for a short time
70 10 Then…
50 30
40
replication factor = 3
Cluster Expansion: Add Nodes
Application
driver
Introduce new nodes to cluster
80
Nodes do not yet own any token
70 10 ranges (data)
50 30
replication factor = 3
Cluster Expansion: Rebalance
Application
driver
Rebalance = redistribution of token
80
ranges around the cluster
72 8
Data is streamed in small chunks to
synchronize the cluster
see “Vnodes”
64 16 minimizes streaming
Data Center 1 distributes rebalance workload
New nodes begin taking ops
56 24 Cleanup = reclaims space on
nodes dedicated to tokens no
48 32 longer owned
40
replication factor = 3
Cluster Expansion: Rebalance
Application
driver
Rebalance = redistribution of token
80
ranges around the cluster
72 8
Data is streamed in small chunks to
synchronize the cluster
see “Vnodes”
64 16 minimizes streaming
Data Center 1 distributes rebalance workload
New nodes begin taking ops
56 24 Cleanup = reclaims space on
nodes dedicated to tokens no
48 32 longer owned
40
replication factor = 3
Write Path ✔write
Compaction memory
• Merge sstables disk or SSD
• Evict tombstones
commit sstable A sstable
sstableB Bv2
• Rebuild indexes log sstable B
• Is a background process append
fsynch
SSTables are
immutable
Memtable
Flush During
Write Load
Compaction
During Write
Load
Compaction And Tombstones
Read Path ✔ ✔ ✔ read
row cache
SELECT * FROM memtable A * can be in-memory table
email_users bloom filter
WHERE domain= memtable B
key cache
'@datastax.com’
AND user = memory OS cache
’rreffner@datastax.co disk or SSD
m’;
commit sstable A sstable B
log
Data Modeling Best Practices
Start with your data access patterns
What does your app do?
What are your query patterns?
Optimize for
Fast writes and reads at the correct consistency
Consider the results set, order, group, filtering
Use TTL to manage data aging
1 Query = 1 Table
Each SELECT should target a single row (1 seek)
Range queries should traverse a single row (efficient)
Denormalization Is Expected
Remember: You’re not optimizing for storage efficiency
Do this:
Forget what you’ve learned about 3rd normal form
Repeat after me… “slow is down”, “storage is cheap”
Denormalize and do parallel writes!
Don’t to this:
Client side joins
Reads before writes
Where to use Cassandra?
2