SlideShare a Scribd company logo
@doanduyhai
KillrChat Presentation
DuyHai DOAN, Technical Advocate
@doanduyhai
KillrChat presentation!
2
What is KillrChat ?
•  scalable messaging app

Why KillrChat ?
•  show real life de-normalization
•  DIY exercise
•  provide real application for attendees
•  highlight Cassandra eco-system
@doanduyhai
Technology stack!
3
AngularJS
UI Bootstrap
SockJS
Spring REST
Spring Security
Spring Messaging
Cassandra
Achilles
Object Mapper
@doanduyhai
Architecture!
4
Tomcat
Spring
C*
HTTP Rest
Spring {Boot,Security,
Rest, Messaging}
Cassandra,
Achilles
In-memory broker
Embedded/local
Cassandra
Single node
AngularJS,
UI Bootstrap,
SockJS
@doanduyhai
Architecture!
5
Tomcat
Spring …
Broker (RabbitMQ, ZeroMQ, Kafka…)
Tomcat
Spring
Tomcat
Spring
Scaling out
@doanduyhai
Front end layout!
6
@doanduyhai
Getting started!
7
Clone the Git repository


git clone https://github.com/doanduyhai/killrchat.git
Go into the ‘killrchat’ folder and launch tests

cd killrchat
mvn clean test
Exercise 1!
User account management!
@doanduyhai
Scalability!
9
n1
n2
n3
n4
n5
n6
n7
n8
A
B
C
D
E
F
G
H
jdoe
oscar
alice
hsue
bob
Scaling by login!
@doanduyhai
Data model!
10

CREATE TABLE killrchat.users(

 
login text,

 
pass text, //password is not allowed because reserved word

 
lastname text,

 
firstname text,

 
bio text,

 
email text,

 
chat_rooms set<text>, 

PRIMARY KEY(login));
@doanduyhai
User’s chat rooms!
11
@doanduyhai
User’s chat rooms data model!
12
How to store chat rooms for an user ?!

CREATE TABLE killrchat.user_rooms(

 
login text,

 
room_name text, 

PRIMARY KEY((login), room_name));
•  pros: can store huge room count per user (106)
•  cons: separated table, needs 1 extra SELECT!
@doanduyhai
User’s chat rooms data model!
13
Best choice!
•  1 SELECT fetches all data for a given user
•  usually, 1 user is not in more that 1000 rooms at a time
•  stores only room name

CREATE TABLE killrchat.users(

 
login text,

 
…

 
chat_rooms set<text>, //list of chat rooms for this user

PRIMARY KEY(login));
@doanduyhai
Lightweight Transaction!
14
Avoid creating the same login by 2 different users ?
☞ use Lightweight Transaction!

INSERT INTO killrchat.users(room_name, …)

VALUES (‘jdoe’, …) IF NOT EXISTS ;
Expensive operation!
☞ do you create a new account every day ?!
Demo
Exercise 2!
Chat room management!
@doanduyhai
Scalability!
17
n1
n2
n3
n4
n5
n6
n7
n8
A
B
C
D
E
F
G
H
games
scala
java
politics
cassandra
Scaling by room name!
@doanduyhai
Data model!
18

CREATE TABLE killrchat.chat_rooms(

 
room_name text,

 
creation_date timestamp,

 
banner text,

 
creator text, 
 
 
 
// de-normalization

 
creator_login text,

 
participants set<text>, 
// de-normalization

PRIMARY KEY(room_name));
@doanduyhai
Room details!
19
@doanduyhai
Room participants!
20
@doanduyhai
De-normalization!
21

CREATE TABLE killrchat.chat_rooms(

 
room_name text,

 
…

 
creator text, 
 
 
 
// JSON blob {login: …, firstname: …, lastname: …}

 
…

 
participants set<text>, 
// JSON blob {login: …, firstname: …, lastname: …} 

PRIMARY KEY(room_name));
@doanduyhai
Lightweight Transaction!
22
Avoid creating the same room by 2 different users ?
☞ use Lightweight Transaction!

