KillrChat Exercises Handbook DuyHai DOAN, Technical Advocate

@doanduyhai

KillrChat presentation! 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

2

Technology stack! AngularJS UI Bootstrap

SockJS

Spring REST Spring Messaging Spring Security

Achilles Object Mapper Cassandra

@doanduyhai

3

Front end layout!

@doanduyhai

4

Exercises outline! TDD style

Implement the services to make tests green

Glue-code and front-end code provided!

@doanduyhai

5

Getting started! 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

@doanduyhai

6

Exercise 1! User account management!

Specifications!

git checkout exercise_1_specs

@doanduyhai

8

Scalability! Scaling by login n C3

jdoe

n E5

n1 A

hsue

alice

nD 4

n B2

n H8

nF6

bob

oscar

nG7

@doanduyhai

9

Data model!

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,

PRIMARY KEY(login));

@doanduyhai

10

User’s chat rooms!

@doanduyhai

11

User’s chat rooms data model! 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

12

User’s chat rooms data model! Best choice!

CREATE TABLE killrchat.users(

login text,



chat_rooms set, //list of chat rooms for this user

PRIMARY KEY(login));

• 

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

• 

@doanduyhai

13

Lightweight Transaction! 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 ?!

@doanduyhai

14

Let’s code!! Tasks •  • 

annotate UserEntity implement UserService

Solution

git checkout exercise_1_solution

@doanduyhai

15

Exercise 2! Chat room management!

Specifications!

git checkout exercise_2_specs

@doanduyhai

17

Scalability!

n1

@doanduyhai

18

Data model!

CREATE TABLE killrchat.chat_rooms(

room_name text,

creation_date timestamp,

banner text,

creator text,

// de-normalization

creator_login text,

participants set,

// de-normalization

PRIMARY KEY(room_name));

@doanduyhai

19

Room details!

@doanduyhai

20

Room participants!

@doanduyhai

21

De-normalization!

CREATE TABLE killrchat.chat_rooms(

room_name text,



creator text,

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



participants set,

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

PRIMARY KEY(room_name));

@doanduyhai

22

Lightweight Transaction! Avoid creating the same room by 2 different users ? ☞ use Lightweight Transaction!

INSERT INTO killrchat.chat_rooms(room_name, …)

VALUES (‘games’, …) IF NOT EXISTS ;

@doanduyhai

23

Listing all rooms! How to list all existing rooms ? •  • 

limit to first 100 rooms rooms ordered by their token (hash of room_name)

!

Full text search ? •  • 

possible with ‘gam*’ sematics Lucene integration otherwise (DSE)!

@doanduyhai

24

Let’s code!! Tasks •  • 

ChatRoomEntity already given with proper annotations Implement first methods in ChatRoomService

Solution

git checkout exercise_2_solution

@doanduyhai

25

Exercise 3! Participants management! Room deletion!

Specifications!

git checkout exercise_3_specs

@doanduyhai

27

Participant joining! 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

28

Concurrent delete/update! DELETE FROM chat_rooms WHERE room_name= ‘games’; UPDATE chat_rooms SET participants = participants + {login: ‘jdoe’, …} WHERE room_name = ‘games’;

result @doanduyhai

games

participants creator banner ... {login: ‘jdoe’, …}





∅ 29

Participant joining! Solution ☞ use Lightweight Transaction!

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

WHERE room_name = ‘games’ IF EXISTS;

@doanduyhai

30

Concurrent delete/update! UPDATE chat_rooms SET participants = participants + {login: ‘jdoe’, …} WHERE room_name = ‘games’ IF EXISTS;

OK

@doanduyhai

DELETE FROM chat_rooms WHERE room_name= ‘games’ IF creator_login = ‘jdoe’;

31

Concurrent delete/update! DELETE FROM chat_rooms WHERE room_name= ‘games’ IF creator_login = ‘jdoe’;

UPDATE chat_rooms SET participants = participants + {login: ‘jdoe’, …} WHERE room_name = ‘games’ IF EXISTS; @doanduyhai

Room deleted

32

Participant leaving! 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

33

Concurrent delete/update! DELETE FROM chat_rooms WHERE room_name= ‘games’; UPDATE chat_rooms SET participants = participants - {login: ‘jdoe’, …} WHERE room_name = ‘games’;

result

games

participants creator banner ...

∅ @doanduyhai





∅ 34

Deleting room! 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

35

Deleting room! Solution

DELETE killrchat.chat_rooms

WHERE room_name = ‘games’

IF creator_login = ;

Advantages •  • 

current user login coming from Security context, no cheating ! slow but how often do you delete rooms ?

@doanduyhai

36

Let’s code!! Tasks • 

Implement remaining methods in ChatRoomService

Solution

git checkout exercise_3_solution

@doanduyhai

37

Exercise 4! Chat messages management!

Specifications!

git checkout exercise_4_specs

@doanduyhai

39

