SlideShare a Scribd company logo
©2013 DataStax Confidential. Do not distribute without consent.
Old dog, new tricks
1
@PatrickMcFadin
Patrick McFadin

Chief Evangelist for Apache Cassandra at DataStax
Oracle Architecture
More CPU
More memory
More disk
DBRM
Clusterware
FAN
RAC
Data Guard
Golden Gate
Cache Fusion
Active?
Standby?
TimesTen
Scale
Hadoop
Scale
Scale
Uptime
Uptime
Uptime
ASM
• Think a YouTube competitor
– Users add videos, rate them, comment on them, etc.
– Can search for videos by tag
DataStax: Old Dogs, New Tricks. Teaching your Relational DBA to fetch
DataStax: Old Dogs, New Tricks. Teaching your Relational DBA to fetch
CREATE TABLE users (

id number(12) NOT NULL ,

firstname nvarchar2(25) NOT NULL ,

lastname nvarchar2(25) NOT NULL,

email nvarchar2(50) NOT NULL,

password nvarchar2(255) NOT NULL,

created_date timestamp(6),

PRIMARY KEY (id),

CONSTRAINT email_uq UNIQUE (email)

);
-- Users by email address index

CREATE INDEX idx_users_email ON users (email);
• Create entity table
• Add constraints
• Index fields
• Foreign Key relationships
CREATE TABLE videos (

id number(12),

userid number(12) NOT NULL,

name nvarchar2(255),

description nvarchar2(500),

location nvarchar2(255),

location_type int,

added_date timestamp,

CONSTRAINT users_userid_fk
FOREIGN KEY (userid)
REFERENCES users (Id) ON DELETE CASCADE,

PRIMARY KEY (id)

);
“Static” Table
CREATE TABLE videos (

videoid uuid,

userid uuid,

name varchar,

description varchar,

location text,

location_type int,

preview_thumbnails map<text,text>,

tags set<varchar>,

added_date timestamp,

PRIMARY KEY (videoid)

);
Table Name
Column Name
Column CQL Type
Primary Key Designation Partition Key
Row
Column
1
Partition
Key 1
Column
2
Column
3
Column
4
Partition
Column
1
Partition
Key 1
Column
2
Column
3
Column
4
Column
1
Partition
Key 1
Column
2
Column
3
Column
4
Column
1
Partition
Key 1
Column
2
Column
3
Column
4
Column
1
Partition
Key 1
Column
2
Column
3
Column
4
Table Column
1
Partition
Key 1
Column
2
Column
3
Column
4
Column
1
Partition
Key 1
Column
2
Column
3
Column
4
Column
1
Partition
Key 1
Column
2
Column
3
Column
4
Column
1
Partition
Key 1
Column
2
Column
3
Column
4
Column
1
Partition
Key 2
Column
2
Column
3
Column
4
Column
1
Column
2
Column
3
Column
4
Column
1
Column
2
Column
3
Column
4
Column
1
Column
2
Column
3
Column
4
Partition
Key 2
Partition
Key 2
Partition
Key 2
Keyspace
Column
1
Partition
Key 1
Column
2
Column
3
Column
4
Column
1
Partition
Key 2
Column
2
Column
3
Column
4
Column
1
Partition
Key 1
Column
2
Column
3
Column
4
Column
1
Partition
Key 1
Column
2
Column
3
Column
4
Column
1
Partition
Key 1
Column
2
Column
3
Column
4
Column
1
Partition
Key 2
Column
2
Column
3
Column
4
Column
1
Partition
Key 2
Column
2
Column
3
Column
4
Column
1
Partition
Key 2
Column
2
Column
3
Column
4
Column
1
Partition
Key 1
Column
2
Column
3
Column
4
Column
1
Partition
Key 2
Column
2
Column
3
Column
4
Column
1
Partition
Key 1
Column
2
Column
3
Column
4
Column
1
Partition
Key 1
Column
2
Column
3
Column
4
Column
1
Partition
Key 1
Column
2
Column
3
Column
4
Column
1
Partition
Key 2
Column
2
Column
3
Column
4
Column
1
Partition
Key 2
Column
2
Column
3
Column
4
Column
1
Partition
Key 2
Column
2
Column
3
Column
4
Table 1 Table 2
Keyspace 1
Insert
INSERT INTO videos (videoid, name, userid, description, location, location_type, preview_thumbnails, tags, added_date, metadata)

