Professional Documents
Culture Documents
2: Data Model: Creating An E Cient Data Model For Highly-Loaded Applications
2: Data Model: Creating An E Cient Data Model For Highly-Loaded Applications
2: Data Model: Creating An E Cient Data Model For Highly-Loaded Applications
YouTube
Twitch
Discord
YouTube
2 Do Homeworks
Forum: community.datastax.com Training: academy.datastax.com
Discord
How does it work ?
Attend one of the 2 LIVE STREAMED workshop
1 (Wednesday or Thursday) -> They are recorded
2 Homeworks
3 Relax.
Developer Workshop Series Week II
➔ Data Types
➔ What’s NEXT?
89 49 47
Developer Workshop Series Week II
➔ Data Types
➔ What’s NEXT?
A single bare-metal
server, a virtual instance
or a docker container.
Infrastructure: a Datacenter (Ring)
A group of
datacenters configured to
work together.
Data Structure: a Cell
Keyspace columns
● Tabular data model, with one twist
Table
● Keyspaces contain tables
- - - -
● Tables are organized in rows and columns
- - -
x ● Groups of related rows called partitions are stored
partitions - - - together on the same node (or nodes)
● Each row contains a partition key
- - -
○ One or more columns that are hashed to
y - - -
determine which node(s) store that data
- - -
z - - -
rows
Partition key
Example Data: Users organized by city
Keyspace users
Table users_by_city
Last First
City Address Email
Name Name
Hellson Kevin 23 Jackson St. kevin@gmail.com
Phoenix Lastfall Norda 3 Stone St dino@gmail.com
partitions Smith Jana 3 Stone St wilm@gmail.com
Franklin George 2 Star St gjet@gmail.com
rows
Seattle Jackson Jane 2 Star St jane@gmail.com
Jasons Judy 2 StarSt judy@gmail.com
keyspace table
Bad Example:
PRIMARY KEY ((city), last_name, first_name);
Partition Key
CREATE TABLE users.users_by_city (
city text,
An identifier for a partition. last_name text,
Consists of at least one column, first_name text,
address text,
may have more if needed
email text,
PRIMARY KEY ((city), last_name, first_name, email));
PARTITIONS ROWS.
Bad Example:
BUCKETING
● Sensor ID - UUID
world, different sensors reporting their state every 10
● Timestamp:
seconds. Every sensor reports its UUID, timestamp of the
● Value: float
report, sensor’s value.
This?
Or this?
Always specify the partition key! Or maybe that?!
SELECT address FROM users_by_city WHERE city = “Otterberg” AND last_name = “Koshkina”;
Developer Workshop Series Week II
➔ Data Types
➔ What’s NEXT?
Queries
Designing Process:
Conceptual Data Model
Designing Process:
Application Workflow
Use-Case I:
● A User opens a Video Page
WF1: Find comments related to target video using its identifier, most recent first
Use-Case II + III:
● A User opens a Profile
● A Moderator verifies a User if spammer or not
WF2: Find comments related to target user using its identifier, get most recent first
Designing Process:
Mapping
comments_by_user comments_by_video
↑ ↑
↑ ↑
Designing Process:
Physical Data Model
comments_by_user comments_by_video
UUID UUID
↑ ↑
TIMEUUID TIMEUUID
UUID UUID
TEXT TEXT
Designing Process:
Schema DDL
CREATE TABLE IF NOT EXISTS comments_by_user (
userid uuid,
commentid timeuuid,
videoid uuid,
comment text,
PRIMARY KEY ((userid), commentid)
) WITH CLUSTERING ORDER BY (commentid DESC);
89 49 47
Developer Workshop Series Week II
➔ Data Types
➔ What’s NEXT?
g...
somethin
a thing.. I’m a MAP of
.
an key/value pairs Key Value
r...
oth
er yet anothe K1 V1
t hin
g K2 V2
...
in g... K3 V3
sm all th
K4 V4
K5 V5
Collection: Set
{‘Thriller’, ‘Short’}
{‘Tragicomedy’, ‘Western’}
Collection: Set
Insert
Add to set
Collection: List
List
Collection: List
Insert
Append
Collection: List
Replace an element
Insert
Add to map
User Defined Types
Cool
Thing!
User Defined Types
Insert
Select field
Counters
89 49 47
Developer Workshop Series Week II
➔ Data Types
➔ What’s NEXT?
● Single-Row Partitions
https://katacoda.com/datastax/courses/cassandra-intro/tables-single-row-partitions
● Multi-Row Partitions
https://katacoda.com/datastax/courses/cassandra-intro/tables-multi-row-partitions
● Advanced Data Types
https://katacoda.com/datastax/courses/cassandra-intro/advanced-data-types
Training Courses at DataStax Academy
● Join academy.datastax.com
LEARN
● Browse www.datastax.com/dev
Join community.datastax.com
ASK/SHARE
Ask/answer community user questions - share your expertise
Follow us @DataStaxDevs
CONNECT
We are on Youtube - Twitter - Twitch!
89 49 47
Thank You