SlideShare a Scribd company logo
What we learned about Cassandra while building
go90 ?
Chris Webster
Thomas Ng
1 What is go90 ?
2 What do we use Cassandra for ?
3 Lessons learned
4 Q and A
2© DataStax, All Rights Reserved.
What is go90 ?
© DataStax, All Rights Reserved. 3
Mobile video entertainment
platform
On demand original content
Live events ( NBA / NFL / Soccer /
Reality Show / Concerts)
Interactive and Social
What do we use Cassandra for ?
© DataStax, All Rights Reserved. 4
• User metadata storage and search
• Schema evolution
• DSE cassandra/solr integration
• Comments
• Time series data
• Complex pagination
• Counters
• Resume point
• Expiration (TTL)
What do we use Cassandra for ?
© DataStax, All Rights Reserved. 5
• Activity / Feed
• Activity aggregation
• Fan-out to followers
• User accounts/rights
• Service management
• Content discovery
go90 Cassandra setup
• DSE 4.8.4
• Cassandra 2.1.12.1046
• Java driver version 2.10
• Native Protocol v3
• Java 8
• Running on Amazon Web Services EC2
• c3/4 4xlarge instances
• Mission critical service on own cluster
• Shared cluster for others
• Ephemeral ssd and encrypted ebs
© DataStax, All Rights Reserved. 6
Lessons learned
Schema evolution
• Use case: Add new column to table schema
• Existing user profile table:
• Primary key: pid (UUID)
• Columns: lastName, firstName, gender, lastModified
• Deployed and running in production
• Lookup user info with prepared statement:
• Query: select * from user_profile where pid = ‘some-uuid’;
• Add new column for imageUrl
• Service code change to extract new column from ResultSet in existing query above
• Apply schema change to production server
• alter table user_profile add imageurl varchar;
• Deploy new service
• No down time at all !?
© DataStax, All Rights Reserved. 8
Avoid SELECT * !
• Prepared statement running on existing service with the old schema might start to fall as soon as
new column is added:
• Java driver could throw InvalidTypeException at runtime when it tries to de-serialize the ResultSet
• Cassandra’s cache of prepared statement could go out-of-sync with the new table schema
• https://support.datastax.com/hc/en-us/articles/209573086-Java-driver-queries-result-in-
InvalidTypeException-Not-enough-bytes-to-deserialize-type-
• Always explicitly specify the fields you need in your SELECT query:
• Predictable result
• Avoid down time during schema change
• More data efficient - only get what you need
• Query: select lastName, firstName, imageUrl from user_profile where pid = ‘some-uuid’;
© DataStax, All Rights Reserved. 9
Data modeling with time series data
• Use case:
• Look up latest comments (timestamp descending) on a video id, paginated
• Create schema based on the query you need
• Make use of clustering order to do the sorting for you!
• Make sure your pagination code covers each clustering key
• Different people could comment on a video at the same timestamp!
• Or make use of automatic paging support in Java driver
© DataStax, All Rights Reserved. 10
Time series data example
Video id timestamp User id Comment
va_therunner 1470090047166 user_t
this is a comment
string
va_therunner 1470090031702 user_z Hi there
va_therunner 1470090031702 user_t Yo
va_therunner 1470090031702 user_a Love it!
va_tagged 1458951942903 user_b tagged
va_tagged 1458951902463 user_x go90
va_guidance 1470090031702 user_v whodunit
© DataStax, All Rights Reserved. 11
CREATE TABLE IF NOT EXISTS comments (
videoid varchar,
timestamp bigint,
userid varchar,
comment varchar,
PRIMARY KEY(videoid, timestamp, userid))
WITH CLUSTERING ORDER BY (timestamp DESC,
userid DESC);
Pagination example
Video id timestamp User id Comment
va_therunner 1470090047166 user_t
this is a comment
string
va_therunner 1470090031702 user_z Hi there
va_therunner 1470090031702 user_t Yo
va_therunner 1470090031702 user_a Love it!
va_therunner 1458951942903 user_b tagged
va_tagged 1458951902463 user_x go90
va_guidance 1470090031702 user_v whodunit
© DataStax, All Rights Reserved. 12
// start pagination thru comments table
select ts, uid, comment from comments where vid =
'va_therunner' limit 3;
> Returns first 3 rows
// incorrect second call
select ts, uid, comment from comments where
timestamp < 1470090031702 AND vid = 'va_therunner'
limit 3;
> Returns “tagged” comment // “Love it!” comment
will be skipped
// need to paginate clustering column “user id” too
select ts, uid, comment from comments where
timestamp = 1470090031702 AND vid = 'va_therunner'
AND uid < 'user_t' limit 3;
> Returns “Love it!”
Counters
• Use case:
• Display total number of comments for each video asset
• Avoid select count (*)!
• Built in support for synchronized concurrent access
• Use a separate table for all counters (separate from original metadata)
• Cannot add counter column to non-counter column family
• Sometimes counter value can get out of sync
• http://www.datastax.com/dev/blog/whats-new-in-cassandra-2-1-a-better-implementation-
of-counters
• background job at night to count the table and adjust counter values if needed
• Counters cannot be deleted
• Once deleted – you will not be able to use the same counter for sometime (undefined
state)
• Workaround – read value and add negative value (not concurrent safe)
© DataStax, All Rights Reserved. 13
Make use of TTL and DTCS !
• Use case:
• Storing resume points for every user, and every video they watched
• Lookup what is recently watched by a user
• Problem:
• This can grow fast and might not be scalable! (why store the resume point for a person that only watches
one video and leave ?)
• Solution:
• For resume points and watch history, insert with TTL of 30 days.
• Combine it with DateTieredCompactionStragtegy (DTCS)
• Best fit: time series fact data, delete by TTL
• Help cassandra to drop expired data (sstables on disk) effectively by grouping data into sstables by timestamp.
• Can drop whole sstables at once
• Less disk read means faster read time
© DataStax, All Rights Reserved. 14
Avoid deletes (tombstones)
• Use case:
• Activity feed with aggregation support
• Problem:
• How to group similar activity into one and not show duplicates ?
• User follows DreamWorksTV and Sabrina
• They publish a new episode for the same series (Songs that stick) at the same
time
• In user’s feed, we want to show one combined event instead of 2 duplicate events
• Feed read needs to be fast – first screen in 1.0 app!
© DataStax, All Rights Reserved. 15
First solution
• Two separate tables
• Feed table: primary key on (userID, timestamp). Always contains aggregated final
view of a user’s feed. Lookup is simple read query on the user id => fast.
• Aggregation table: primary key (userID, targetID). For each key, we store the
current activity written to feed with it’s timestamp.
• Feed update is done async on a background job – which involves:
• Read aggregation table to see if there is previous entry
• Update aggregation table (either insert or update)
• Update feed table, which can be a insert if no previous entry, or a delete to remove
previous entry and then insert new aggregated entry.
• Feed update is expensive, but is done asynchronously
• Feed read is fast since is a simple read
• It works - ship it!
© DataStax, All Rights Reserved. 16
Empty feed
• Field reports of getting empty feed screen
• Can occur at random times
© DataStax, All Rights Reserved. 17
Read timeout and tombstones
• Long compaction is happening and causing read timeout
• Too many delete operations
• Each delete will create a new tombstone
• Too many tombstone will cause expensive compaction
• It will also significantly slow down read operations because too many tombstones
needs to be scanned
© DataStax, All Rights Reserved. 18
How to avoid tombstones ?
• Adjust gc_grace_seconds so compaction happen more frequently to reduce number of
tombstones
• Smaller compaction each time
• Node repair should happen more frequently too:
• http://docs.datastax.com/en/cassandra/2.0/cassandra/operations/ops_repair_nodes_c.html
• New data model and algorithm could help too!
• Avoid excessive delete ops if possible!
• Make use of TTL and DTCS
• In our case, we switched to a write-only algorithm:
• aggregation in memory by reading more entries instead
• 45 days TTL with DTCS
• time series fact data, delete by TTL
© DataStax, All Rights Reserved. 19
Search: DSE Solr integration
• Real time fuzzy user
search
• Zero down time to add this
feature to existing
production cluster
• Separate small solr data
center dedicated for new
search queries only
• Existing queries
unchanged
• Writes into existing cluster
will be replicated into solr
nodes automatically
© DataStax, All Rights Reserved. 20
Solr
C*
WebService
App
Request
Search
request
DB
queries
replication
Solr index disappearing
• While we try to set up this initially – new data written to the original cluster will be available for
search, but then entries starts to disappear after a few minutes.
• Turns out to be combination of two problems:
• Existing bug in DSE 4.6.9 or earlier: Top deletion may cause unwanted deletes from the index. (DSP-
6654)
• In the solr schema xml – if you are going to index the primary key field in the schema, the field cannot
be tokenized. (In our case, we do not need to index the primary key anyway – it’s an UUID and no
one is going to search with that from the app)
• https://docs.datastax.com/en/datastax_enterprise/4.0/datastax_enterprise/srch/srchConfSkema.html
• We fixed solr schema and upgrade to DSE 4.8.4 – and all is well!
© DataStax, All Rights Reserved. 21
DevOps
Upgrade DSE and Java
• Upgrade
• DSE 4.6 to 4.8 (Cassandra 2.0 to 2.1)
• Java 7 to 8
• Benchmarks with cassandra-stress
• https://docs.datastax.com/en/cassandra/2.1/cassandra/tools/toolsCStress_t.html
• Findings
• In general, Cassandra 2.1 gives better performance in both read and write.
• We discovered minor peak performance degradation when running with Java 8 and Cassandra 2.1
• http://docs.datastax.com/en/datastax_enterprise/4.8/datastax_enterprise/install/installTARdse.html
© DataStax, All Rights Reserved. 23
© DataStax, All Rights Reserved. 24
PV or HVM ?
• Linux Amazon Machine Images (AMI)
• Paravirtual (PV)
• Hardware virtual machine (HVM)
• http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/virtualization_types.html
• HVM gives better performance
• Align with Amazon recommendations
• Cassandra-stress results:
• HVM: ~105K write/s
• PV: ~95K write/s
© DataStax, All Rights Reserved. 25
Storage with EC2
• Ephemeral (internal) vs Elastic block storage (EBS)
• In general, ephemeral gives better performance and is recommended
• Internal disks are physically attached to the instance
• http://www.datastax.com/dev/blog/what-is-the-story-with-aws-storage
• Our mixed mode (read/write) test results:
• Ephemeral: 61K ops rate
• EBS with encryption: 45K ops rate
• But what about when encryption is required ?
• EBS has built-in encryption support
• http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSEncryption.html
• Ephemeral - no native support from AWS, you need to deploy your own solution.
© DataStax, All Rights Reserved. 26
Maintenance
• Repairs
• Cron job to schedule repair jobs weekly
• Full repair on each node
• Can take long for big clusters to complete full round
• Looking to move to opscenter 6.0.2 with better management interface
• Future:
• Parallel node repairs
• Increment repairs
• Backups
• Daily backup to S3
• Can only restore data since last backup
• Future: commit log backup for point-in-time restore
© DataStax, All Rights Reserved. 27
Summary
© DataStax, All Rights Reserved. 28
• Avoid SELECT *
• Effective data modeling
• Make use of TTL and DTCS to avoid tombstones!
• Search with SOLR
• https://go90.com
Q and A