VALUES (06049cbb-dfed-421f-b889-5f649a0de1ed,'The data model is dead. Long live the data model.',
9761d3d7-7fbd-4269-9988-6cfd4e188678, 

'First in a three part series for Cassandra Data Modeling','http://www.youtube.com/watch?v=px6U2n74q3g',1,

{'YouTube':'http://www.youtube.com/watch?v=px6U2n74q3g'},{'cassandra','data model','relational','instruction'},

'2013-05-02 12:30:29');
Table Name
Fields
Values
Partition Key: Required
Partition keys
06049cbb-dfed-421f-b889-5f649a0de1ed Murmur3 Hash Token = 7224631062609997448
873ff430-9c23-4e60-be5f-278ea2bb21bd Murmur3 Hash Token = -6804302034103043898
Consistent hash. 128 bit number
between 2-63
and 264
INSERT INTO videos (videoid, name, userid, description)

VALUES (06049cbb-dfed-421f-b889-5f649a0de1ed,'The data model is dead. Long live the data model.’,
9761d3d7-7fbd-4269-9988-6cfd4e188678, 'First in a three part series for Cassandra Data Modeling');
INSERT INTO videos (videoid, name, userid, description)

VALUES (873ff430-9c23-4e60-be5f-278ea2bb21bd,'Become a Super Modeler’,
9761d3d7-7fbd-4269-9988-6cfd4e188678, 'Second in a three part series for Cassandra Data Modeling');
“Dynamic” Table
CREATE TABLE videos_by_tag (

tag text,

videoid uuid,

added_date timestamp,

name text,

preview_image_location text,

tagged_date timestamp,

PRIMARY KEY (tag, videoid)

);
Partition Key Clustering Column
Primary key relationship
PRIMARY KEY (tag,videoid)
Primary key relationship
Partition Key
PRIMARY KEY (tag,videoid)
Primary key relationship
Partition Key Clustering Column
PRIMARY KEY (tag,videoid)
Primary key relationship
Partition Key
data model
PRIMARY KEY (tag,videoid)
Clustering Column
-5.6
06049cbb-dfed-421f-b889-5f649a0de1ed
Primary key relationship
Partition Key
2013-05-16 16:50:002013-05-02 12:30:29
873ff430-9c23-4e60-be5f-278ea2bb21bd
PRIMARY KEY (tag,videoid)
Clustering Column
data model
49f64d40-7d89-4890-b910-dbf923563a33
2013-06-11 11:00:00
Select
name | description | added_date

---------------------------------------------------+----------------------------------------------------------+--------------------------

The data model is dead. Long live the data model. | First in a three part series for Cassandra Data Modeling | 2013-05-02 12:30:29-0700
SELECT name, description, added_date

FROM videos

WHERE videoid = 06049cbb-dfed-421f-b889-5f649a0de1ed;
Fields
Table Name
Primary Key: Partition Key Required
Controlling Order
CREATE TABLE raw_weather_data (

wsid text,

year int,

month int,

day int,

hour int,

temperature double,

PRIMARY KEY ((wsid), year, month, day, hour)

) WITH CLUSTERING ORDER BY (year DESC, month DESC, day DESC, hour DESC);
INSERT INTO raw_weather_data(wsid,year,month,day,hour,temperature)

VALUES (‘10010:99999’,2005,12,1,10,-5.6);
INSERT INTO raw_weather_data(wsid,year,month,day,hour,temperature)

VALUES (‘10010:99999’,2005,12,1,9,-5.1);
INSERT INTO raw_weather_data(wsid,year,month,day,hour,temperature)