Scalability! Scaling messages by room name! n C3

games

message1 … messageN …

nD 4

n B2

n E5

n1 A

politics

message1 … messageN …

java

n H8

nF6

scala

message1 … messageN …

cassandra

message1 … messageN …

message1 … messageN …

nG7

@doanduyhai

40

Data model!

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

41

Data model! 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

@doanduyhai

42

Let’s code!! Tasks •  • 

MessageEntity already given with proper annotations Implement methods in MessageService

Solution

git checkout exercise_4_solution

@doanduyhai

43

!" !

Q&R

Thank You @doanduyhai [email protected] https://academy.datastax.com/

KillrChat Exercises Handbook - GitHub

scalable messaging app. Why KillrChat ? ... provide real application for attendees. • highlight Cassandra eco- .... bucketing by day is the right design. PRIMARY ...

2MB Sizes 5 Downloads 283 Views

Recommend Documents

Exercises - GitHub
UNIX® Network Programming Volume 1, Third Edition: The Sockets ... To build today's highly distributed, networked applications and services, you need deep.

Hands-On Exercises - GitHub
Nov 29, 2011 - Lecture 13: Building a Bioinformatics Pipeline, Part III ... Download protein sequences for the best blast hits from Swiss-Prot ... Download the file unknown1.fas and unknown2.fas from the class website. ... u1.seq[:10].tostring().

Hands-On Exercises - GitHub
Nov 22, 2011 - Lecture 12: Building a Bioinformatics Pipeline, Part II. Paul M. ... have shown that it is amongst the best performing multiple ... See the MAFFT website for additional references ... MAFFT v6.864b (2011/11/10) ... Once you've confirme

Exercises part 1 - GitHub
This R Markdown document contains exercises to accompany the course “Data analysis and visualization using R”. This document contains the exercises ...

Scientific Computing for Biologists Hands-On Exercises ... - GitHub
Scientific Computing for Biologists. Hands-On Exercises, Lecture 7 .... Download the file zeros.dat from the course wiki. This is a 25 × 15 binary matrix that ...

Scientific Computing for Biologists Hands-On Exercises ... - GitHub
Nov 15, 2011 - computer runs Windows you can have access to a Unix-like environment by installing a program called .... 6 4976 Nov 1 12:21 rolland-etal-2 -cAMP.pdf ..... GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin1 . ).

Scientific Computing for Biologists Hands-On Exercises ... - GitHub
Oct 25, 2011 - Discriminant Analysis in R. The function ... data = iris, prior = c(1, 1, 1)/3) ... if we were analyzing a data set with tens or hundreds of variables.

Scientific Computing for Biologists Hands-On Exercises ... - GitHub
Oct 1, 2011 - iris.cl ... analysis of road distances between US cities available at the following link (but see notes ...

Scientific Computing for Biologists Hands-On Exercises ... - GitHub
Nov 8, 2011 - vignette can be downloaded from the CRAN website. Using mixtools. We'll look at how to use mixtools using a data set on eruption times for the ...

Buzzing Exercises
Sirens. 2. Step-by-step. Lowest point on all patterns is played as low as possible. Highest point on last repetition is played as high as possible. Play all six, then ...

PATRIOTIC​ ​EXERCISES
Administrative​ ​Procedure​ ​207. PATRIOTIC​ ​EXERCISES. Background ... 1. April​​2016. Administrative​​Procedures​​Manual. Page​​1​​of​​2 ...

23. [202 Useful Exercises for IELTS- Practice Exercises for IELTS ...
[202 Useful Exercises for IELTS- Practice Exercises for IELTS [audiobook].pdf. 23. [202 Useful Exercises for IELTS- Practice Exercises for IELTS [audiobook].pdf.

Exercises -
commonly used modeling programs, such as MODFLOW and MT3DMS. The purpose of this ... As with any software, it's always a good idea to save the current file. ... represent Boundaries, Properties, Grid, and Analytic element. Whichever one ...

Exercises -
There are four areas of the Groundwater Vistas main window: (1) the menus and .... window. 2. Normally you want to import the head file and also the cell-by-cell flow file. ...... MAS (disguised by the file manager as a “Microsoft Access Stored.

Exercises -
Arrange the following in increasing order of forces of attraction between the particles – water, sugar ... Particles of matter have spaces between them. Particles of ...

Calculus exercises
Approximate tna Volue c ſ Sin(f) dt asi-h errorſ 4 o, Ooooo. O. (2) Evoluole Ava old.cinc integrols or shoe divergence. (e) ſix also ax (b) fixer as. (23) Fina. -Ane values cle p al- Lonic Vn AN2 old Jingy integral cover 9s, end evoluccle it for -

lumbar exercises pdf
Sign in. Loading… Page 1. Whoops! There was a problem loading more pages. lumbar exercises pdf. lumbar exercises pdf. Open. Extract. Open with. Sign In.

osteoporosis exercises pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. osteoporosis ...