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

PDF
Micro-batching: High-performance Writes (Adam Zegelin, Instaclustr) | Cassand...
PDF
Using Approximate Data for Small, Insightful Analytics (Ben Kornmeier, Protec...
PPTX
Cassandra Tuning - above and beyond
PDF
Terror & Hysteria: Cost Effective Scaling of Time Series Data with Cassandra ...
PDF
Cassandra CLuster Management by Japan Cassandra Community
PPTX
Real Time Business Intelligence with Cassandra, Kafka and Hadoop - A Real Sto...
PPTX
Lessons Learned From Running 1800 Clusters (Brooke Jensen, Instaclustr) | Cas...
PDF
Instaclustr webinar 2017 feb 08 japan
Micro-batching: High-performance Writes (Adam Zegelin, Instaclustr) | Cassand...
Using Approximate Data for Small, Insightful Analytics (Ben Kornmeier, Protec...
Cassandra Tuning - above and beyond
Terror & Hysteria: Cost Effective Scaling of Time Series Data with Cassandra ...
Cassandra CLuster Management by Japan Cassandra Community
Real Time Business Intelligence with Cassandra, Kafka and Hadoop - A Real Sto...
Lessons Learned From Running 1800 Clusters (Brooke Jensen, Instaclustr) | Cas...
Instaclustr webinar 2017 feb 08 japan

What's hot (20)

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

Viewers also liked (20)

PDF
Data Modeling a Scheduling App (Adam Hutson, DataScale) | Cassandra Summit 2016
PDF
Troubleshooting Cassandra (J.B. Langston, DataStax) | C* Summit 2016
PDF
What is in All of Those SSTable Files Not Just the Data One but All the Rest ...
PPTX
Webinar: Transforming Customer Experience Through an Always-On Data Platform
PPTX
Webinar - Macy’s: Why Your Database Decision Directly Impacts Customer Experi...
PPTX
Bloor Research & DataStax: How graph databases solve previously unsolvable bu...
PPTX
There are More Clouds! Azure and Cassandra (Carlos Rolo, Pythian) | C* Summit...
PDF
Tuning Speculative Retries to Fight Latency (Michael Figuiere, Minh Do, Netfl...
PPTX
Using Spark to Load Oracle Data into Cassandra (Jim Hatcher, IHS Markit) | C*...
PPTX
The Missing Manual for Leveled Compaction Strategy (Wei Deng & Ryan Svihla, D...
PDF
Can My Inventory Survive Eventual Consistency?
PDF
Building Killr Applications with DSE
PDF
Webinar - Bringing Game Changing Insights with Graph Databases
PPTX
Webinar - DataStax Enterprise 5.1: 3X the operational analytics speed, help f...
PPTX
Webinar: Fighting Fraud with Graph Databases
PPTX
Give sense to your Big Data w/ Apache TinkerPop™ & property graph databases
PPTX
An Overview of Apache Cassandra
PDF
Building a Fast, Resilient Time Series Store with Cassandra (Alex Petrov, Dat...
PDF
The Promise and Perils of Encrypting Cassandra Data (Ameesh Divatia, Baffle, ...
PPTX
Stratio's Cassandra Lucene index: Geospatial Use Cases (Andrés de la Peña & J...
Data Modeling a Scheduling App (Adam Hutson, DataScale) | Cassandra Summit 2016
Troubleshooting Cassandra (J.B. Langston, DataStax) | C* Summit 2016
What is in All of Those SSTable Files Not Just the Data One but All the Rest ...
Webinar: Transforming Customer Experience Through an Always-On Data Platform
Webinar - Macy’s: Why Your Database Decision Directly Impacts Customer Experi...
Bloor Research & DataStax: How graph databases solve previously unsolvable bu...
There are More Clouds! Azure and Cassandra (Carlos Rolo, Pythian) | C* Summit...
Tuning Speculative Retries to Fight Latency (Michael Figuiere, Minh Do, Netfl...
Using Spark to Load Oracle Data into Cassandra (Jim Hatcher, IHS Markit) | C*...
The Missing Manual for Leveled Compaction Strategy (Wei Deng & Ryan Svihla, D...
Can My Inventory Survive Eventual Consistency?
Building Killr Applications with DSE
Webinar - Bringing Game Changing Insights with Graph Databases
Webinar - DataStax Enterprise 5.1: 3X the operational analytics speed, help f...
Webinar: Fighting Fraud with Graph Databases
Give sense to your Big Data w/ Apache TinkerPop™ & property graph databases
An Overview of Apache Cassandra
Building a Fast, Resilient Time Series Store with Cassandra (Alex Petrov, Dat...
The Promise and Perils of Encrypting Cassandra Data (Ameesh Divatia, Baffle, ...
Stratio's Cassandra Lucene index: Geospatial Use Cases (Andrés de la Peña & J...
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
PDF
Cassandra and Spark
DOCX
Cassandra data modelling best practices
PPTX
Cassandra20141009
PPTX
Cassandra20141113
PPT
Toronto jaspersoft meetup
PPTX
Performance tuning - A key to successful cassandra migration
PDF
Cassandra Community Webinar | Getting Started with Apache Cassandra with Patr...
PDF
Infosys Ltd: Performance Tuning - A Key to Successful Cassandra Migration
PDF
Introduction to Apache Cassandra
PDF
Apache Cassandra & Data Modeling
PDF
Apache Cassandra at Macys
PDF
Cassandra: An Alien Technology That's not so Alien
PDF
Cassandra 3.0 Awesomeness
PDF
Macy's: Changing Engines in Mid-Flight
PDF
Datastax day 2016 introduction to apache cassandra
PDF
Moving from a Relational Database to Cassandra: Why, Where, When, and How
PDF
Cassandra introduction 2016
PPTX
Exploring NoSQL and implementing through Cassandra
PDF
Paris Day Cassandra: Use case
Top 10 Best Practices for Apache Cassandra and DataStax Enterprise
Cassandra and Spark
Cassandra data modelling best practices
Cassandra20141009
Cassandra20141113
Toronto jaspersoft meetup
Performance tuning - A key to successful cassandra migration
Cassandra Community Webinar | Getting Started with Apache Cassandra with Patr...
Infosys Ltd: Performance Tuning - A Key to Successful Cassandra Migration
Introduction to Apache Cassandra
Apache Cassandra & Data Modeling
Apache Cassandra at Macys
Cassandra: An Alien Technology That's not so Alien
Cassandra 3.0 Awesomeness
Macy's: Changing Engines in Mid-Flight
Datastax day 2016 introduction to apache cassandra
Moving from a Relational Database to Cassandra: Why, Where, When, and How
Cassandra introduction 2016
Exploring NoSQL and implementing through Cassandra
Paris Day Cassandra: Use case

More from DataStax (20)

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

Recently uploaded (20)

PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
ai tools demonstartion for schools and inter college
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
Introduction to Artificial Intelligence
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
history of c programming in notes for students .pptx
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
System and Network Administraation Chapter 3
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
2025 Textile ERP Trends: SAP, Odoo & Oracle
PTS Company Brochure 2025 (1).pdf.......
ai tools demonstartion for schools and inter college
Upgrade and Innovation Strategies for SAP ERP Customers
Introduction to Artificial Intelligence
How to Choose the Right IT Partner for Your Business in Malaysia
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
history of c programming in notes for students .pptx
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
System and Network Administraation Chapter 3
Softaken Excel to vCard Converter Software.pdf
Odoo POS Development Services by CandidRoot Solutions
Design an Analysis of Algorithms II-SECS-1021-03
wealthsignaloriginal-com-DS-text-... (1).pdf
Wondershare Filmora 15 Crack With Activation Key [2025
How to Migrate SBCGlobal Email to Yahoo Easily
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Lecture 3: Operating Systems Introduction to Computer Hardware Systems

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