VALUES (‘10010:99999’,2005,12,1,8,-4.9);
INSERT INTO raw_weather_data(wsid,year,month,day,hour,temperature)

VALUES (‘10010:99999’,2005,12,1,7,-5.3);
Clustering
200510010:99999 12 1 10
200510010:99999 12 1 9
raw_weather_data
-5.6
-5.1
200510010:99999 12 1 8
200510010:99999 12 1 7
-4.9
-5.3
Order By
DESC
• Think a YouTube competitor
– Users add videos, rate them, comment on them, etc.
– Can search for videos by tag
DataStax: Old Dogs, New Tricks. Teaching your Relational DBA to fetch
DataStax: Old Dogs, New Tricks. Teaching your Relational DBA to fetch
CREATE TABLE users (

id number(12) NOT NULL ,

firstname nvarchar2(25) NOT NULL ,

lastname nvarchar2(25) NOT NULL,

email nvarchar2(50) NOT NULL,

password nvarchar2(255) NOT NULL,

created_date timestamp(6),

PRIMARY KEY (id),

CONSTRAINT email_uq UNIQUE (email)

);
-- Users by email address index

CREATE INDEX idx_users_email ON users (email);
• Create entity table
• Add constraints
• Index fields
• Foreign Key relationships
CREATE TABLE videos (

id number(12),

userid number(12) NOT NULL,

name nvarchar2(255),

description nvarchar2(500),

location nvarchar2(255),

location_type int,

added_date timestamp,

CONSTRAINT users_userid_fk
FOREIGN KEY (userid)
REFERENCES users (Id) ON DELETE CASCADE,

PRIMARY KEY (id)

);
Some Application Workflows in KillrVideo
27
User Logs
into site
Show basic
information
about user
Show videos
added by a
user
Show
comments
posted by a
user
Search for a
video by tag
Show latest
videos
added to the
site
Show
comments
for a video
Show
ratings for a
video
Show video
and its
details
28
Show video
and its
details
Find video by id
Show videos
added by a
user
Find videos by user
(latest first)
CREATE TABLE videos (

videoid uuid,

userid uuid,

name text,

description text,

location text,

location_type int,

preview_image_location text,

tags set<text>,

added_date timestamp,

PRIMARY KEY (videoid)

);
CREATE TABLE user_videos (

userid uuid,

added_date timestamp,

videoid uuid,

name text,

preview_image_location text,

PRIMARY KEY (userid, added_date, videoid)

) WITH CLUSTERING
ORDER BY (added_date DESC, videoid ASC);
Views or indexes?
Denormalized data
Opps!
29
Table A
Client
Opps!
30
Table A
Client
Table B
Opps!
31
Table A
Client
Table B
Opps!
32
Table A
Client
Table B
Opps!
33
Client
Table B
Thank you!
Bring the questions
Follow me on twitter
@PatrickMcFadin

More Related Content

PDF
Introduction to Data Modeling with Apache Cassandra
PDF
Advanced Data Modeling with Apache Cassandra
PDF
Apache Cassandra & Data Modeling
PDF
Tech Talk: Best Practices for Data Modeling
PDF
Real data models of silicon valley
PDF
Percona Live 4/15/15: Transparent sharding database virtualization engine (DVE)
PDF
Cassandra nice use cases and worst anti patterns
PPTX
Introduction to Data Modeling with Apache Cassandra
Advanced Data Modeling with Apache Cassandra
Apache Cassandra & Data Modeling
Tech Talk: Best Practices for Data Modeling
Real data models of silicon valley
Percona Live 4/15/15: Transparent sharding database virtualization engine (DVE)
Cassandra nice use cases and worst anti patterns

What's hot (20)