INSERT INTO killrchat.chat_rooms(room_name, …)

VALUES (‘games’, …) IF NOT EXISTS ;
Demo
Exercise 3!
Participants management!
Room deletion!
@doanduyhai
Participant joining!
25
Adding new participant!

UPDATE killrchat.chat_rooms SET participants = participants + {…} 


WHERE room_name = ‘games’;
❓
What if the creator deletes the room at the same time ?
@doanduyhai
Concurrent delete/update!
26
UPDATE chat_rooms SET
participants = 
participants + {login: ‘jdoe’, …}
WHERE room_name = ‘games’;
DELETE FROM chat_rooms
WHERE room_name= ‘games’;
result games
participants creator banner ...
{login: ‘jdoe’, …} ∅ ∅ ∅
@doanduyhai
Participant joining!
27
Solution
☞ use Lightweight Transaction!

UPDATE killrchat.chat_rooms SET participants = participants + {…} 


WHERE room_name = ‘games’ IF EXISTS;
@doanduyhai
Concurrent delete/update!
28
UPDATE chat_rooms SET
participants = 
participants + {login: ‘jdoe’, …}
WHERE room_name = ‘games’
IF EXISTS;
DELETE FROM chat_rooms
WHERE room_name= ‘games’
IF creator_login = ‘jdoe’;
OK
@doanduyhai
Concurrent delete/update!
29
UPDATE chat_rooms SET
participants = 
participants + {login: ‘jdoe’, …}
WHERE room_name = ‘games’
IF EXISTS;
DELETE FROM chat_rooms
WHERE room_name= ‘games’
IF creator_login = ‘jdoe’;
Room deleted
@doanduyhai
Participant leaving!
30
Removing participant (no read-before-write)!

UPDATE killrchat.chat_rooms SET participants = participants - {…} 


WHERE room_name = ‘games’; ❓
What if the creator deletes the room at the same time ?
•  we’ll create a tombstone
•  tombstone will be garbage-collected by compaction !
@doanduyhai
Concurrent delete/update!
31
UPDATE chat_rooms SET
participants = 
participants - {login: ‘jdoe’, …}
WHERE room_name = ‘games’;
DELETE FROM chat_rooms
WHERE room_name= ‘games’;
result games
participants creator banner ...
∅ ∅ ∅ ∅
@doanduyhai
Deleting room!
32
What if participant leaving at the same time ?
•  not a problem, tombstone will be garbage
What if participant joining at the same time ?
☞ use Lightweight Transaction!

Only room creator can delete room, no one else!
☞ use Lightweight Transaction
!
@doanduyhai
Deleting room!
33

DELETE killrchat.chat_rooms 

WHERE room_name = ‘games’

IF creator_login = <current_user_login>;
Solution
Advantages
•  current user login coming from Security context, no cheating !
•  slow but how often do you delete rooms ?
Demo
Exercise 4!
Chat messages management!
@doanduyhai
Scalability!
36
n1
n2
n3
n4
n5
n6
n7
n8
A
B
C
D
E
F
G
H
Scaling messages by room name!
games
message1
 …
 messageN
…
politics
message1
 …
 messageN
…
java
message1
 …
 messageN
…
cassandra
message1
 …
 messageN
…
scala
message1
 …
 messageN
…
@doanduyhai
Data model!
37

CREATE TABLE killrchat.chat_room_messages(

 
room_name text,

 
message_id timeuuid,

 
content text,

 
author text, 
 
 
// JSON blob {login: …, firstname: …, lastname: …}

 
system_message boolean,

 
PRIMARY KEY((room_name), message_id)

) WITH CLUSTERING ORDER BY (message_id DESC);
@doanduyhai
Data model!
38
Clustering column message_id order by DESC
•  latest messages first
•  leverage the new row cache in Cassandra 2.1
Improvements
•  current data model limits messages count to ≈ 500 ⨉ 106 
•  bucketing by day is the right design

PRIMARY KEY((room_name, day), message_id) //day format yyyyMMdd
Demo
Q & R
! "!
Thank You
@doanduyhai
duy_hai.doan@datastax.com
https://academy.datastax.com/