More Related Content

What's hot (20)

PDF
Optimizing Your Cluster with Coordinator Nodes (Eric Lubow, SimpleReach) | Ca...
DataStax
 
PPTX
How to size up an Apache Cassandra cluster (Training)
DataStax Academy
 
PPTX
DataStax | Best Practices for Securing DataStax Enterprise (Matt Kennedy) | C...
DataStax
 
PPTX
DataStax | DSE Search 5.0 and Beyond (Nick Panahi & Ariel Weisberg) | Cassand...
DataStax
 
PDF
Micro-batching: High-performance writes
Instaclustr
 
PPTX
Processing 50,000 events per second with Cassandra and Spark
Ben Slater
 
PDF
Clock Skew and Other Annoying Realities in Distributed Systems (Donny Nadolny...
DataStax
 
PPTX
Everyday I’m scaling... Cassandra
Instaclustr
 
PPTX
Designing & Optimizing Micro Batching Systems Using 100+ Nodes (Ananth Ram, R...
DataStax
 
PPT
Webinar: Getting Started with Apache Cassandra
DataStax
 
PPTX
Building a Multi-Region Cluster at Target (Aaron Ploetz, Target) | Cassandra ...
DataStax
 
PPTX
Load testing Cassandra applications
Ben Slater
 
PPTX
One Billion Black Friday Shoppers on a Distributed Data Store (Fahd Siddiqui,...
DataStax
 
PPTX
Cassandra
exsuns
 
PDF
Advanced Operations
DataStax Academy
 
PDF
Understanding Cassandra internals to solve real-world problems
Acunu
 
PDF
Instaclustr Webinar 50,000 Transactions Per Second with Apache Spark on Apach...
Instaclustr
 
PDF
DataStax | Building a Spark Streaming App with DSE File System (Rocco Varela)...
DataStax
 
PPTX
Maintaining Consistency Across Data Centers (Randy Fradin, BlackRock) | Cassa...
DataStax
 
PDF
C* for Deep Learning (Andrew Jefferson, Tracktable) | Cassandra Summit 2016
DataStax
 
Optimizing Your Cluster with Coordinator Nodes (Eric Lubow, SimpleReach) | Ca...
DataStax
 
How to size up an Apache Cassandra cluster (Training)
DataStax Academy
 
DataStax | Best Practices for Securing DataStax Enterprise (Matt Kennedy) | C...
DataStax
 
DataStax | DSE Search 5.0 and Beyond (Nick Panahi & Ariel Weisberg) | Cassand...
DataStax
 
Micro-batching: High-performance writes
Instaclustr
 
Processing 50,000 events per second with Cassandra and Spark
Ben Slater
 
Clock Skew and Other Annoying Realities in Distributed Systems (Donny Nadolny...
DataStax
 
Everyday I’m scaling... Cassandra
Instaclustr
 
Designing & Optimizing Micro Batching Systems Using 100+ Nodes (Ananth Ram, R...
DataStax
 
Webinar: Getting Started with Apache Cassandra
DataStax
 
Building a Multi-Region Cluster at Target (Aaron Ploetz, Target) | Cassandra ...
DataStax
 
Load testing Cassandra applications
Ben Slater
 
One Billion Black Friday Shoppers on a Distributed Data Store (Fahd Siddiqui,...
DataStax
 
Cassandra
exsuns
 
Advanced Operations
DataStax Academy
 
Understanding Cassandra internals to solve real-world problems
Acunu
 
Instaclustr Webinar 50,000 Transactions Per Second with Apache Spark on Apach...
Instaclustr
 
DataStax | Building a Spark Streaming App with DSE File System (Rocco Varela)...
DataStax
 
Maintaining Consistency Across Data Centers (Randy Fradin, BlackRock) | Cassa...
DataStax
 
C* for Deep Learning (Andrew Jefferson, Tracktable) | Cassandra Summit 2016
DataStax
 

Viewers also liked (20)

PDF
Data Modeling a Scheduling App (Adam Hutson, DataScale) | Cassandra Summit 2016
DataStax
 
PDF
Troubleshooting Cassandra (J.B. Langston, DataStax) | C* Summit 2016
DataStax
 
PDF
What is in All of Those SSTable Files Not Just the Data One but All the Rest ...
DataStax
 
PPTX
Webinar: Transforming Customer Experience Through an Always-On Data Platform
DataStax
 
PPTX
Webinar - Macy’s: Why Your Database Decision Directly Impacts Customer Experi...
DataStax
 
PPTX
Bloor Research & DataStax: How graph databases solve previously unsolvable bu...
DataStax
 
PPTX
There are More Clouds! Azure and Cassandra (Carlos Rolo, Pythian) | C* Summit...
DataStax
 
PDF
Tuning Speculative Retries to Fight Latency (Michael Figuiere, Minh Do, Netfl...
DataStax
 
PPTX
Using Spark to Load Oracle Data into Cassandra (Jim Hatcher, IHS Markit) | C*...
DataStax
 
PPTX
The Missing Manual for Leveled Compaction Strategy (Wei Deng & Ryan Svihla, D...
DataStax
 
PDF
Can My Inventory Survive Eventual Consistency?
DataStax
 
PDF
Building Killr Applications with DSE
DataStax
 
PDF
Webinar - Bringing Game Changing Insights with Graph Databases
DataStax
 
PPTX
Webinar - DataStax Enterprise 5.1: 3X the operational analytics speed, help f...
DataStax
 
PPTX
Webinar: Fighting Fraud with Graph Databases
DataStax
 
PPTX
Give sense to your Big Data w/ Apache TinkerPop™ & property graph databases
DataStax
 
PPTX
An Overview of Apache Cassandra
DataStax
 
PDF
Building a Fast, Resilient Time Series Store with Cassandra (Alex Petrov, Dat...
DataStax
 
PDF
The Promise and Perils of Encrypting Cassandra Data (Ameesh Divatia, Baffle, ...
DataStax
 
PPTX
Stratio's Cassandra Lucene index: Geospatial Use Cases (Andrés de la Peña & J...
DataStax
 
Data Modeling a Scheduling App (Adam Hutson, DataScale) | Cassandra Summit 2016
DataStax
 
Troubleshooting Cassandra (J.B. Langston, DataStax) | C* Summit 2016
DataStax
 
What is in All of Those SSTable Files Not Just the Data One but All the Rest ...
DataStax
 
Webinar: Transforming Customer Experience Through an Always-On Data Platform
DataStax
 
Webinar - Macy’s: Why Your Database Decision Directly Impacts Customer Experi...
DataStax
 
Bloor Research & DataStax: How graph databases solve previously unsolvable bu...
DataStax
 
There are More Clouds! Azure and Cassandra (Carlos Rolo, Pythian) | C* Summit...
DataStax
 
Tuning Speculative Retries to Fight Latency (Michael Figuiere, Minh Do, Netfl...
DataStax
 
Using Spark to Load Oracle Data into Cassandra (Jim Hatcher, IHS Markit) | C*...
DataStax
 
The Missing Manual for Leveled Compaction Strategy (Wei Deng & Ryan Svihla, D...
DataStax
 
Can My Inventory Survive Eventual Consistency?
DataStax
 
Building Killr Applications with DSE
DataStax
 
Webinar - Bringing Game Changing Insights with Graph Databases
DataStax
 
Webinar - DataStax Enterprise 5.1: 3X the operational analytics speed, help f...
DataStax
 
Webinar: Fighting Fraud with Graph Databases
DataStax
 
Give sense to your Big Data w/ Apache TinkerPop™ & property graph databases
DataStax
 
An Overview of Apache Cassandra
DataStax
 
Building a Fast, Resilient Time Series Store with Cassandra (Alex Petrov, Dat...
DataStax
 
The Promise and Perils of Encrypting Cassandra Data (Ameesh Divatia, Baffle, ...
DataStax
 
Stratio's Cassandra Lucene index: Geospatial Use Cases (Andrés de la Peña & J...
DataStax
 
Ad

Similar to What We Learned About Cassandra While Building go90 (Christopher Webster & Thomas Ng, AOL) | C* Summit 2016 (20)

PDF
Top 10 Best Practices for Apache Cassandra and DataStax Enterprise
DataStax
 
PDF
Cassandra and Spark
nickmbailey
 
DOCX
Cassandra data modelling best practices
Sandeep Sharma IIMK Smart City,IoT,Bigdata,Cloud,BI,DW
 
PPTX
Cassandra20141009
Brian Enochson
 
PPTX
Cassandra20141113
Brian Enochson
 
PPT
Toronto jaspersoft meetup
Patrick McFadin
 
PPTX
Performance tuning - A key to successful cassandra migration
Ramkumar Nottath
 
PDF
Cassandra Community Webinar | Getting Started with Apache Cassandra with Patr...
DataStax Academy
 
PDF
Infosys Ltd: Performance Tuning - A Key to Successful Cassandra Migration
DataStax Academy
 
PDF
Introduction to Apache Cassandra
Robert Stupp
 
PDF
Apache Cassandra & Data Modeling
Massimiliano Tomassi
 
PDF
Apache Cassandra at Macys
DataStax Academy
 
PDF
Cassandra: An Alien Technology That's not so Alien
Brian Hess
 
PDF
Cassandra 3.0 Awesomeness
Jon Haddad
 
PDF
Macy's: Changing Engines in Mid-Flight
DataStax Academy
 
PDF
Datastax day 2016 introduction to apache cassandra
Duyhai Doan
 
PDF
Moving from a Relational Database to Cassandra: Why, Where, When, and How
Anant Corporation
 
PDF
Cassandra introduction 2016
Duyhai Doan
 
PPTX
Exploring NoSQL and implementing through Cassandra
Dileep Kalidindi
 
PDF
Paris Day Cassandra: Use case
Christopher Batey
 
Top 10 Best Practices for Apache Cassandra and DataStax Enterprise
DataStax
 
Cassandra and Spark
nickmbailey
 
Cassandra data modelling best practices
Sandeep Sharma IIMK Smart City,IoT,Bigdata,Cloud,BI,DW
 
Cassandra20141009
Brian Enochson
 
Cassandra20141113
Brian Enochson
 
Toronto jaspersoft meetup
Patrick McFadin
 
Performance tuning - A key to successful cassandra migration
Ramkumar Nottath
 
Cassandra Community Webinar | Getting Started with Apache Cassandra with Patr...
DataStax Academy
 
Infosys Ltd: Performance Tuning - A Key to Successful Cassandra Migration
DataStax Academy
 
Introduction to Apache Cassandra
Robert Stupp
 
Apache Cassandra & Data Modeling
Massimiliano Tomassi
 
Apache Cassandra at Macys
DataStax Academy
 
Cassandra: An Alien Technology That's not so Alien
Brian Hess
 
Cassandra 3.0 Awesomeness
Jon Haddad
 
Macy's: Changing Engines in Mid-Flight
DataStax Academy
 
Datastax day 2016 introduction to apache cassandra
Duyhai Doan
 
Moving from a Relational Database to Cassandra: Why, Where, When, and How
Anant Corporation
 
Cassandra introduction 2016
Duyhai Doan
 
Exploring NoSQL and implementing through Cassandra
Dileep Kalidindi
 
Paris Day Cassandra: Use case
Christopher Batey
 
Ad

More from DataStax (20)

PPTX
Is Your Enterprise Ready to Shine This Holiday Season?
DataStax
 
PPTX
Designing Fault-Tolerant Applications with DataStax Enterprise and Apache Cas...
DataStax
 
PPTX
Running DataStax Enterprise in VMware Cloud and Hybrid Environments
DataStax
 
PPTX
Best Practices for Getting to Production with DataStax Enterprise Graph
DataStax
 
PPTX
Webinar | Data Management for Hybrid and Multi-Cloud: A Four-Step Journey
DataStax
 
PPTX
Webinar | How to Understand Apache Cassandra™ Performance Through Read/Writ...
DataStax
 
PDF
Webinar | Better Together: Apache Cassandra and Apache Kafka
DataStax
 
PDF
Introduction to Apache Cassandra™ + What’s New in 4.0
DataStax
 
PPTX
Webinar: How Active Everywhere Database Architecture Accelerates Hybrid Cloud...
DataStax
 
PPTX
Webinar | Aligning GDPR Requirements with Today's Hybrid Cloud Realities
DataStax
 
PDF
Designing a Distributed Cloud Database for Dummies
DataStax
 
PDF
How to Power Innovation with Geo-Distributed Data Management in Hybrid Cloud
DataStax
 
PDF
How to Evaluate Cloud Databases for eCommerce
DataStax
 
PPTX
Webinar: DataStax Enterprise 6: 10 Ways to Multiply the Power of Apache Cassa...
DataStax
 
PPTX
Webinar: DataStax and Microsoft Azure: Empowering the Right-Now Enterprise wi...
DataStax
 
PPTX
Webinar - Real-Time Customer Experience for the Right-Now Enterprise featurin...
DataStax
 
PPTX
Datastax - The Architect's guide to customer experience (CX)
DataStax
 
PPTX
An Operational Data Layer is Critical for Transformative Banking Applications
DataStax
 
PPTX
Becoming a Customer-Centric Enterprise Via Real-Time Data and Design Thinking
DataStax
 
PPTX
Innovation Around Data and AI for Fraud Detection
DataStax
 
Is Your Enterprise Ready to Shine This Holiday Season?
DataStax
 
Designing Fault-Tolerant Applications with DataStax Enterprise and Apache Cas...
DataStax
 
Running DataStax Enterprise in VMware Cloud and Hybrid Environments
DataStax
 
Best Practices for Getting to Production with DataStax Enterprise Graph
DataStax
 
Webinar | Data Management for Hybrid and Multi-Cloud: A Four-Step Journey
DataStax
 
Webinar | How to Understand Apache Cassandra™ Performance Through Read/Writ...
DataStax
 
Webinar | Better Together: Apache Cassandra and Apache Kafka
DataStax
 
Introduction to Apache Cassandra™ + What’s New in 4.0
DataStax
 
Webinar: How Active Everywhere Database Architecture Accelerates Hybrid Cloud...
DataStax
 
Webinar | Aligning GDPR Requirements with Today's Hybrid Cloud Realities
DataStax
 
Designing a Distributed Cloud Database for Dummies
DataStax
 
How to Power Innovation with Geo-Distributed Data Management in Hybrid Cloud
DataStax
 
How to Evaluate Cloud Databases for eCommerce
DataStax
 
Webinar: DataStax Enterprise 6: 10 Ways to Multiply the Power of Apache Cassa...
DataStax
 
Webinar: DataStax and Microsoft Azure: Empowering the Right-Now Enterprise wi...
DataStax
 
Webinar - Real-Time Customer Experience for the Right-Now Enterprise featurin...
DataStax
 
Datastax - The Architect's guide to customer experience (CX)
DataStax
 
An Operational Data Layer is Critical for Transformative Banking Applications
DataStax
 
Becoming a Customer-Centric Enterprise Via Real-Time Data and Design Thinking
DataStax
 
Innovation Around Data and AI for Fraud Detection
DataStax
 

Recently uploaded (20)

PPTX
How Odoo Became a Game-Changer for an IT Company in Manufacturing ERP
SatishKumar2651
 
PDF
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
PPTX
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
PPTX
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PPTX
Perfecting XM Cloud for Multisite Setup.pptx
Ahmed Okour
 
PPT
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PPTX
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
How Odoo Became a Game-Changer for an IT Company in Manufacturing ERP
SatishKumar2651
 
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Human Resources Information System (HRIS)
Amity University, Patna
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
Perfecting XM Cloud for Multisite Setup.pptx
Ahmed Okour
 
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 

What We Learned About Cassandra While Building go90 (Christopher Webster & Thomas Ng, AOL) | C* Summit 2016

  • 1. What we learned about Cassandra while building go90 ? Chris Webster Thomas Ng
  • 2. 1 What is go90 ? 2 What do we use Cassandra for ? 3 Lessons learned 4 Q and A 2© DataStax, All Rights Reserved.
  • 3. What is go90 ? © DataStax, All Rights Reserved. 3 Mobile video entertainment platform On demand original content Live events ( NBA / NFL / Soccer / Reality Show / Concerts) Interactive and Social
  • 4. What do we use Cassandra for ? © DataStax, All Rights Reserved. 4 • User metadata storage and search • Schema evolution • DSE cassandra/solr integration • Comments • Time series data • Complex pagination • Counters • Resume point • Expiration (TTL)
  • 5. What do we use Cassandra for ? © DataStax, All Rights Reserved. 5 • Activity / Feed • Activity aggregation • Fan-out to followers • User accounts/rights • Service management • Content discovery
  • 6. go90 Cassandra setup • DSE 4.8.4 • Cassandra 2.1.12.1046 • Java driver version 2.10 • Native Protocol v3 • Java 8 • Running on Amazon Web Services EC2 • c3/4 4xlarge instances • Mission critical service on own cluster • Shared cluster for others • Ephemeral ssd and encrypted ebs © DataStax, All Rights Reserved. 6
  • 8. Schema evolution • Use case: Add new column to table schema • Existing user profile table: • Primary key: pid (UUID) • Columns: lastName, firstName, gender, lastModified • Deployed and running in production • Lookup user info with prepared statement: • Query: select * from user_profile where pid = ‘some-uuid’; • Add new column for imageUrl • Service code change to extract new column from ResultSet in existing query above • Apply schema change to production server • alter table user_profile add imageurl varchar; • Deploy new service • No down time at all !? © DataStax, All Rights Reserved. 8
  • 9. Avoid SELECT * ! • Prepared statement running on existing service with the old schema might start to fall as soon as new column is added: • Java driver could throw InvalidTypeException at runtime when it tries to de-serialize the ResultSet • Cassandra’s cache of prepared statement could go out-of-sync with the new table schema • https://support.datastax.com/hc/en-us/articles/209573086-Java-driver-queries-result-in- InvalidTypeException-Not-enough-bytes-to-deserialize-type- • Always explicitly specify the fields you need in your SELECT query: • Predictable result • Avoid down time during schema change • More data efficient - only get what you need • Query: select lastName, firstName, imageUrl from user_profile where pid = ‘some-uuid’; © DataStax, All Rights Reserved. 9
  • 10. Data modeling with time series data • Use case: • Look up latest comments (timestamp descending) on a video id, paginated • Create schema based on the query you need • Make use of clustering order to do the sorting for you! • Make sure your pagination code covers each clustering key • Different people could comment on a video at the same timestamp! • Or make use of automatic paging support in Java driver © DataStax, All Rights Reserved. 10
  • 11. Time series data example Video id timestamp User id Comment va_therunner 1470090047166 user_t this is a comment string va_therunner 1470090031702 user_z Hi there va_therunner 1470090031702 user_t Yo va_therunner 1470090031702 user_a Love it! va_tagged 1458951942903 user_b tagged va_tagged 1458951902463 user_x go90 va_guidance 1470090031702 user_v whodunit © DataStax, All Rights Reserved. 11 CREATE TABLE IF NOT EXISTS comments ( videoid varchar, timestamp bigint, userid varchar, comment varchar, PRIMARY KEY(videoid, timestamp, userid)) WITH CLUSTERING ORDER BY (timestamp DESC, userid DESC);
  • 12. Pagination example Video id timestamp User id Comment va_therunner 1470090047166 user_t this is a comment string va_therunner 1470090031702 user_z Hi there va_therunner 1470090031702 user_t Yo va_therunner 1470090031702 user_a Love it! va_therunner 1458951942903 user_b tagged va_tagged 1458951902463 user_x go90 va_guidance 1470090031702 user_v whodunit © DataStax, All Rights Reserved. 12 // start pagination thru comments table select ts, uid, comment from comments where vid = 'va_therunner' limit 3; > Returns first 3 rows // incorrect second call select ts, uid, comment from comments where timestamp < 1470090031702 AND vid = 'va_therunner' limit 3; > Returns “tagged” comment // “Love it!” comment will be skipped // need to paginate clustering column “user id” too select ts, uid, comment from comments where timestamp = 1470090031702 AND vid = 'va_therunner' AND uid < 'user_t' limit 3; > Returns “Love it!”
  • 13. Counters • Use case: • Display total number of comments for each video asset • Avoid select count (*)! • Built in support for synchronized concurrent access • Use a separate table for all counters (separate from original metadata) • Cannot add counter column to non-counter column family • Sometimes counter value can get out of sync • http://www.datastax.com/dev/blog/whats-new-in-cassandra-2-1-a-better-implementation- of-counters • background job at night to count the table and adjust counter values if needed • Counters cannot be deleted • Once deleted – you will not be able to use the same counter for sometime (undefined state) • Workaround – read value and add negative value (not concurrent safe) © DataStax, All Rights Reserved. 13
  • 14. Make use of TTL and DTCS ! • Use case: • Storing resume points for every user, and every video they watched • Lookup what is recently watched by a user • Problem: • This can grow fast and might not be scalable! (why store the resume point for a person that only watches one video and leave ?) • Solution: • For resume points and watch history, insert with TTL of 30 days. • Combine it with DateTieredCompactionStragtegy (DTCS) • Best fit: time series fact data, delete by TTL • Help cassandra to drop expired data (sstables on disk) effectively by grouping data into sstables by timestamp. • Can drop whole sstables at once • Less disk read means faster read time © DataStax, All Rights Reserved. 14
  • 15. Avoid deletes (tombstones) • Use case: • Activity feed with aggregation support • Problem: • How to group similar activity into one and not show duplicates ? • User follows DreamWorksTV and Sabrina • They publish a new episode for the same series (Songs that stick) at the same time • In user’s feed, we want to show one combined event instead of 2 duplicate events • Feed read needs to be fast – first screen in 1.0 app! © DataStax, All Rights Reserved. 15
  • 16. First solution • Two separate tables • Feed table: primary key on (userID, timestamp). Always contains aggregated final view of a user’s feed. Lookup is simple read query on the user id => fast. • Aggregation table: primary key (userID, targetID). For each key, we store the current activity written to feed with it’s timestamp. • Feed update is done async on a background job – which involves: • Read aggregation table to see if there is previous entry • Update aggregation table (either insert or update) • Update feed table, which can be a insert if no previous entry, or a delete to remove previous entry and then insert new aggregated entry. • Feed update is expensive, but is done asynchronously • Feed read is fast since is a simple read • It works - ship it! © DataStax, All Rights Reserved. 16
  • 17. Empty feed • Field reports of getting empty feed screen • Can occur at random times © DataStax, All Rights Reserved. 17
  • 18. Read timeout and tombstones • Long compaction is happening and causing read timeout • Too many delete operations • Each delete will create a new tombstone • Too many tombstone will cause expensive compaction • It will also significantly slow down read operations because too many tombstones needs to be scanned © DataStax, All Rights Reserved. 18
  • 19. How to avoid tombstones ? • Adjust gc_grace_seconds so compaction happen more frequently to reduce number of tombstones • Smaller compaction each time • Node repair should happen more frequently too: • http://docs.datastax.com/en/cassandra/2.0/cassandra/operations/ops_repair_nodes_c.html • New data model and algorithm could help too! • Avoid excessive delete ops if possible! • Make use of TTL and DTCS • In our case, we switched to a write-only algorithm: • aggregation in memory by reading more entries instead • 45 days TTL with DTCS • time series fact data, delete by TTL © DataStax, All Rights Reserved. 19
  • 20. Search: DSE Solr integration • Real time fuzzy user search • Zero down time to add this feature to existing production cluster • Separate small solr data center dedicated for new search queries only • Existing queries unchanged • Writes into existing cluster will be replicated into solr nodes automatically © DataStax, All Rights Reserved. 20 Solr C* WebService App Request Search request DB queries replication
  • 21. Solr index disappearing • While we try to set up this initially – new data written to the original cluster will be available for search, but then entries starts to disappear after a few minutes. • Turns out to be combination of two problems: • Existing bug in DSE 4.6.9 or earlier: Top deletion may cause unwanted deletes from the index. (DSP- 6654) • In the solr schema xml – if you are going to index the primary key field in the schema, the field cannot be tokenized. (In our case, we do not need to index the primary key anyway – it’s an UUID and no one is going to search with that from the app) • https://docs.datastax.com/en/datastax_enterprise/4.0/datastax_enterprise/srch/srchConfSkema.html • We fixed solr schema and upgrade to DSE 4.8.4 – and all is well! © DataStax, All Rights Reserved. 21
  • 23. Upgrade DSE and Java • Upgrade • DSE 4.6 to 4.8 (Cassandra 2.0 to 2.1) • Java 7 to 8 • Benchmarks with cassandra-stress • https://docs.datastax.com/en/cassandra/2.1/cassandra/tools/toolsCStress_t.html • Findings • In general, Cassandra 2.1 gives better performance in both read and write. • We discovered minor peak performance degradation when running with Java 8 and Cassandra 2.1 • http://docs.datastax.com/en/datastax_enterprise/4.8/datastax_enterprise/install/installTARdse.html © DataStax, All Rights Reserved. 23
  • 24. © DataStax, All Rights Reserved. 24
  • 25. PV or HVM ? • Linux Amazon Machine Images (AMI) • Paravirtual (PV) • Hardware virtual machine (HVM) • http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/virtualization_types.html • HVM gives better performance • Align with Amazon recommendations • Cassandra-stress results: • HVM: ~105K write/s • PV: ~95K write/s © DataStax, All Rights Reserved. 25
  • 26. Storage with EC2 • Ephemeral (internal) vs Elastic block storage (EBS) • In general, ephemeral gives better performance and is recommended • Internal disks are physically attached to the instance • http://www.datastax.com/dev/blog/what-is-the-story-with-aws-storage • Our mixed mode (read/write) test results: • Ephemeral: 61K ops rate • EBS with encryption: 45K ops rate • But what about when encryption is required ? • EBS has built-in encryption support • http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSEncryption.html • Ephemeral - no native support from AWS, you need to deploy your own solution. © DataStax, All Rights Reserved. 26
  • 27. Maintenance • Repairs • Cron job to schedule repair jobs weekly • Full repair on each node • Can take long for big clusters to complete full round • Looking to move to opscenter 6.0.2 with better management interface • Future: • Parallel node repairs • Increment repairs • Backups • Daily backup to S3 • Can only restore data since last backup • Future: commit log backup for point-in-time restore © DataStax, All Rights Reserved. 27
  • 28. Summary © DataStax, All Rights Reserved. 28 • Avoid SELECT * • Effective data modeling • Make use of TTL and DTCS to avoid tombstones! • Search with SOLR • https://go90.com