PDF
CQL3 in depth
TXT
Hanya contoh saja dari xampp
PDF
Extending Spark SQL API with Easier to Use Array Types Operations with Marek ...
PDF
Tracking Data Updates in Real-time with Change Data Capture
PDF
Highload2o013 osipv
PDF
PostgreSQL: Advanced indexing
PDF
MySQL SQL Tutorial
PDF
Developers' mDay 2017. - Bogdan Kecman Oracle
PDF
Mssm及assm下索引叶块分裂的测试
PDF
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
PPT
Oracle PL-SQL
PDF
第7回 大規模データを用いたデータフレーム操作実習(1)
PDF
Scaling the #2ndhalf
PDF
Automated Debugging of Big Data Analytics in Apache Spark Using BigSift with ...
PDF
Tiered storage intro. By Robert Hodges, Altinity CEO
PDF
EKON22 Introduction to Machinelearning
PDF
【Maclean liu技术分享】拨开oracle cbo优化器迷雾,探究histogram直方图之秘 0321
PDF
ClickHouse Unleashed 2020: Our Favorite New Features for Your Analytical Appl...
PPTX
Axis2 client memory leak
PPTX
Finding SQL execution outliers
CQL3 in depth
Hanya contoh saja dari xampp
Extending Spark SQL API with Easier to Use Array Types Operations with Marek ...
Tracking Data Updates in Real-time with Change Data Capture
Highload2o013 osipv
PostgreSQL: Advanced indexing
MySQL SQL Tutorial
Developers' mDay 2017. - Bogdan Kecman Oracle
Mssm及assm下索引叶块分裂的测试
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
Oracle PL-SQL
第7回 大規模データを用いたデータフレーム操作実習(1)
Scaling the #2ndhalf
Automated Debugging of Big Data Analytics in Apache Spark Using BigSift with ...
Tiered storage intro. By Robert Hodges, Altinity CEO
EKON22 Introduction to Machinelearning
【Maclean liu技术分享】拨开oracle cbo优化器迷雾,探究histogram直方图之秘 0321
ClickHouse Unleashed 2020: Our Favorite New Features for Your Analytical Appl...
Axis2 client memory leak
Finding SQL execution outliers
Ad

Viewers also liked (20)

PDF
DataStax: How to Roll Cassandra into Production Without Losing your Health, M...
PDF
Battery Ventures: Simulating and Visualizing Large Scale Cassandra Deployments
PDF
DataStax: 7 Deadly Sins for Cassandra Ops
PDF
Cassandra Core Concepts
PDF
Crash course intro to cassandra
PDF
DataStax & O'Reilly Media: Large Scale Data Analytics with Spark and Cassandr...
PDF
Cassandra 3.0 Awesomeness
PDF
Diagnosing Problems in Production (Nov 2015)
PDF
Instaclustr: Securing Cassandra
PDF
DataStax: Making Cassandra Fail (for effective testing)
PDF
Diagnosing Problems in Production - Cassandra
PDF
Enter the Snake Pit for Fast and Easy Spark
PDF
DataStax: Enabling Search in your Cassandra Application with DataStax Enterprise
PDF
Spark and cassandra (Hulu Talk)
PDF
Cake Solutions: Cassandra as event sourced journal for big data analytics
PDF
Azure + DataStax Enterprise Powers Office 365 Per User Store
PDF
Cassandra meetup slides - Oct 15 Santa Monica Coloft
PDF
Cassandra Core Concepts - Cassandra Day Toronto
PDF
Python and cassandra
PDF
Large Scale Data Analytics with Spark and Cassandra on the DSE Platform
DataStax: How to Roll Cassandra into Production Without Losing your Health, M...
Battery Ventures: Simulating and Visualizing Large Scale Cassandra Deployments
DataStax: 7 Deadly Sins for Cassandra Ops
Cassandra Core Concepts
Crash course intro to cassandra
DataStax & O'Reilly Media: Large Scale Data Analytics with Spark and Cassandr...
Cassandra 3.0 Awesomeness
Diagnosing Problems in Production (Nov 2015)
Instaclustr: Securing Cassandra
DataStax: Making Cassandra Fail (for effective testing)
Diagnosing Problems in Production - Cassandra
Enter the Snake Pit for Fast and Easy Spark
DataStax: Enabling Search in your Cassandra Application with DataStax Enterprise
Spark and cassandra (Hulu Talk)
Cake Solutions: Cassandra as event sourced journal for big data analytics
Azure + DataStax Enterprise Powers Office 365 Per User Store
Cassandra meetup slides - Oct 15 Santa Monica Coloft
Cassandra Core Concepts - Cassandra Day Toronto
Python and cassandra
Large Scale Data Analytics with Spark and Cassandra on the DSE Platform
Ad