More Related Content

PDF
KillrChat Data Modeling
PDF
KillrChat: Building Your First Application in Apache Cassandra (English)
PDF
DEF CON 27 - workshop - GUILLAUME ROSS - defending environments and hunting m...
PDF
Cassandra introduction @ ParisJUG
PDF
Cassandra introduction @ NantesJUG
PDF
Cassandra drivers and libraries
PDF
Apache Zeppelin @DevoxxFR 2016
PDF
Spark Cassandra 2016
KillrChat Data Modeling
KillrChat: Building Your First Application in Apache Cassandra (English)
DEF CON 27 - workshop - GUILLAUME ROSS - defending environments and hunting m...
Cassandra introduction @ ParisJUG
Cassandra introduction @ NantesJUG
Cassandra drivers and libraries
Apache Zeppelin @DevoxxFR 2016
Spark Cassandra 2016

Viewers also liked (20)

PDF
Cassandra introduction mars jug
PDF
Fast track to getting started with DSE Max @ ING
PDF
Introduction to KillrChat
PDF
Sasi, cassandra on the full text search ride At Voxxed Day Belgrade 2016
PDF
Cassandra and Spark, closing the gap between no sql and analytics codemotio...
PDF
Datastax day 2016 introduction to apache cassandra
PDF
Spark cassandra integration 2016
PDF
Cassandra introduction at FinishJUG
PDF
Spark cassandra integration, theory and practice
PDF
Cassandra nice use cases and worst anti patterns no sql-matters barcelona
PDF
Libon cassandra summiteu2014
PDF
Data stax academy
PDF
Cassandra introduction 2016
PDF
Cassandra 3 new features @ Geecon Krakow 2016
PDF
Real time data processing with spark & cassandra @ NoSQLMatters 2015 Paris
PDF
Apache zeppelin the missing component for the big data ecosystem
PDF
Datastax enterprise presentation
PDF
Cassandra for the ops dos and donts
PDF
Sasi, cassandra on full text search ride
PDF
From rdbms to cassandra without a hitch
Cassandra introduction mars jug
Fast track to getting started with DSE Max @ ING
Introduction to KillrChat
Sasi, cassandra on the full text search ride At Voxxed Day Belgrade 2016
Cassandra and Spark, closing the gap between no sql and analytics codemotio...
Datastax day 2016 introduction to apache cassandra
Spark cassandra integration 2016
Cassandra introduction at FinishJUG
Spark cassandra integration, theory and practice
Cassandra nice use cases and worst anti patterns no sql-matters barcelona
Libon cassandra summiteu2014
Data stax academy
Cassandra introduction 2016
Cassandra 3 new features @ Geecon Krakow 2016
Real time data processing with spark & cassandra @ NoSQLMatters 2015 Paris
Apache zeppelin the missing component for the big data ecosystem
Datastax enterprise presentation
Cassandra for the ops dos and donts
Sasi, cassandra on full text search ride
From rdbms to cassandra without a hitch
Ad

Similar to KillrChat presentation (20)

