SlideShare ist ein Scribd-Unternehmen logo
1 von 42
Downloaden Sie, um offline zu lesen
Coursera, Cassandra, Java Drivers
Biography
Daniel Chia
@DanielJHChia
Software Engineer, Infrastructure Team
2
1 Introduction
2 Why We Chose Cassandra
3 Example Use Cases
4 Pain Points
5 Java Drivers
Coursera
4
5
6
Web
iOS
Android
Why Cassandra
7
Coursera Tech Stack
• 100% AWS
• MySQL + Cassandra
• Service-oriented
8
Consistently Fast Latencies
9
Availability
10
Scalability
11
Use Case #1
• Resume video where you left off
• High write volume
• TTL data
12
13
CREATE TABLE video_progress_kvs_basic (
user_id int,
course_id varchar,
video_id varchar,
viewed_up_to bigint,
updated_at bigint
PRIMARY KEY ((user_id, course_id, video_id))
);
Use Case #2: Media Asset Service
14
15
16
Use case #3: Video Workflows
17
Input.mp4
Step 1: Audio
Step 2: Low Res Video
Step 3: High Res Video
Assembly 1: Crash
Assembly 2: Ok
Assembly 3: Crash
Assembly 4: Ok
Assembly 5: Ok
18
CREATE TABLE transloadit_workflow (
workflow_id text,
step_id text,
assembly_id text,
step_details text,
step_payload map<text, text>,
step_status text,
PRIMARY KEY (workflow_id, step_id, assembly_id)
)
19
20
Looking Back
Cassandra - Initial Pain Points
• Can’t execute arbitrary queries
• Filtering, sorting, etc.
• Can’t be abused as an OLAP database
• Worries about ‘eventual’ consistency
21
Gotchas
• Lots of truly ad-hoc queries is hard
• Don’t use C* directly to explore your data. (Spark?)
• Sorting, filtering can be hard
• Consider Solr / ElasticSearch
• Or even MySQL depending on load / importance
22
Helpful Things
• Data modeling consulting
• Monitoring
• Data access layer for common use cases
23
24
25
Java Drivers
Best Practices
• Driver Choice
• Cluster / Connection Setup
• Executing Queries
27
28
Datastax Java Drivers
29
public class Scratch {
static Cluster cluster;
public static void main(String args[]) {
cluster = Cluster.builder()
.addContactPoint("cassandra")
.build();
readRow("asset:QoMqLLyCEeSOi3paAormVw");
cluster.close();
}
static void readRow(String id) {
Session session = cluster.connect("asset");
ResultSet result = session.execute(
"SELECT * from asset_kvs_timestamp where part_key = ?", id);
System.out.println(result.one());
session.close();
}
}
30
cluster = Cluster.builder()
.addContactPoint("cassandra")
.build();
31
LoadBalancingPolicy policy =
new TokenAwarePolicy(
new DCAwareRoundRobinPolicy());
cluster = Cluster.builder()
.addContactPoint(“cassandra")
.withLoadBalancingPolicy(policy)
.build();
32
cluster = Cluster.builder()
.addContactPoint(“cassandra")
.withLoadBalancingPolicy(policy)
.withRetryPolicy(retryPolicy)
.build();
Default Retry Policy
• Retries read if enough replicas alive, but data fetch failed.
• Retries write only for batched writes.
• Retries next host on Unavailable. 2.0.11+ or 2.1.7 (JAVA-709)
33
Share Session!
34
public static void main(String args[]) {
cluster = Cluster.builder()
.addContactPoint(“cassandra”).build();
readRow("asset:QoMqLLyCEeSOi3paAormVw");
readRow("asset:7i2ClbKnEeSk_npaAormVw");
readRow("asset:KS1vywpGEeWKtzoMw4q1xg");
cluster.close();
}
static void readRow(String id) {
Session session = cluster.connect("asset");
ResultSet result = session.execute(
"SELECT * from asset_kvs_timestamp where part_key = ?", id);
System.out.println(result.one());
session.close();
}
35
public static void main(String args[]) {
cluster =
Cluster.builder()
.addContactPoint("cassandra").build();
session = cluster.connect();
readRow("asset:QoMqLLyCEeSOi3paAormVw");
readRow("asset:7i2ClbKnEeSk_npaAormVw");
readRow("asset:KS1vywpGEeWKtzoMw4q1xg");
session.close();
cluster.close();
}
static void readRow(String id) {
ResultSet result = session.execute(
"SELECT * from asset.asset_kvs_timestamp where part_key = ?", id);
System.out.println(result.one());
}
Use prepared statements
• If doing query more than once
• Better performance
• Token aware routing
36
37
static PreparedStatement statement;
public static void main(String args[]) {
…
session = cluster.connect();
statement = session.prepare(
"SELECT * from asset.asset_kvs_timestamp where part_key = ?")
readRow("asset:QoMqLLyCEeSOi3paAormVw");
…
}
static void readRow(String id) {
BoundStatement bound = statement.bind().setString("part_key", id);
ResultSet result = session.execute(bound);
System.out.println(result.one());
}
There Be Dragons.. JAVA-420
statement = session.prepare(
"SELECT part_key, time_key, content
from asset.asset_kvs_timestamp where part_key = ?")
38
Always specify columns explicitly for prepared statements!
Consider Async
static List<String> readRows(List<String> ids) {
return ids.stream().map(id -> {
BoundStatement bound = statement.bind().setString("part_key", id);
ResultSet result = session.execute(bound);
return result.one().getString("c_enc");
}).collect(Collectors.toList());
}
39
Async..
static ListenableFuture<List<String>> readRowsAsync(List<String> ids) {
List<ListenableFuture<String>> futures = ids.stream().map(id -> {
BoundStatement bound = statement.bind().setString("part_key", id);
ResultSetFuture future = session.executeAsync(bound);
return Futures.transform(future, (ResultSet result) -> 

result.one().getString(“c_enc"));
}).collect(Collectors.toList());
return Futures.allAsList(futures);
}
40
http://www.datastax.com/dev/blog/java-driver-async-queries
Thank you
Cassandra Summit 2016 

September 7-9 

San Jose, CA
Get 15% Off with Code: MeetupPromo

Cassandrasummit.org

Weitere ähnliche Inhalte

Was ist angesagt?

DataStax | Advanced DSE Analytics Client Configuration (Jacek Lewandowski) | ...
DataStax | Advanced DSE Analytics Client Configuration (Jacek Lewandowski) | ...DataStax | Advanced DSE Analytics Client Configuration (Jacek Lewandowski) | ...
DataStax | Advanced DSE Analytics Client Configuration (Jacek Lewandowski) | ...
DataStax
 
The world's next top data model
The world's next top data modelThe world's next top data model
The world's next top data model
Patrick McFadin
 
From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016
From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016
From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016
DataStax
 

Was ist angesagt? (20)

Real data models of silicon valley
Real data models of silicon valleyReal data models of silicon valley
Real data models of silicon valley
 
Spark Cassandra Connector: Past, Present and Furure
Spark Cassandra Connector: Past, Present and FurureSpark Cassandra Connector: Past, Present and Furure
Spark Cassandra Connector: Past, Present and Furure
 
DataStax: An Introduction to DataStax Enterprise Search
DataStax: An Introduction to DataStax Enterprise SearchDataStax: An Introduction to DataStax Enterprise Search
DataStax: An Introduction to DataStax Enterprise Search
 
Cassandra 3.0 Awesomeness
Cassandra 3.0 AwesomenessCassandra 3.0 Awesomeness
Cassandra 3.0 Awesomeness
 
Beyond the Query: A Cassandra + Solr + Spark Love Triangle Using Datastax Ent...
Beyond the Query: A Cassandra + Solr + Spark Love Triangle Using Datastax Ent...Beyond the Query: A Cassandra + Solr + Spark Love Triangle Using Datastax Ent...
Beyond the Query: A Cassandra + Solr + Spark Love Triangle Using Datastax Ent...
 
Storing time series data with Apache Cassandra
Storing time series data with Apache CassandraStoring time series data with Apache Cassandra
Storing time series data with Apache Cassandra
 
Cassandra EU - Data model on fire
Cassandra EU - Data model on fireCassandra EU - Data model on fire
Cassandra EU - Data model on fire
 
DataStax | Advanced DSE Analytics Client Configuration (Jacek Lewandowski) | ...
DataStax | Advanced DSE Analytics Client Configuration (Jacek Lewandowski) | ...DataStax | Advanced DSE Analytics Client Configuration (Jacek Lewandowski) | ...
DataStax | Advanced DSE Analytics Client Configuration (Jacek Lewandowski) | ...
 
Cassandra 2.0 and timeseries
Cassandra 2.0 and timeseriesCassandra 2.0 and timeseries
Cassandra 2.0 and timeseries
 
Time series with apache cassandra strata
Time series with apache cassandra   strataTime series with apache cassandra   strata
Time series with apache cassandra strata
 
DataStax | Best Practices for Securing DataStax Enterprise (Matt Kennedy) | C...
DataStax | Best Practices for Securing DataStax Enterprise (Matt Kennedy) | C...DataStax | Best Practices for Securing DataStax Enterprise (Matt Kennedy) | C...
DataStax | Best Practices for Securing DataStax Enterprise (Matt Kennedy) | C...
 
Apache Cassandra & Data Modeling
Apache Cassandra & Data ModelingApache Cassandra & Data Modeling
Apache Cassandra & Data Modeling
 
DataStax | Data Science with DataStax Enterprise (Brian Hess) | Cassandra Sum...
DataStax | Data Science with DataStax Enterprise (Brian Hess) | Cassandra Sum...DataStax | Data Science with DataStax Enterprise (Brian Hess) | Cassandra Sum...
DataStax | Data Science with DataStax Enterprise (Brian Hess) | Cassandra Sum...
 
Cassandra Basics, Counters and Time Series Modeling
Cassandra Basics, Counters and Time Series ModelingCassandra Basics, Counters and Time Series Modeling
Cassandra Basics, Counters and Time Series Modeling
 
A Cassandra + Solr + Spark Love Triangle Using DataStax Enterprise
A Cassandra + Solr + Spark Love Triangle Using DataStax EnterpriseA Cassandra + Solr + Spark Love Triangle Using DataStax Enterprise
A Cassandra + Solr + Spark Love Triangle Using DataStax Enterprise
 
The world's next top data model
The world's next top data modelThe world's next top data model
The world's next top data model
 
From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016
From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016
From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016
 
Cassandra 3.0
Cassandra 3.0Cassandra 3.0
Cassandra 3.0
 
Cassandra Day NY 2014: Getting Started with the DataStax C# Driver
Cassandra Day NY 2014: Getting Started with the DataStax C# DriverCassandra Day NY 2014: Getting Started with the DataStax C# Driver
Cassandra Day NY 2014: Getting Started with the DataStax C# Driver
 
Introduction to data modeling with apache cassandra
Introduction to data modeling with apache cassandraIntroduction to data modeling with apache cassandra
Introduction to data modeling with apache cassandra
 

Andere mochten auch

Standing Up Your First Cluster
Standing Up Your First ClusterStanding Up Your First Cluster
Standing Up Your First Cluster
DataStax Academy
 
Cassandra Adoption on Cisco UCS & Open stack
Cassandra Adoption on Cisco UCS & Open stackCassandra Adoption on Cisco UCS & Open stack
Cassandra Adoption on Cisco UCS & Open stack
DataStax Academy
 
Cassandra @ Netflix: Monitoring C* at Scale, Gossip and Tickler & Python
Cassandra @ Netflix: Monitoring C* at Scale, Gossip and Tickler & PythonCassandra @ Netflix: Monitoring C* at Scale, Gossip and Tickler & Python
Cassandra @ Netflix: Monitoring C* at Scale, Gossip and Tickler & Python
DataStax Academy
 
Cassandra on Docker @ Walmart Labs
Cassandra on Docker @ Walmart LabsCassandra on Docker @ Walmart Labs
Cassandra on Docker @ Walmart Labs
DataStax Academy
 
Real Time Analytics with Dse
Real Time Analytics with DseReal Time Analytics with Dse
Real Time Analytics with Dse
DataStax Academy
 

Andere mochten auch (20)

Introduction to DataStax Enterprise Graph Database
Introduction to DataStax Enterprise Graph DatabaseIntroduction to DataStax Enterprise Graph Database
Introduction to DataStax Enterprise Graph Database
 
Bad Habits Die Hard
Bad Habits Die Hard Bad Habits Die Hard
Bad Habits Die Hard
 
Standing Up Your First Cluster
Standing Up Your First ClusterStanding Up Your First Cluster
Standing Up Your First Cluster
 
Cassandra Core Concepts
Cassandra Core ConceptsCassandra Core Concepts
Cassandra Core Concepts
 
Production Ready Cassandra
Production Ready CassandraProduction Ready Cassandra
Production Ready Cassandra
 
Cassandra Adoption on Cisco UCS & Open stack
Cassandra Adoption on Cisco UCS & Open stackCassandra Adoption on Cisco UCS & Open stack
Cassandra Adoption on Cisco UCS & Open stack
 
Introduction to DataStax Enterprise Advanced Replication with Apache Cassandra
Introduction to DataStax Enterprise Advanced Replication with Apache CassandraIntroduction to DataStax Enterprise Advanced Replication with Apache Cassandra
Introduction to DataStax Enterprise Advanced Replication with Apache Cassandra
 
Cassandra @ Netflix: Monitoring C* at Scale, Gossip and Tickler & Python
Cassandra @ Netflix: Monitoring C* at Scale, Gossip and Tickler & PythonCassandra @ Netflix: Monitoring C* at Scale, Gossip and Tickler & Python
Cassandra @ Netflix: Monitoring C* at Scale, Gossip and Tickler & Python
 
Data Modeling for Apache Cassandra
Data Modeling for Apache CassandraData Modeling for Apache Cassandra
Data Modeling for Apache Cassandra
 
Cassandra on Docker @ Walmart Labs
Cassandra on Docker @ Walmart LabsCassandra on Docker @ Walmart Labs
Cassandra on Docker @ Walmart Labs
 
Cassandra @ Sony: The good, the bad, and the ugly part 1
Cassandra @ Sony: The good, the bad, and the ugly part 1Cassandra @ Sony: The good, the bad, and the ugly part 1
Cassandra @ Sony: The good, the bad, and the ugly part 1
 
Cassandra @ Sony: The good, the bad, and the ugly part 2
Cassandra @ Sony: The good, the bad, and the ugly part 2Cassandra @ Sony: The good, the bad, and the ugly part 2
Cassandra @ Sony: The good, the bad, and the ugly part 2
 
Real Time Analytics with Dse
Real Time Analytics with DseReal Time Analytics with Dse
Real Time Analytics with Dse
 
Getting Started with Graph Databases
Getting Started with Graph DatabasesGetting Started with Graph Databases
Getting Started with Graph Databases
 
Analytics with Spark and Cassandra
Analytics with Spark and CassandraAnalytics with Spark and Cassandra
Analytics with Spark and Cassandra
 
Cassandra Data Maintenance with Spark
Cassandra Data Maintenance with SparkCassandra Data Maintenance with Spark
Cassandra Data Maintenance with Spark
 
Successful Software Development with Apache Cassandra
Successful Software Development with Apache CassandraSuccessful Software Development with Apache Cassandra
Successful Software Development with Apache Cassandra
 
Cassandra: One (is the loneliest number)
Cassandra: One (is the loneliest number)Cassandra: One (is the loneliest number)
Cassandra: One (is the loneliest number)
 
Client Drivers and Cassandra, the Right Way
Client Drivers and Cassandra, the Right WayClient Drivers and Cassandra, the Right Way
Client Drivers and Cassandra, the Right Way
 
Tales From The Front: An Architecture For Multi-Data Center Scalable Applicat...
Tales From The Front: An Architecture For Multi-Data Center Scalable Applicat...Tales From The Front: An Architecture For Multi-Data Center Scalable Applicat...
Tales From The Front: An Architecture For Multi-Data Center Scalable Applicat...
 

Ähnlich wie Coursera Cassandra Driver

Cassandra Tools and Distributed Administration (Jeffrey Berger, Knewton) | C*...
Cassandra Tools and Distributed Administration (Jeffrey Berger, Knewton) | C*...Cassandra Tools and Distributed Administration (Jeffrey Berger, Knewton) | C*...
Cassandra Tools and Distributed Administration (Jeffrey Berger, Knewton) | C*...
DataStax
 

Ähnlich wie Coursera Cassandra Driver (20)

DataStax NYC Java Meetup: Cassandra with Java
DataStax NYC Java Meetup: Cassandra with JavaDataStax NYC Java Meetup: Cassandra with Java
DataStax NYC Java Meetup: Cassandra with Java
 
Hey Relational Developer, Let's Go Crazy (Patrick McFadin, DataStax) | Cassan...
Hey Relational Developer, Let's Go Crazy (Patrick McFadin, DataStax) | Cassan...Hey Relational Developer, Let's Go Crazy (Patrick McFadin, DataStax) | Cassan...
Hey Relational Developer, Let's Go Crazy (Patrick McFadin, DataStax) | Cassan...
 
Escalabilidad horizontal y arquitecturas elásticas en Microsoft azure
Escalabilidad horizontal y arquitecturas elásticas en Microsoft azureEscalabilidad horizontal y arquitecturas elásticas en Microsoft azure
Escalabilidad horizontal y arquitecturas elásticas en Microsoft azure
 
NoSQL/SQLデュアルインタフェースを備えたIoT向けデータベースGridDB ~コマンドライン・インターフェース(CLI)を使ってみましょう~
NoSQL/SQLデュアルインタフェースを備えたIoT向けデータベースGridDB ~コマンドライン・インターフェース(CLI)を使ってみましょう~NoSQL/SQLデュアルインタフェースを備えたIoT向けデータベースGridDB ~コマンドライン・インターフェース(CLI)を使ってみましょう~
NoSQL/SQLデュアルインタフェースを備えたIoT向けデータベースGridDB ~コマンドライン・インターフェース(CLI)を使ってみましょう~
 
Dissecting Real-World Database Performance Dilemmas
Dissecting Real-World Database Performance DilemmasDissecting Real-World Database Performance Dilemmas
Dissecting Real-World Database Performance Dilemmas
 
Instaclustr webinar 2017 feb 08 japan
Instaclustr webinar 2017 feb 08   japanInstaclustr webinar 2017 feb 08   japan
Instaclustr webinar 2017 feb 08 japan
 
Terraform introduction
Terraform introductionTerraform introduction
Terraform introduction
 
Deep Learning for Computer Vision: Software Frameworks (UPC 2016)
Deep Learning for Computer Vision: Software Frameworks (UPC 2016)Deep Learning for Computer Vision: Software Frameworks (UPC 2016)
Deep Learning for Computer Vision: Software Frameworks (UPC 2016)
 
Introduction to Apache Cassandra
Introduction to Apache CassandraIntroduction to Apache Cassandra
Introduction to Apache Cassandra
 
What's New in Apache Hive
What's New in Apache HiveWhat's New in Apache Hive
What's New in Apache Hive
 
Introduction to .Net Driver
Introduction to .Net DriverIntroduction to .Net Driver
Introduction to .Net Driver
 
Everything as a Code / Александр Тарасов (Одноклассники)
Everything as a Code / Александр Тарасов (Одноклассники)Everything as a Code / Александр Тарасов (Одноклассники)
Everything as a Code / Александр Тарасов (Одноклассники)
 
Everything as a code
Everything as a codeEverything as a code
Everything as a code
 
Python and cassandra
Python and cassandraPython and cassandra
Python and cassandra
 
Cassandra Day Atlanta 2015: Python & Cassandra
Cassandra Day Atlanta 2015: Python & CassandraCassandra Day Atlanta 2015: Python & Cassandra
Cassandra Day Atlanta 2015: Python & Cassandra
 
Cassandra Summit 2014: Highly Scalable Web Application in the Cloud with Cass...
Cassandra Summit 2014: Highly Scalable Web Application in the Cloud with Cass...Cassandra Summit 2014: Highly Scalable Web Application in the Cloud with Cass...
Cassandra Summit 2014: Highly Scalable Web Application in the Cloud with Cass...
 
Jörg Schad - Hybrid Cloud (Kubernetes, Spark, HDFS, …)-as-a-Service - Codemot...
Jörg Schad - Hybrid Cloud (Kubernetes, Spark, HDFS, …)-as-a-Service - Codemot...Jörg Schad - Hybrid Cloud (Kubernetes, Spark, HDFS, …)-as-a-Service - Codemot...
Jörg Schad - Hybrid Cloud (Kubernetes, Spark, HDFS, …)-as-a-Service - Codemot...
 
Jörg Schad - Hybrid Cloud (Kubernetes, Spark, HDFS, …)-as-a-Service - Codemot...
Jörg Schad - Hybrid Cloud (Kubernetes, Spark, HDFS, …)-as-a-Service - Codemot...Jörg Schad - Hybrid Cloud (Kubernetes, Spark, HDFS, …)-as-a-Service - Codemot...
Jörg Schad - Hybrid Cloud (Kubernetes, Spark, HDFS, …)-as-a-Service - Codemot...
 
Database connectivity in python
Database connectivity in pythonDatabase connectivity in python
Database connectivity in python
 
Cassandra Tools and Distributed Administration (Jeffrey Berger, Knewton) | C*...
Cassandra Tools and Distributed Administration (Jeffrey Berger, Knewton) | C*...Cassandra Tools and Distributed Administration (Jeffrey Berger, Knewton) | C*...
Cassandra Tools and Distributed Administration (Jeffrey Berger, Knewton) | C*...
 

Kürzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 

Coursera Cassandra Driver

  • 3. 1 Introduction 2 Why We Chose Cassandra 3 Example Use Cases 4 Pain Points 5 Java Drivers
  • 5. 5
  • 8. Coursera Tech Stack • 100% AWS • MySQL + Cassandra • Service-oriented 8
  • 12. Use Case #1 • Resume video where you left off • High write volume • TTL data 12
  • 13. 13 CREATE TABLE video_progress_kvs_basic ( user_id int, course_id varchar, video_id varchar, viewed_up_to bigint, updated_at bigint PRIMARY KEY ((user_id, course_id, video_id)) );
  • 14. Use Case #2: Media Asset Service 14
  • 15. 15
  • 16. 16
  • 17. Use case #3: Video Workflows 17 Input.mp4 Step 1: Audio Step 2: Low Res Video Step 3: High Res Video Assembly 1: Crash Assembly 2: Ok Assembly 3: Crash Assembly 4: Ok Assembly 5: Ok
  • 18. 18
  • 19. CREATE TABLE transloadit_workflow ( workflow_id text, step_id text, assembly_id text, step_details text, step_payload map<text, text>, step_status text, PRIMARY KEY (workflow_id, step_id, assembly_id) ) 19
  • 21. Cassandra - Initial Pain Points • Can’t execute arbitrary queries • Filtering, sorting, etc. • Can’t be abused as an OLAP database • Worries about ‘eventual’ consistency 21
  • 22. Gotchas • Lots of truly ad-hoc queries is hard • Don’t use C* directly to explore your data. (Spark?) • Sorting, filtering can be hard • Consider Solr / ElasticSearch • Or even MySQL depending on load / importance 22
  • 23. Helpful Things • Data modeling consulting • Monitoring • Data access layer for common use cases 23
  • 24. 24
  • 25. 25
  • 27. Best Practices • Driver Choice • Cluster / Connection Setup • Executing Queries 27
  • 29. 29 public class Scratch { static Cluster cluster; public static void main(String args[]) { cluster = Cluster.builder() .addContactPoint("cassandra") .build(); readRow("asset:QoMqLLyCEeSOi3paAormVw"); cluster.close(); } static void readRow(String id) { Session session = cluster.connect("asset"); ResultSet result = session.execute( "SELECT * from asset_kvs_timestamp where part_key = ?", id); System.out.println(result.one()); session.close(); } }
  • 31. 31 LoadBalancingPolicy policy = new TokenAwarePolicy( new DCAwareRoundRobinPolicy()); cluster = Cluster.builder() .addContactPoint(“cassandra") .withLoadBalancingPolicy(policy) .build();
  • 33. Default Retry Policy • Retries read if enough replicas alive, but data fetch failed. • Retries write only for batched writes. • Retries next host on Unavailable. 2.0.11+ or 2.1.7 (JAVA-709) 33
  • 34. Share Session! 34 public static void main(String args[]) { cluster = Cluster.builder() .addContactPoint(“cassandra”).build(); readRow("asset:QoMqLLyCEeSOi3paAormVw"); readRow("asset:7i2ClbKnEeSk_npaAormVw"); readRow("asset:KS1vywpGEeWKtzoMw4q1xg"); cluster.close(); } static void readRow(String id) { Session session = cluster.connect("asset"); ResultSet result = session.execute( "SELECT * from asset_kvs_timestamp where part_key = ?", id); System.out.println(result.one()); session.close(); }
  • 35. 35 public static void main(String args[]) { cluster = Cluster.builder() .addContactPoint("cassandra").build(); session = cluster.connect(); readRow("asset:QoMqLLyCEeSOi3paAormVw"); readRow("asset:7i2ClbKnEeSk_npaAormVw"); readRow("asset:KS1vywpGEeWKtzoMw4q1xg"); session.close(); cluster.close(); } static void readRow(String id) { ResultSet result = session.execute( "SELECT * from asset.asset_kvs_timestamp where part_key = ?", id); System.out.println(result.one()); }
  • 36. Use prepared statements • If doing query more than once • Better performance • Token aware routing 36
  • 37. 37 static PreparedStatement statement; public static void main(String args[]) { … session = cluster.connect(); statement = session.prepare( "SELECT * from asset.asset_kvs_timestamp where part_key = ?") readRow("asset:QoMqLLyCEeSOi3paAormVw"); … } static void readRow(String id) { BoundStatement bound = statement.bind().setString("part_key", id); ResultSet result = session.execute(bound); System.out.println(result.one()); }
  • 38. There Be Dragons.. JAVA-420 statement = session.prepare( "SELECT part_key, time_key, content from asset.asset_kvs_timestamp where part_key = ?") 38 Always specify columns explicitly for prepared statements!
  • 39. Consider Async static List<String> readRows(List<String> ids) { return ids.stream().map(id -> { BoundStatement bound = statement.bind().setString("part_key", id); ResultSet result = session.execute(bound); return result.one().getString("c_enc"); }).collect(Collectors.toList()); } 39
  • 40. Async.. static ListenableFuture<List<String>> readRowsAsync(List<String> ids) { List<ListenableFuture<String>> futures = ids.stream().map(id -> { BoundStatement bound = statement.bind().setString("part_key", id); ResultSetFuture future = session.executeAsync(bound); return Futures.transform(future, (ResultSet result) -> 
 result.one().getString(“c_enc")); }).collect(Collectors.toList()); return Futures.allAsList(futures); } 40 http://www.datastax.com/dev/blog/java-driver-async-queries
  • 42. Cassandra Summit 2016 
 September 7-9 
 San Jose, CA Get 15% Off with Code: MeetupPromo
 Cassandrasummit.org