Similar to DataStax: Old Dogs, New Tricks. Teaching your Relational DBA to fetch (20)

PDF
Oracle to Cassandra Core Concepts Guide Pt. 2
PDF
1 Dundee - Cassandra 101
PDF
Cassandra - lesson learned
PDF
Introduction to Apache Cassandra™ + What’s New in 4.0
PDF
Cassandra lesson learned - extended
PDF
Cassandra, web scale no sql data platform
PDF
Owning time series with team apache Strata San Jose 2015
PDF
Manchester Hadoop User Group: Cassandra Intro
PDF
Cassandra 3.0 advanced preview
PDF
Cassandra Community Webinar | Getting Started with Apache Cassandra with Patr...
PDF
Advanced data modeling with apache cassandra
PDF
Advanced Cassandra
PDF
Time series with apache cassandra strata
PDF
Jan 2015 - Cassandra101 Manchester Meetup
PDF
Javantura v2 - Data modeling with Apapche Cassandra - Marko Švaljek
PDF
Introduction to data modeling with apache cassandra
PDF
Vienna Feb 2015: Cassandra: How it works and what it's good for!
PDF
Cassandra Day Atlanta 2015: Data Modeling 101
PDF
Cassandra Day Chicago 2015: Apache Cassandra Data Modeling 101
PDF
Cassandra Day London 2015: Data Modeling 101
Oracle to Cassandra Core Concepts Guide Pt. 2
1 Dundee - Cassandra 101
Cassandra - lesson learned
Introduction to Apache Cassandra™ + What’s New in 4.0
Cassandra lesson learned - extended
Cassandra, web scale no sql data platform
Owning time series with team apache Strata San Jose 2015
Manchester Hadoop User Group: Cassandra Intro
Cassandra 3.0 advanced preview
Cassandra Community Webinar | Getting Started with Apache Cassandra with Patr...
Advanced data modeling with apache cassandra
Advanced Cassandra
Time series with apache cassandra strata
Jan 2015 - Cassandra101 Manchester Meetup
Javantura v2 - Data modeling with Apapche Cassandra - Marko Švaljek
Introduction to data modeling with apache cassandra
Vienna Feb 2015: Cassandra: How it works and what it's good for!
Cassandra Day Atlanta 2015: Data Modeling 101
Cassandra Day Chicago 2015: Apache Cassandra Data Modeling 101
Cassandra Day London 2015: Data Modeling 101

More from DataStax Academy (20)

PDF
Forrester CXNYC 2017 - Delivering great real-time cx is a true craft
PPTX
Introduction to DataStax Enterprise Graph Database
PPTX
Introduction to DataStax Enterprise Advanced Replication with Apache Cassandra
PPTX
Cassandra on Docker @ Walmart Labs
PDF
Cassandra 3.0 Data Modeling
PPTX
Cassandra Adoption on Cisco UCS & Open stack
PDF
Data Modeling for Apache Cassandra
PDF
Coursera Cassandra Driver
PDF
Production Ready Cassandra
PDF
Cassandra @ Netflix: Monitoring C* at Scale, Gossip and Tickler & Python
PPTX
Cassandra @ Sony: The good, the bad, and the ugly part 1
PPTX
Cassandra @ Sony: The good, the bad, and the ugly part 2
PDF
Standing Up Your First Cluster
PDF
Real Time Analytics with Dse
PDF
Cassandra Core Concepts
PPTX
Enabling Search in your Cassandra Application with DataStax Enterprise
PPTX
Bad Habits Die Hard
PDF
Apache Cassandra and Drivers
PDF
Getting Started with Graph Databases
PDF
Cassandra Data Maintenance with Spark
Forrester CXNYC 2017 - Delivering great real-time cx is a true craft
Introduction to DataStax Enterprise Graph Database
Introduction to DataStax Enterprise Advanced Replication with Apache Cassandra
Cassandra on Docker @ Walmart Labs
Cassandra 3.0 Data Modeling
Cassandra Adoption on Cisco UCS & Open stack
Data Modeling for Apache Cassandra
Coursera Cassandra Driver
Production Ready Cassandra
Cassandra @ Netflix: Monitoring C* at Scale, Gossip and Tickler & Python
Cassandra @ Sony: The good, the bad, and the ugly part 1
Cassandra @ Sony: The good, the bad, and the ugly part 2
Standing Up Your First Cluster
Real Time Analytics with Dse
Cassandra Core Concepts
Enabling Search in your Cassandra Application with DataStax Enterprise
Bad Habits Die Hard
Apache Cassandra and Drivers
Getting Started with Graph Databases
Cassandra Data Maintenance with Spark