PDF
DOAN DuyHai – Cassandra: real world best use-cases and worst anti-patterns - ...
PDF
Cassandra nice use cases and worst anti patterns
PDF
Eight Rules for Making Your First Great Game
PDF
JUG Münster 2014 - Code Recommenders & Codetrails - Wissenstransfer 2.0
PDF
Sonatype DevSecOps Leadership forum 2020
PDF
Introduction to Cassandra & Data model
PPTX
Writing clean code in C# and .NET
KEY
Pylons + Tokyo Cabinet
PDF
Github github-github
PDF
Being Amazon for Software Developers - IDE 2.0: Crowdsourcing mal anders #Jav...
KEY
MongoDB at ZPUGDC
PDF
Clean Code @Voxxed Days Cluj 2023 - opening Keynote
PDF
Rainbow Over the Windows: More Colors Than You Could Expect
PDF
Making A Game Engine Is Easier Than You Think
PPTX
Old code doesn't stink - Detroit
PPTX
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
PPTX
ICS3211 lecture 08
PDF
Hackersuli Minecraft hackeles kezdoknek
PDF
Rails israel 2013
PDF
Lecture 2: C# Programming for VR application in Unity
DOAN DuyHai – Cassandra: real world best use-cases and worst anti-patterns - ...
Cassandra nice use cases and worst anti patterns
Eight Rules for Making Your First Great Game
JUG Münster 2014 - Code Recommenders & Codetrails - Wissenstransfer 2.0
Sonatype DevSecOps Leadership forum 2020
Introduction to Cassandra & Data model
Writing clean code in C# and .NET
Pylons + Tokyo Cabinet
Github github-github
Being Amazon for Software Developers - IDE 2.0: Crowdsourcing mal anders #Jav...
MongoDB at ZPUGDC
Clean Code @Voxxed Days Cluj 2023 - opening Keynote
Rainbow Over the Windows: More Colors Than You Could Expect
Making A Game Engine Is Easier Than You Think
Old code doesn't stink - Detroit
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
ICS3211 lecture 08
Hackersuli Minecraft hackeles kezdoknek
Rails israel 2013
Lecture 2: C# Programming for VR application in Unity
Ad

More from Duyhai Doan (15)

PDF
Pourquoi Terraform n'est pas le bon outil pour les déploiements automatisés d...
PDF
Le futur d'apache cassandra
PDF
Big data 101 for beginners devoxxpl
PDF
Big data 101 for beginners riga dev days
PDF
Datastax day 2016 : Cassandra data modeling basics
PDF
Apache cassandra in 2016
PDF
Spark zeppelin-cassandra at synchrotron
PDF
Algorithme distribués pour big data saison 2 @DevoxxFR 2016
PDF
Cassandra 3 new features 2016
PDF
Cassandra introduction 2016
PDF
Cassandra UDF and Materialized Views
PDF
Apache zeppelin, the missing component for the big data ecosystem
PDF
Distributed algorithms for big data @ GeeCon
PDF
Spark cassandra connector.API, Best Practices and Use-Cases
PDF
Algorithmes distribues pour le big data @ DevoxxFR 2015
Pourquoi Terraform n'est pas le bon outil pour les déploiements automatisés d...
Le futur d'apache cassandra
Big data 101 for beginners devoxxpl
Big data 101 for beginners riga dev days
Datastax day 2016 : Cassandra data modeling basics
Apache cassandra in 2016
Spark zeppelin-cassandra at synchrotron
Algorithme distribués pour big data saison 2 @DevoxxFR 2016
Cassandra 3 new features 2016
Cassandra introduction 2016
Cassandra UDF and Materialized Views
Apache zeppelin, the missing component for the big data ecosystem
Distributed algorithms for big data @ GeeCon
Spark cassandra connector.API, Best Practices and Use-Cases
Algorithmes distribues pour le big data @ DevoxxFR 2015

Recently uploaded (20)

PDF
Getting Started with Data Integration: FME Form 101
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Encapsulation theory and applications.pdf
PDF
project resource management chapter-09.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Enhancing emotion recognition model for a student engagement use case through...
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
WOOl fibre morphology and structure.pdf for textiles
PPTX
Chapter 5: Probability Theory and Statistics
PPTX
A Presentation on Touch Screen Technology
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
Getting Started with Data Integration: FME Form 101
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Building Integrated photovoltaic BIPV_UPV.pdf
Univ-Connecticut-ChatGPT-Presentaion.pdf
Encapsulation theory and applications.pdf
project resource management chapter-09.pdf
Group 1 Presentation -Planning and Decision Making .pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Unlocking AI with Model Context Protocol (MCP)
Enhancing emotion recognition model for a student engagement use case through...
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
cloud_computing_Infrastucture_as_cloud_p
WOOl fibre morphology and structure.pdf for textiles
Chapter 5: Probability Theory and Statistics
A Presentation on Touch Screen Technology
Assigned Numbers - 2025 - Bluetooth® Document
NewMind AI Weekly Chronicles - August'25-Week II
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf

KillrChat presentation