Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Apache Cassandra:
building a production app on an
eventually-consistent DB
Oliver Lockwood
Prague, 20-21 October 2016
Agenda
• Brief introduction to Cassandra
• Gotchas when using an eventually-consistent DB
• Performing DB schema and data ...
Introduction to Cassandra
What it is, and what it’s good for
• NoSQL database
• Distributed architecture with no “master” ...
Introduction to Cassandra
How storage, reads, writes and conflict resolution work
• Replication factor = how many copies
•...
Introduction to Cassandra
What it’s not good for
Oliver Lockwood Prague, 20-21 October 2016
http://planetcassandra.org/blo...
Gotchas
Lessons we learned the hard way
• Distributable nature of Cassandra depends
on synchronized clocks
• What happens ...
Gotchas
Lessons we learned the hard way
Demo!
Oliver Lockwood Prague, 20-21 October 2016
http://stackoverflow.com/question...
Gotchas
Lessons we learned the hard way - resolution
• Node 3’s clock is slow
• Use client-side timestamps?
CQL protocol v...
Schema evolution in Cassandra
Introduction
• DB schemas evolve – accept it!
• Automation is better than manual processes
•...
Schema evolution in Cassandra
Introducing cqlmigrate
Oliver Lockwood Prague, 20-21 October 2016
https://github.com/sky-uk/...
Schema evolution in Cassandra
Diving deeper into cqlmigrate
• Schema update operations are recorded, so each CQL file is a...
Schema evolution in Cassandra
Diving deeper into cqlmigrate
Demo!
Oliver Lockwood Prague, 20-21 October 2016
https://githu...
In conclusion
Takeaway menu
Oliver Lockwood Prague, 20-21 October 2016
http://www.datastax.com/dev/blog/lightweight-transa...
Upcoming SlideShare
Loading in …5
×

Apache Cassandra: building a production app on an eventually-consistent DB

347 views

Published on

At Sky, we use Cassandra for database persistence in our Online Video Platform - the system which delivers all OTT video content to both Sky and NOW TV customers - and yes, that includes handling huge spikes in traffic both when there's a big Premier League football match and when a new Game of Thrones season comes online!

This talk aims to cover the following topics.
- A brief introduction to Cassandra, including what it’s good for, what it’s not good for, and why. We'll dig into how storage, reads, writes and conflict resolution work.
- Gotchas in an eventually-consistent DB - some interesting problems we encountered and the lessons we learned the hard way.
- Performing database schema and data evolution in Cassandra for a production app.
- Why this is important, and what we did at Sky to ensure consistency of our database schema.

Presented at Geecon Prague on 20th October 2016.

Published in: Technology
  • Be the first to comment

Apache Cassandra: building a production app on an eventually-consistent DB

  1. 1. Apache Cassandra: building a production app on an eventually-consistent DB Oliver Lockwood Prague, 20-21 October 2016
  2. 2. Agenda • Brief introduction to Cassandra • Gotchas when using an eventually-consistent DB • Performing DB schema and data evolution in Cassandra for a production app Oliver Lockwood Prague, 20-21 October 2016
  3. 3. Introduction to Cassandra What it is, and what it’s good for • NoSQL database • Distributed architecture with no “master” – highly scalable and resilient • Write-optimised • Eventual consistency Oliver Lockwood Prague, 20-21 October 2016 http://www.datastax.com/dbas-guide-to-nosql
  4. 4. Introduction to Cassandra How storage, reads, writes and conflict resolution work • Replication factor = how many copies • Replication strategy determines storage location • Contact points used initially • Client connection is to cluster • Co-ordinator could be any node (based on load balancing policy) • Storage is independent of co-ordinator • Last Write Wins for conflicts Oliver Lockwood Prague, 20-21 October 2016 http://www.slideshare.net/DataStax/understanding-data-consistency-in-apache-cassandra ClientClient Client 2Client 2
  5. 5. Introduction to Cassandra What it’s not good for Oliver Lockwood Prague, 20-21 October 2016 http://planetcassandra.org/blog/flite-breaking-down-the-cql-where-clause/
  6. 6. Gotchas Lessons we learned the hard way • Distributable nature of Cassandra depends on synchronized clocks • What happens if clocks drift? • INSERT, DELETE, READ from a single client. • What if Node 3’s clock is slow? Oliver Lockwood Prague, 20-21 October 2016 https://blog.logentries.com/2014/03/synchronizing-clocks-in-a-cassandra-cluster-pt-1-the-problem/ http://datascale.io/how-to-create-a-cassandra-cluster-in-aws/ ClientClient (1) INSERT (2) DELETE
  7. 7. Gotchas Lessons we learned the hard way Demo! Oliver Lockwood Prague, 20-21 October 2016 http://stackoverflow.com/questions/17474830/configuring-cassandra-with-private-ip-for-internode-communications https://github.com/oliverlockwood/aws-ansible-cassandra
  8. 8. Gotchas Lessons we learned the hard way - resolution • Node 3’s clock is slow • Use client-side timestamps? CQL protocol v3 supports this. • Avoid time-sensitive query patterns Oliver Lockwood Prague, 20-21 October 2016 http://www.datastax.com/dev/blog/java-driver-2-1-2-native-protocol-v3 ClientClient (1) INSERT (2) DELETE
  9. 9. Schema evolution in Cassandra Introduction • DB schemas evolve – accept it! • Automation is better than manual processes • For RDBMS: Flyway, Liquibase etc. • For Cassandra… … cqlmigrate! Oliver Lockwood Prague, 20-21 October 2016 https://flywaydb.org/ http://www.liquibase.org/
  10. 10. Schema evolution in Cassandra Introducing cqlmigrate Oliver Lockwood Prague, 20-21 October 2016 https://github.com/sky-uk/cqlmigrate http://developers.sky.com/internal/ovp/cassandra/schema/evolution/2016/07/05/cqlmigrate/
  11. 11. Schema evolution in Cassandra Diving deeper into cqlmigrate • Schema update operations are recorded, so each CQL file is applied only once • Locking mechanism uses LWT to avoid race conditions Oliver Lockwood Prague, 20-21 October 2016 http://www.datastax.com/dev/blog/lightweight-transactions-in-cassandra-2-0 http://www.cs.utexas.edu/users/lorenzo/corsi/cs380d/past/03F/notes/paxos-simple.pdf
  12. 12. Schema evolution in Cassandra Diving deeper into cqlmigrate Demo! Oliver Lockwood Prague, 20-21 October 2016 https://github.com/oliverlockwood/cqlmigrate-example-app
  13. 13. In conclusion Takeaway menu Oliver Lockwood Prague, 20-21 October 2016 http://www.datastax.com/dev/blog/lightweight-transactions-in-cassandra-2-0 http://www.cs.utexas.edu/users/lorenzo/corsi/cs380d/past/03F/notes/paxos-simple.pdf

×