Recently uploaded (20)

PDF
cuic standard and advanced reporting.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Machine learning based COVID-19 study performance prediction
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Big Data Technologies - Introduction.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Approach and Philosophy of On baking technology
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
cuic standard and advanced reporting.pdf
Understanding_Digital_Forensics_Presentation.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Machine learning based COVID-19 study performance prediction
Building Integrated photovoltaic BIPV_UPV.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Encapsulation_ Review paper, used for researhc scholars
Big Data Technologies - Introduction.pptx
Unlocking AI with Model Context Protocol (MCP)
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Approach and Philosophy of On baking technology
Chapter 3 Spatial Domain Image Processing.pdf
Electronic commerce courselecture one. Pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Spectral efficient network and resource selection model in 5G networks
Digital-Transformation-Roadmap-for-Companies.pptx

DataStax: Old Dogs, New Tricks. Teaching your Relational DBA to fetch

  • 1. ©2013 DataStax Confidential. Do not distribute without consent. Old dog, new tricks 1 @PatrickMcFadin Patrick McFadin
 Chief Evangelist for Apache Cassandra at DataStax
  • 2. Oracle Architecture More CPU More memory More disk DBRM Clusterware FAN RAC Data Guard Golden Gate Cache Fusion Active? Standby? TimesTen Scale Hadoop Scale Scale Uptime Uptime Uptime ASM
  • 3. • Think a YouTube competitor – Users add videos, rate them, comment on them, etc. – Can search for videos by tag
  • 6. CREATE TABLE users (
 id number(12) NOT NULL ,
 firstname nvarchar2(25) NOT NULL ,
 lastname nvarchar2(25) NOT NULL,
 email nvarchar2(50) NOT NULL,
 password nvarchar2(255) NOT NULL,
 created_date timestamp(6),
 PRIMARY KEY (id),
 CONSTRAINT email_uq UNIQUE (email)
 ); -- Users by email address index
 CREATE INDEX idx_users_email ON users (email); • Create entity table • Add constraints • Index fields • Foreign Key relationships CREATE TABLE videos (
 id number(12),
 userid number(12) NOT NULL,
 name nvarchar2(255),
 description nvarchar2(500),
 location nvarchar2(255),
 location_type int,
 added_date timestamp,
 CONSTRAINT users_userid_fk FOREIGN KEY (userid) REFERENCES users (Id) ON DELETE CASCADE,
 PRIMARY KEY (id)
 );
  • 7. “Static” Table CREATE TABLE videos (
 videoid uuid,
 userid uuid,
 name varchar,
 description varchar,
 location text,
 location_type int,
 preview_thumbnails map<text,text>,
 tags set<varchar>,
 added_date timestamp,
 PRIMARY KEY (videoid)
 ); Table Name Column Name Column CQL Type Primary Key Designation Partition Key
  • 10. Table Column 1 Partition Key 1 Column 2 Column 3 Column 4 Column 1 Partition Key 1 Column 2 Column 3 Column 4 Column 1 Partition Key 1 Column 2 Column 3 Column 4 Column 1 Partition Key 1 Column 2 Column 3 Column 4 Column 1 Partition Key 2 Column 2 Column 3 Column 4 Column 1 Column 2 Column 3 Column 4 Column 1 Column 2 Column 3 Column 4 Column 1 Column 2 Column 3 Column 4 Partition Key 2 Partition Key 2 Partition Key 2
  • 11. Keyspace Column 1 Partition Key 1 Column 2 Column 3 Column 4 Column 1 Partition Key 2 Column 2 Column 3 Column 4 Column 1 Partition Key 1 Column 2 Column 3 Column 4 Column 1 Partition Key 1 Column 2 Column 3 Column 4 Column 1 Partition Key 1 Column 2 Column 3 Column 4 Column 1 Partition Key 2 Column 2 Column 3 Column 4 Column 1 Partition Key 2 Column 2 Column 3 Column 4 Column 1 Partition Key 2 Column 2 Column 3 Column 4 Column 1 Partition Key 1 Column 2 Column 3 Column 4 Column 1 Partition Key 2 Column 2 Column 3 Column 4 Column 1 Partition Key 1 Column 2 Column 3 Column 4 Column 1 Partition Key 1 Column 2 Column 3 Column 4 Column 1 Partition Key 1 Column 2 Column 3 Column 4 Column 1 Partition Key 2 Column 2 Column 3 Column 4 Column 1 Partition Key 2 Column 2 Column 3 Column 4 Column 1 Partition Key 2 Column 2 Column 3 Column 4 Table 1 Table 2 Keyspace 1
  • 12. Insert INSERT INTO videos (videoid, name, userid, description, location, location_type, preview_thumbnails, tags, added_date, metadata)
 VALUES (06049cbb-dfed-421f-b889-5f649a0de1ed,'The data model is dead. Long live the data model.', 9761d3d7-7fbd-4269-9988-6cfd4e188678, 
 'First in a three part series for Cassandra Data Modeling','http://www.youtube.com/watch?v=px6U2n74q3g',1,
 {'YouTube':'http://www.youtube.com/watch?v=px6U2n74q3g'},{'cassandra','data model','relational','instruction'},
 '2013-05-02 12:30:29'); Table Name Fields Values Partition Key: Required
  • 13. Partition keys 06049cbb-dfed-421f-b889-5f649a0de1ed Murmur3 Hash Token = 7224631062609997448 873ff430-9c23-4e60-be5f-278ea2bb21bd Murmur3 Hash Token = -6804302034103043898 Consistent hash. 128 bit number between 2-63 and 264 INSERT INTO videos (videoid, name, userid, description)
 VALUES (06049cbb-dfed-421f-b889-5f649a0de1ed,'The data model is dead. Long live the data model.’, 9761d3d7-7fbd-4269-9988-6cfd4e188678, 'First in a three part series for Cassandra Data Modeling'); INSERT INTO videos (videoid, name, userid, description)
 VALUES (873ff430-9c23-4e60-be5f-278ea2bb21bd,'Become a Super Modeler’, 9761d3d7-7fbd-4269-9988-6cfd4e188678, 'Second in a three part series for Cassandra Data Modeling');
  • 14. “Dynamic” Table CREATE TABLE videos_by_tag (
 tag text,
 videoid uuid,
 added_date timestamp,
 name text,
 preview_image_location text,
 tagged_date timestamp,
 PRIMARY KEY (tag, videoid)
 ); Partition Key Clustering Column
  • 15. Primary key relationship PRIMARY KEY (tag,videoid)
  • 16. Primary key relationship Partition Key PRIMARY KEY (tag,videoid)
  • 17. Primary key relationship Partition Key Clustering Column PRIMARY KEY (tag,videoid)
  • 18. Primary key relationship Partition Key data model PRIMARY KEY (tag,videoid) Clustering Column
  • 19. -5.6 06049cbb-dfed-421f-b889-5f649a0de1ed Primary key relationship Partition Key 2013-05-16 16:50:002013-05-02 12:30:29 873ff430-9c23-4e60-be5f-278ea2bb21bd PRIMARY KEY (tag,videoid) Clustering Column data model 49f64d40-7d89-4890-b910-dbf923563a33 2013-06-11 11:00:00
  • 20. Select name | description | added_date
 ---------------------------------------------------+----------------------------------------------------------+--------------------------
 The data model is dead. Long live the data model. | First in a three part series for Cassandra Data Modeling | 2013-05-02 12:30:29-0700 SELECT name, description, added_date
 FROM videos
 WHERE videoid = 06049cbb-dfed-421f-b889-5f649a0de1ed; Fields Table Name Primary Key: Partition Key Required
  • 21. Controlling Order CREATE TABLE raw_weather_data (
 wsid text,
 year int,
 month int,
 day int,
 hour int,
 temperature double,
 PRIMARY KEY ((wsid), year, month, day, hour)
 ) WITH CLUSTERING ORDER BY (year DESC, month DESC, day DESC, hour DESC); INSERT INTO raw_weather_data(wsid,year,month,day,hour,temperature)
 VALUES (‘10010:99999’,2005,12,1,10,-5.6); INSERT INTO raw_weather_data(wsid,year,month,day,hour,temperature)
 VALUES (‘10010:99999’,2005,12,1,9,-5.1); INSERT INTO raw_weather_data(wsid,year,month,day,hour,temperature)
 VALUES (‘10010:99999’,2005,12,1,8,-4.9); INSERT INTO raw_weather_data(wsid,year,month,day,hour,temperature)
 VALUES (‘10010:99999’,2005,12,1,7,-5.3);
  • 22. Clustering 200510010:99999 12 1 10 200510010:99999 12 1 9 raw_weather_data -5.6 -5.1 200510010:99999 12 1 8 200510010:99999 12 1 7 -4.9 -5.3 Order By DESC
  • 23. • Think a YouTube competitor – Users add videos, rate them, comment on them, etc. – Can search for videos by tag
  • 26. CREATE TABLE users (
 id number(12) NOT NULL ,
 firstname nvarchar2(25) NOT NULL ,
 lastname nvarchar2(25) NOT NULL,
 email nvarchar2(50) NOT NULL,
 password nvarchar2(255) NOT NULL,
 created_date timestamp(6),
 PRIMARY KEY (id),
 CONSTRAINT email_uq UNIQUE (email)
 ); -- Users by email address index
 CREATE INDEX idx_users_email ON users (email); • Create entity table • Add constraints • Index fields • Foreign Key relationships CREATE TABLE videos (
 id number(12),
 userid number(12) NOT NULL,
 name nvarchar2(255),
 description nvarchar2(500),
 location nvarchar2(255),
 location_type int,
 added_date timestamp,
 CONSTRAINT users_userid_fk FOREIGN KEY (userid) REFERENCES users (Id) ON DELETE CASCADE,
 PRIMARY KEY (id)
 );
  • 27. Some Application Workflows in KillrVideo 27 User Logs into site Show basic information about user Show videos added by a user Show comments posted by a user Search for a video by tag Show latest videos added to the site Show comments for a video Show ratings for a video Show video and its details
  • 28. 28 Show video and its details Find video by id Show videos added by a user Find videos by user (latest first) CREATE TABLE videos (
 videoid uuid,
 userid uuid,
 name text,
 description text,
 location text,
 location_type int,
 preview_image_location text,
 tags set<text>,
 added_date timestamp,
 PRIMARY KEY (videoid)
 ); CREATE TABLE user_videos (
 userid uuid,
 added_date timestamp,
 videoid uuid,
 name text,
 preview_image_location text,
 PRIMARY KEY (userid, added_date, videoid)
 ) WITH CLUSTERING ORDER BY (added_date DESC, videoid ASC); Views or indexes? Denormalized data
  • 34. Thank you! Bring the questions Follow me on twitter @PatrickMcFadin