CASSANDRA
To be or not to be?
ABOUT ME
Andriy Rymar
Software Engineer @ Lohika
Morning@Lohika Program Committee Member
JUG Lviv Active Member
2
AGENDA
3
AGENDA
Cluster Ring
3
Node 4
Node 1
Node 2
Node 3
AGENDA
Cluster Ring
Data Model
3
Row1
Row2
Row3
AGENDA
Cluster Ring
Data Model
Read & Write
3
Read
Write
AGENDA
Cluster Ring
Data Model
Read & Write
Update & Delete
3
Update
Delete
AGENDA
Cluster Ring
Data Model
Read & Write
Update & Delete
3
To be or not to be?
HASHTAG
#jeeconf_cassandra
4
HASHTAG
#jeeconf_cassandra
4
#jeeconf_cassandra
PREFACE
5
#jeeconf_cassandra
TRENDS
6
#jeeconf_cassandra
TRENDS
6
#jeeconf_cassandra
TRENDS
7
#jeeconf_cassandra
TRENDS
7
#jeeconf_cassandra
7
#jeeconf_cassandra
CASSANDRA
To be or not to be?
#jeeconf_cassandra
9
CLUSTER
#jeeconf_cassandra
DISCOVERY
Node1
Node3
Node4 Node2
10
#jeeconf_cassandra
DISCOVERY
Node3
Node4 Node2
Node1
10
#jeeconf_cassandra
DISCOVERY
Node3
Node4 Node2
Hi, I’m node 2
Node1
10
#jeeconf_cassandra
DISCOVERY
Node3
Node4 Node2
OK, here are
you and me
Hi, I’m node 2
Node1
10
#jeeconf_cassandra
DISCOVERY
Node3
Node4 Node2
Hi, I’m node 3
OK, here are
you and me
Hi, I’m node 2
Node1
10
#jeeconf_cassandra
DISCOVERY
Node3
Node4 Node2
Hi, I’m node 3
OK, here are
you and me
Hi, I’m node 2
Well, here are you,
me and node2
Node1
10
#jeeconf_cassandra
DISCOVERY
Node3
Node4 Node2
Hi, I’m node 4
Hi, I’m node 3
OK, here are
you and me
Hi, I’m node 2
Well, here are you,
me and node2
Node1
10
#jeeconf_cassandra
DISCOVERY
Node3
Node4 Node2
Cool, here are you, me,
node2 and node3
Hi, I’m node 4
Hi, I’m node 3
OK, here are
you and me
Hi, I’m node 2
Well, here are you,
me and node2
Node1
10
#jeeconf_cassandra
DISCOVERY
Node3
Node4 Node2
Cool, here are you, me,
node2 and node3
Hi, I’m node 4
Hi, I’m node 3
OK, here are
you and me
Hi, I’m node 2
Well, here are you,
me and node2
Node1
10
#jeeconf_cassandra
DISCOVERY
Node3
Node4 Node2
Cool, here are you, me,
node2 and node3
Hi, I’m node 4
Hi, I’m node 3
OK, here are
you and me
Hi, I’m node 2
Well, here are you,
me and node2
Node1
10
#jeeconf_cassandra
DISCOVERY
Node3
Node4 Node2
Cool, here are you, me,
node2 and node3
Hi, I’m node 4
Hi, I’m node 3
OK, here are
you and me
Hi, I’m node 2
Well, here are you,
me and node2
Node1
10
#jeeconf_cassandra
RING
Node1
Node3
Node4 Node2
11
#jeeconf_cassandra
DATA RANGE
Long.min Long.max
12
#jeeconf_cassandra
DATA RANGE
Long.min Long.max
12
#jeeconf_cassandra
RING CLUSTER
Node1
Node3
Node4 Node2
Long.minLong.max
13
#jeeconf_cassandra
TOKEN
14
#jeeconf_cassandra
TOKEN
12343214
14
#jeeconf_cassandra
TOKEN
12343214
Long.min Long.max
14
#jeeconf_cassandra
INITIALTOKENS
Node1 Node2
12343214 21144543
15
#jeeconf_cassandra
16
TOKENS
#jeeconf_cassandra
Issues
16
TOKENS
#jeeconf_cassandra
REPLICATION
17
#jeeconf_cassandra
REPLICATION
RF
17
#jeeconf_cassandra
= 2
REPLICATION
RF
17
#jeeconf_cassandra
= 2
REPLICATION
RF
17
«Hello, JeeConf»
Node 1:
«Hello, JeeConf»
Node 2:
«Hello, JeeConf»
#jeeconf_cassandra
REPLICATION &TOKENS
Node1
Node 2Node 3
18
#jeeconf_cassandra
REPLICATION &TOKENS
Node1
RF = 2
Node 2Node 3
18
#jeeconf_cassandra
REPLICATION &TOKENS
RF = 2
Node 2Node 3
Node1
18
#jeeconf_cassandra
REPLICATION &TOKENS
RF = 2
Node 2Node 3
Node1
18
#jeeconf_cassandra
REPLICATION &TOKENS
RF = 2
Node 3
Node1
Node 2
node1
Node1
18
#jeeconf_cassandra
REPLICATION &TOKENS
RF = 2
Node 3
Node1
Node 2
node1
Node1
18
#jeeconf_cassandra
REPLICATION &TOKENS
RF = 2
Node 3
Node1
Node 2
node1
Node1
18
#jeeconf_cassandra
REPLICATION &TOKENS
Node1
RF = 2
Node 3 Node 2
node1
18
#jeeconf_cassandra
REPLICATION &TOKENS
Node1
RF = 2
Node 3 Node 2
node1
18
#jeeconf_cassandra
REPLICATION &TOKENS
Node1
RF = 2
Node 3 Node 2
node1
Node 2
node1
18
#jeeconf_cassandra
VNODE
19
#jeeconf_cassandra
VNODE
19
#jeeconf_cassandra
VNODE
255
19
#jeeconf_cassandra
VNODE
255
From To
19
#jeeconf_cassandra
REPLICATION &V-NODE
Node1
Node 2Node 3
20
#jeeconf_cassandra
REPLICATION &V-NODE
Node1
RF = 2
Node 2Node 3
20
#jeeconf_cassandra
REPLICATION &V-NODE
Node1
RF = 2
Node 2Node 3
v-node = 2
20
#jeeconf_cassandra
Node1
REPLICATION &V-NODE
RF = 2
Node 2Node 3
v-node = 2
20
#jeeconf_cassandra
Node1
REPLICATION &V-NODE
RF = 2
Node 2Node 3
v-node = 2
20
#jeeconf_cassandra
Node1
REPLICATION &V-NODE
RF = 2
Node 2Node 3
v-node = 2
20
#jeeconf_cassandra
Node1
REPLICATION &V-NODE
RF = 2
Node 2Node 3
v-node = 2
20
#jeeconf_cassandra
Node1
REPLICATION &V-NODE
RF = 2
Node 2Node 3
v-node = 2
20
#jeeconf_cassandra
REPLICATION &V-NODE
Node1
RF = 2
Node 2Node 3
v-node = 2
20
#jeeconf_cassandra
REPLICATION &V-NODE
Node1
RF = 2
Node 2Node 3
v-node = 2
20
#jeeconf_cassandra
NODE RANGE
Node1
Node3
Node4 Node2
21
#jeeconf_cassandra
NODE RANGE
22
Node1
Node3
Node4 Node2
#jeeconf_cassandra
CASSANDRA
To be or not to be?
#jeeconf_cassandra
24
DATA MODEL
#jeeconf_cassandra
KEYSPACE
25
#jeeconf_cassandra
KEYSPACE
25
#jeeconf_cassandra
KEYSPACE
Table1 Table2
25
#jeeconf_cassandra
KEYSPACE
25
#jeeconf_cassandra
Column Family 1 Column Family 2
KEYSPACE
Row 1
Row 2
Row 1
Row 2
25
#jeeconf_cassandra
Column Family 1 Column Family 2
KEYSPACE
value value value
value value
value
key key key key
key key
value value value
key key key
Row 1
Row 2
Row 1
Row 2
25
#jeeconf_cassandra
Column Family 1 Column Family 2
DATA DISTRIBUTION
26
#jeeconf_cassandra
DATA DISTRIBUTION
murmur3(partition_key)
26
#jeeconf_cassandra
27
KEYS
#jeeconf_cassandra
27
KEYS
Primary
#jeeconf_cassandra
27
KEYS
Primary
http://www.pngall.com/man-png
#jeeconf_cassandra
27
KEYS
Primary
Partition
http://www.pngall.com/man-png
#jeeconf_cassandra
27
KEYS
Primary
Partition
http://www.pngall.com/man-png
http://www.pngmart.com/image/31069
#jeeconf_cassandra
27
KEYS
Primary
Partition
Composite
http://www.pngall.com/man-png
http://www.pngmart.com/image/31069
#jeeconf_cassandra
27
KEYS
Primary
Partition
Composite
http://www.pngall.com/man-png
http://www.pngmart.com/image/31069 http://www.pngmart.com/image/21342
#jeeconf_cassandra
27
KEYS
Primary
Partition
Composite
Clustering
http://www.pngall.com/man-png
http://www.pngmart.com/image/31069 http://www.pngmart.com/image/21342
#jeeconf_cassandra
27
KEYS
Primary
Partition
Composite
Clustering
http://www.pngall.com/man-png
http://www.pngmart.com/image/31069 http://www.pngmart.com/image/21342
http://ujceastside.org/home-health-aides/
#jeeconf_cassandra
28
PRIMARY
CREATE TABLE album (
id uuid,
name text,
PRIMARY KEY (id)
)
#jeeconf_cassandra
28
PRIMARY
CREATE TABLE album (
id uuid,
name text,
PRIMARY KEY (id)
)
Primary & Partition & Clustering
#jeeconf_cassandra
29
PARTITION
CREATE TABLE author_book (
author text,
book text,
population int,
PRIMARY KEY (author, book)
)
#jeeconf_cassandra
29
PARTITION
CREATE TABLE author_book (
author text,
book text,
population int,
PRIMARY KEY (author, book)
)
Partition Clustering
#jeeconf_cassandra
30
COMPOSITE & CLUESTERING
CREATE TABLE teacher_lesson (
teacher text,
lesson text,
topic text,
duration int,
PRIMARY KEY ((teacher, lesson), topic, duration)
)
#jeeconf_cassandra
30
COMPOSITE & CLUESTERING
CREATE TABLE teacher_lesson (
teacher text,
lesson text,
topic text,
duration int,
PRIMARY KEY ((teacher, lesson), topic, duration)
)
Composite Clustering
#jeeconf_cassandra
31
IMPORTANT
#jeeconf_cassandra
31
IMPORTANT
Natural ordering
#jeeconf_cassandra
31
IMPORTANT
Natural ordering
No relations
#jeeconf_cassandra
31
IMPORTANT
Natural ordering
No relations
No ACID transactions
#jeeconf_cassandra
CASSANDRA
to be or not to be?
#jeeconf_cassandra
33
READ & WRITE
#jeeconf_cassandra
ARCHITECTURE
Node
34
#jeeconf_cassandra
ARCHITECTURE
Memory Permanent storage
Node
34
#jeeconf_cassandra
ARCHITECTURE
Memory
MemTable
Permanent storage
Node
34
#jeeconf_cassandra
ARCHITECTURE
Memory
MemTable
CommitLog
Permanent storage
Node
34
#jeeconf_cassandra
ARCHITECTURE
Memory
MemTable
CommitLog
Permanent storage
SSTable 1 SSTable 2 SSTable 3
Node
34
#jeeconf_cassandra
ARCHITECTURE
Memory
MemTable
CommitLog
Permanent storage
SSTable 1 SSTable 2 SSTable 3
Newer Older
Node
34
#jeeconf_cassandra
Memory
MemTable
CommitLog
Permanent storage
SSTable 1 SSTable 2 SSTable 3
Newer Older
Node
34
#jeeconf_cassandra
WRITE
Request
Memory
MemTable
CommitLog
Permanent storage
SSTable 1 SSTable 2 SSTable 3
Newer Older
Node
34
#jeeconf_cassandra
WRITE
Request
Memory
MemTable
CommitLog
Permanent storage
SSTable 1 SSTable 2 SSTable 3
Newer Older
Node
1
34
#jeeconf_cassandra
WRITE
Request
Memory
MemTable
CommitLog
Permanent storage
SSTable 1 SSTable 2 SSTable 3
Newer Older
Node
1
2
34
#jeeconf_cassandra
WRITE
Request
Memory
MemTable
CommitLog
Permanent storage
SSTable 1 SSTable 2 SSTable 3
Newer Older
Node
1
3
4
2
34
#jeeconf_cassandra
WRITE
Request
Memory
MemTable
CommitLog
Permanent storage
SSTable 5
SSTable 4
SSTable 1 SSTable 2 SSTable 3
Newer Older
Node
1
3
4
5
2
34
#jeeconf_cassandra
WRITE
WRITE
Node 1 Node 2 Node 3
35
#jeeconf_cassandra
WRITE
Node 1 Node 2 Node 3
RF = 3
35
#jeeconf_cassandra
WRITE
Node 1 Node 2 Node 3
RF = 3
35
Client
#jeeconf_cassandra
WRITE
Node 1 Node 2 Node 3
RF = 3
35
Client
#jeeconf_cassandra
CONSISTENCY LEVEL
36
#jeeconf_cassandra
CONSISTENCY LEVEL
36
CL
#jeeconf_cassandra
WRITE
Node 1 Node 2 Node 3
RF = 3
37
Client
#jeeconf_cassandra
WRITE
Node 1 Node 2 Node 3
RF = 3
37
Client
#jeeconf_cassandra
CL = 2
WRITE
Node 3
RF = 3
Node 2Node 1
37
Client
#jeeconf_cassandra
successsuccess
CL = 2
WRITE
Node 3
RF = 3
Node 2Node 1
37
Client
#jeeconf_cassandra
successsuccess
CL = 2
READ
Memory
MemTable
Permanent storage
Node
38
#jeeconf_cassandra
Request
READ
Memory
MemTable
Permanent storage
Node
38
#jeeconf_cassandra
Request
READ
Memory
MemTable
Permanent storage
Node
1
38
#jeeconf_cassandra
Request
READ
Memory
MemTable
Permanent storage
Node
SSTable 1 SSTable 2
1
38
#jeeconf_cassandra
Request
READ
Memory
MemTable
Permanent storage
Node
SSTable 1BF IF SSTable 2BF IF
1
38
#jeeconf_cassandra
Request
READ
Memory
MemTable
Permanent storage
Node
SSTable 1BF IF SSTable 2BF IF
1
2
38
#jeeconf_cassandra
Request
READ
Memory
MemTable
Permanent storage
Node
SSTable 1BF IF SSTable 2BF IF
1
2
3
38
#jeeconf_cassandra
Request
READ
Memory
MemTable
Permanent storage
Node
SSTable 1BF IF SSTable 2BF IF
1
2
3
4
38
#jeeconf_cassandra
Request
READ
Memory
MemTable
Permanent storage
Node
SSTable 1BF IF SSTable 2BF IF
1
2
3
4
5
38
#jeeconf_cassandra
Request
READ
Memory
MemTable
Permanent storage
Node
SSTable 1BF IF SSTable 2BF IF
1
2
3
4
5 6
38
#jeeconf_cassandra
READ
Node 1 Node 2 Node 3
39
#jeeconf_cassandra
READ
Node 1 Node 2 Node 3
RF = 3
39
#jeeconf_cassandra
READ
Node 1 Node 2 Node 3
CL = 2
RF = 3
39
#jeeconf_cassandra
READ
Node 1 Node 2 Node 3
CL = 2
RF = 3
39
Client
#jeeconf_cassandra
READ
Node 1 Node 2 Node 3
CL = 2
RF = 3 get digest
39
Client
#jeeconf_cassandra
READ
Node 1 Node 2 Node 3
CL = 2
RF = 3 get digest
123453
39
Client
#jeeconf_cassandra
READ
Node 1 Node 2 Node 3
CL = 2
RF = 3 get digest
123453
39
Client
#jeeconf_cassandra
CASSANDRA
To be or not to be?
#jeeconf_cassandra
41
UPDATE & DELETE
#jeeconf_cassandra
UPDATE
42
#jeeconf_cassandra
UPDATE
Upsert
42
#jeeconf_cassandra
UPDATE
Memory
MemTable
Permanent storage
SSTable 1 SSTable 2 SSTable 3
Newer Older
Node
CommitLog
43
#jeeconf_cassandra
UPDATE
Request
Memory
MemTable
Permanent storage
SSTable 1 SSTable 2 SSTable 3
Newer Older
Node
CommitLog
43
#jeeconf_cassandra
UPDATE
Request
Memory
MemTable
Permanent storage
SSTable 1 SSTable 2 SSTable 3
Newer Older
Node
CommitLog
1
43
#jeeconf_cassandra
UPDATE
Request
Memory
MemTable
Permanent storage
SSTable 1 SSTable 2 SSTable 3
Newer Older
Node
CommitLog
1
2
43
#jeeconf_cassandra
UPDATE
Request
Memory
MemTable
Permanent storage
SSTable 1 SSTable 2 SSTable 3
Newer Older
Node
CommitLog
1
2
3
43
#jeeconf_cassandra
UPDATE
Request
Memory
MemTable
Permanent storage
SSTable 1 SSTable 2 SSTable 3
Newer Older
Node
CommitLog
1
2
3 4
43
#jeeconf_cassandra
UPDATE
Request
Memory
MemTable
Permanent storage
SSTable 1 SSTable 2 SSTable 3
Newer Older
Node
CommitLog
1
2
3 4
5
43
#jeeconf_cassandra
DELETE
44
#jeeconf_cassandra
DELETE
https://docs.datastax.com/en/cql/3.3/cql/cql_reference/cqlDelete.html
44
#jeeconf_cassandra
DELETE
45
#jeeconf_cassandra
DELETE
45
#jeeconf_cassandra
Update flow *
TOMBSTONES
46
#jeeconf_cassandra
http://shipoffools.wikia.com/wiki/File:Tombstone.png
TOMBSTONES
Overhead
46
#jeeconf_cassandra
http://shipoffools.wikia.com/wiki/File:Tombstone.png
TOMBSTONES
47
#jeeconf_cassandra
TOMBSTONES
Remove
47
#jeeconf_cassandra
TOMBSTONES
Remove
Null
47
#jeeconf_cassandra
TOMBSTONES
Remove
Null
TTL
47
#jeeconf_cassandra
CASSANDRA
To be or not to be?
#jeeconf_cassandra
49
SUMMARY
#jeeconf_cassandra
RECOMMENDATIONS
https://youtu.be/pAGESQo5IjI
Cassandra UnderThe Hood
by Andriy Rymar
50
#jeeconf_cassandra
THANKYOU
My contacts :
Email : andriyrav@gmail.com
Q / A
51
Twitter : @AndriyRymar
#jeeconf_cassandra

Cassandra : To be or not to be