Apache Cassandra for Big Data Applications



Similar documents
HDB++: HIGH AVAILABILITY WITH. l TANGO Meeting l 20 May 2015 l Reynald Bourtembourg

Introduction to Cassandra

Simba Apache Cassandra ODBC Driver

Distributed Systems. Tutorial 12 Cassandra

Highly available, scalable and secure data with Cassandra and DataStax Enterprise. GOTO Berlin 27 th February 2014

Facebook: Cassandra. Smruti R. Sarangi. Department of Computer Science Indian Institute of Technology New Delhi, India. Overview Design Evaluation

Real-Time Big Data in practice with Cassandra. Michaël

LARGE-SCALE DATA STORAGE APPLICATIONS

A programming model in Cloud: MapReduce

Practical Cassandra. Vitalii

Why NoSQL? Your database options in the new non- relational world IBM Cloudant 1

Apache Cassandra Present and Future. Jonathan Ellis

Amazon Redshift & Amazon DynamoDB Michael Hanisch, Amazon Web Services Erez Hadas-Sonnenschein, clipkit GmbH Witali Stohler, clipkit GmbH

An Approach to Implement Map Reduce with NoSQL Databases

How To Scale Out Of A Nosql Database

Benchmarking Couchbase Server for Interactive Applications. By Alexey Diomin and Kirill Grigorchuk

CQL for Cassandra 2.2 & later

No-SQL Databases for High Volume Data

NoSQL Databases. Institute of Computer Science Databases and Information Systems (DBIS) DB 2, WS 2014/2015

Time series IoT data ingestion into Cassandra using Kaa

Introduction to Apache Cassandra

Apache Cassandra 1.2 Documentation

Cassandra A Decentralized, Structured Storage System

Mark Bennett. Search and the Virtual Machine

Evaluation of NoSQL databases for large-scale decentralized microblogging

Big Data Development CASSANDRA NoSQL Training - Workshop. March 13 to am to 5 pm HOTEL DUBAI GRAND DUBAI

So What s the Big Deal?

Analytics March 2015 White paper. Why NoSQL? Your database options in the new non-relational world

NoSQL: Going Beyond Structured Data and RDBMS

Hypertable Architecture Overview

High Throughput Computing on P2P Networks. Carlos Pérez Miguel

HBase Schema Design. NoSQL Ma4ers, Cologne, April Lars George Director EMEA Services

these three NoSQL databases because I wanted to see a the two different sides of the CAP

NoSQL Databases. Nikos Parlavantzas

JVM Performance Study Comparing Oracle HotSpot and Azul Zing Using Apache Cassandra

Open Source DBMS CUBRID 2008 & Community Activities. Byung Joo Chung bjchung@cubrid.com

Lecture 10: HBase! Claudia Hauff (Web Information Systems)!

Enabling SOX Compliance on DataStax Enterprise

Windows Azure Storage Essential Cloud Storage Services

NoSQL and Hadoop Technologies On Oracle Cloud

Going Native With Apache Cassandra. QCon London, 2014

Remote Application Server Version 14. Last updated:

<Insert Picture Here> Oracle NoSQL Database A Distributed Key-Value Store

The NoSQL Ecosystem, Relaxed Consistency, and Snoop Dogg. Adam Marcus MIT CSAIL

Realtime Apache Hadoop at Facebook. Jonathan Gray & Dhruba Borthakur June 14, 2011 at SIGMOD, Athens

Cassandra vs MySQL. SQL vs NoSQL database comparison

Introduction to Hbase Gkavresis Giorgos 1470

Apache Cassandra Query Language (CQL)

Big Data with Component Based Software

Open Source Technologies on Microsoft Azure

NoSQL Database Options

Keep SQL Service Running On Replica Member While Replicating Data In Realtime

Joining Cassandra. Luiz Fernando M. Schlindwein Computer Science Department University of Crete Heraklion, Greece

F1: A Distributed SQL Database That Scales. Presentation by: Alex Degtiar (adegtiar@cmu.edu) /21/2013

extensible record stores document stores key-value stores Rick Cattel s clustering from Scalable SQL and NoSQL Data Stores SIGMOD Record, 2010

Integrating Big Data into the Computing Curricula

Case Study: Real-time Analytics With Druid. Salil Kalia, Tech Lead, TO THE NEW Digital

Database Replication with MySQL and PostgreSQL

How To Use Big Data For Telco (For A Telco)

Evaluator s Guide. McKnight. Consulting Group. McKnight Consulting Group

Cluster Computing. ! Fault tolerance. ! Stateless. ! Throughput. ! Stateful. ! Response time. Architectures. Stateless vs. Stateful.

Data Management in the Cloud

NoSQL Data Base Basics

Weaving Stored Procedures into Java at Zalando

May 6, DataStax Cassandra South Bay Meetup. Cassandra Modeling. Best Practices and Examples. Jay Patel Architect, Platform

VMware Identity Manager Connector Installation and Configuration

Remote Application Server Version 14. Last updated:

CASE STUDY: Oracle TimesTen In-Memory Database and Shared Disk HA Implementation at Instance level. -ORACLE TIMESTEN 11gR1

A Distributed Network Security Analysis System Based on Apache Hadoop-Related Technologies. Jeff Springer, Mehmet Gunes, George Bebis

Inge Os Sales Consulting Manager Oracle Norway

Case study: CASSANDRA

The last 18 months. AutoScale. IaaS. BizTalk Services Hyper-V Disaster Recovery Support. Multi-Factor Auth. Hyper-V Recovery.

Contents. SnapComms Data Protection Recommendations

Apache Cassandra 1.2

MariaDB Cassandra interoperability

MySQL High Availability Solutions. Lenz Grimmer OpenSQL Camp St. Augustin Germany

Tushar Joshi Turtle Networks Ltd

INTRODUCTION TO CASSANDRA

Axway API Gateway. Version 7.4.1

Big Data and Scripting Systems build on top of Hadoop

SIP-DECT Knowledge Base SIP-DECT System Update

Physical Database Design Process. Physical Database Design Process. Major Inputs to Physical Database. Components of Physical Database Design

In-Memory Databases MemSQL

Design and Evolution of the Apache Hadoop File System(HDFS)

Referential Integrity in Cloud NoSQL Databases

Understanding NoSQL Technologies on Windows Azure

Completing the Big Data Ecosystem:

Cassandra A Decentralized Structured Storage System

BENCHMARKING CLOUD DATABASES CASE STUDY on HBASE, HADOOP and CASSANDRA USING YCSB

Benchmarking Cassandra on Violin

Transcription:

Apache Cassandra for Big Data Applications Christof Roduner COO and co-founder christof@scandit.com Java User Group Switzerland January 7, 2014

2 AGENDA Cassandra origins and use How we use Cassandra Data model and query language Cluster organization Replication and consistency Practical experience

3 WHAT IS CASSANDRA? SQL

4 WHAT IS CASSANDRA? not only SQL

5 ORIGINS Dynamo distributed storage BigTable data model

6 USED BY

7 SCANDIT ETH Zurich startup company Our mission: provide the best mobile barcode scanning platform Customers: Bayer, Coop, CapitalOne, Saks 5 th Avenue, Nasa, Barcode scanning SDKs for: ios, Android Phonegap Titanium Xamarin de Scanner SDK ios v3.0.0 De

8 SCANDIT

9 THE SCANALYTICS PLATFORM Two purposes: 1. External tool for app publishers: App-specific real-time usage statistics Insights into user behavior What do users scan? Product categories? Groceries, electronics, books, cosmetics,? Where do users scan? At home? Or while in a retail store? Top products and brands 2. Internal tool for our algorithms team: Improve our image processing algorithms Detect devices and OS versions with camera issues Monitor scan performance of our SDK

BACKEND REQUIREMENTS 12 Analysis of scans Accept and store high volumes of scans Keep history of billions of camera parameters Generate statistics over extended time periods Provide reports to developers

13 BACKEND DESIGN GOALS Scalability High-volume storage High-volume throughput Support large number of concurrent client requests (mobile devices) Availability Low maintenance Even as our customer base grows Multiple data centers

14 WHY DID WE CHOOSE CASSANDRA? Partitioning A..J K..R S..Z

15 WHY DID WE CHOOSE CASSANDRA? Simplicity Master Slave Coordinator

16 MORE REASONS Looked very fast Even when data is much larger than RAM Performs well in write-heavy environment Proven scalability Without downtime Tunable replication Data model YMMV

WHAT YOU HAVE TO GIVE UP 17 Joins Referential integrity Transactions Expressive query language (nested queries, etc.) Consistency (tunable, but not by default ) Limited support for secondary indices

18 HELLO CQL CREATE TABLE users ( username TEXT, email TEXT, web TEXT, phone TEXT, PRIMARY KEY (username) );

19 HELLO CQL CREATE TABLE users ( username TEXT, email TEXT, web TEXT, phone TEXT, PRIMARY KEY (username) ); INSERT INTO users (username, email, phone) VALUES ('alice', 'alice@example.com', '123-456-7890'); INSERT INTO users (username, email, web) VALUES ('bob', 'bob@example.com', 'www.example.com');

20 HELLO CQL CREATE TABLE users ( username TEXT, email TEXT, web TEXT, phone TEXT, PRIMARY KEY (username) ); INSERT INTO users (username, email, phone) VALUES ('alice', 'alice@example.com', '123-456-7890'); INSERT INTO users (username, email, web) VALUES ('bob', 'bob@example.com', 'www.example.com'); cqlsh:demo> SELECT * FROM users; username email phone web ----------+-------------------+--------------+----------------- bob bob@example.com null www.example.com alice alice@example.com 123-456-7890 null

21 FAMILIAR BUT DIFFERENT CREATE TABLE users ( username TEXT, email TEXT, web TEXT, phone TEXT, PRIMARY KEY (username) ); No auto increments (use natural key or UUID instead) Primary key always mandatory

22 FAMILIAR BUT DIFFERENT cqlsh:demo> SELECT * FROM users; username email phone web ----------+-------------------+--------------+----------------- bob bob@example.com null www.example.com alice alice@example.com 123-456-7890 null

23 FAMILIAR BUT DIFFERENT CREATE TABLE users ( username TEXT, email TEXT, web TEXT, phone TEXT, PRIMARY KEY (username) ); Sort order? cqlsh:demo> SELECT * FROM users; username email phone web ----------+-------------------+--------------+----------------- bob bob@example.com null www.example.com alice alice@example.com 123-456-7890 null

24 UNDER THE HOOD: CLUSTER ORGANIZATION Node 1 Token 0 Range 1-64, stored on node 2 Node 4 Token 192 Node 2 Token 64 Node 3 Token 128 Range 65-128, stored on node 3

STORING A ROW 25 1. Calculate md5 hash for row key (the username field in the example above) Example: md5( alice") = 48 2. Determine data range for hash Example: 48 lies within range 1-64 Node 1 Token 0 Range 1-64, stored on node 2 3. Store row on node responsible for range Example: store on node 2 Node 4 Token 192 Node 2 Token 64 Node 3 Token 128 Range 65-128, stored on node 3

26 IMPLICATIONS Cluster automatically balanced Load is shared equally between nodes No hotspots Scaling out? Easy Divide data ranges by adding more nodes Cluster rebalances itself automatically Range queries not possible You can t retrieve «all rows from A-C» Rows are not stored in their «natural» order Rows are stored in order of their md5 hashes

27 FAMILIAR BUT DIFFERENT CREATE TABLE users ( username TEXT, email TEXT, web TEXT, phone TEXT, PRIMARY KEY (username) ); Sort order? cqlsh:demo> SELECT * FROM users; username email phone web ----------+-------------------+--------------+----------------- bob bob@example.com null www.example.com alice alice@example.com 123-456-7890 null

28 UNDER THE HOOD: PHYSICAL STORAGE A physical row stores data in namevalue pairs ( cells ) Cell name is CQL field name (e.g. email ) Cell value is field data (e.g. bob@example.com ) Cells in row are automatically sorted by name ( email < phone < web ) Cell names can be different in rows Up to 2 billion cells per row INSERT INTO users (username, email, phone) VALUES ('alice', 'alice@example.com', '123-456-7890'); INSERT INTO users (username, email, web) VALUES ('bob', 'bob@example.com', 'www.example.com'); bob email: bob@example.com web: www.example.com Physical row with row key alice alice email: alice@example.com phone: 123-456-7890

29 FAMILIAR BUT DIFFERENT CREATE TABLE users ( username TEXT, email TEXT, web TEXT, phone TEXT, PRIMARY KEY (username) ); Sort order? cqlsh:demo> SELECT * FROM users; username email phone web ----------+-------------------+--------------+----------------- bob bob@example.com null www.example.com alice alice@example.com 123-456-7890 null

30 TWO BILLION CELLS CREATE TABLE users ( ); username TEXT, email TEXT, web TEXT, phone TEXT, address TEXT, spouse TEXT, hobbies TEXT, hair_color TEXT, favorite_dish TEXT, pet_name TEXT, favorite_bands TEXT, two_billionth_field TEXT, PRIMARY KEY (username) Who needs 2 billion fields in a table?!?

31 2 BILLION CELLS: WIDE ROWS Use case: track logins of users Data model: One (wide) physical row per user User name as row key Login details (time, IP address, user agent) in cells Cells ordered and grouped ( clustered ) by login timestamp Cells are now tuple-value pairs Advantage: range queries! alice [2014-01-29, agent]: Firefox [2014-01-29, ip_address]: 208.115.113.86 [2014-01-30, agent]: Firefox [2014-01-30, ip_address]: 66.249.66.183 bob [2014-01-23, agent]: Chrome [2014-01-23, ip_address]: 205.29.190.116

32 2 BILLION CELLS: WIDE ROWS Use case: track logins of users Data model: One (wide) physical row per user User name as row key Login details (time, IP address, user agent) in cells Cells ordered and grouped ( clustered ) by login timestamp Cells are now tuple-value pairs CREATE TABLE logins ( ); username TEXT, timestamp TIMESTAMP, ip_address TEXT, agent TEXT, PRIMARY KEY (username, timestamp) Advantage: range queries! alice [2014-01-29, agent]: Firefox [2014-01-29, ip_address]: 208.115.113.86 [2014-01-30, agent]: Firefox [2014-01-30, ip_address]: 66.249.66.183 bob [2014-01-23, agent]: Chrome [2014-01-23, ip_address]: 205.29.190.116

33 QUERYING THE LOGINS INSERT INTO logins (username, timestamp, ip_address, agent) VALUES ('alice', '2014-01-29 16:22:30 +0100', '208.115.113.86', 'Firefox'); cqlsh:demo> SELECT * FROM logins; username timestamp agent ip_address ----------+--------------------------+---------+----------------- bob 2014-01-23 01:12:49+0100 Chrome 205.29.190.116 alice 2014-01-29 16:22:30+0100 Firefox 208.115.113.86 alice 2014-01-30 07:48:03+0100 Firefox 66.249.66.183 alice 2014-01-30 18:06:55+0100 Firefox 208.115.111.70 alice 2014-01-31 12:37:26+0100 Firefox 66.249.66.183

34 ONE CQL ROW FOR EACH CELL CLUSTER Physical rows alice bob [2014-01-29, agent]: Firefox [2014-01-23, agent]: Chrome [2014-01-29, ip_address]: 208.115.113.86 [2014-01-23, ip_address]: 205.29.190.116 [2014-01-30, agent]: Firefox [2014-01-30, ip_address]: 66.249.66.183 cqlsh:demo> SELECT * FROM logins; CQL rows username timestamp agent ip_address ----------+--------------------------+---------+----------------- bob 2014-01-23 01:12:49+0100 Chrome 205.29.190.116 alice 2014-01-29 16:22:30+0100 Firefox 208.115.113.86 alice 2014-01-30 07:48:03+0100 Firefox 66.249.66.183 alice 2014-01-30 18:06:55+0100 Firefox 208.115.111.70 alice 2014-01-31 12:37:26+0100 Firefox 66.249.66.183

35 RANGE QUERIES REVISITED Range queries involving timestamp field are possible (because cells are ordered by timestamp): cqlsh:demo> SELECT * FROM logins WHERE username = 'bob' AND timestamp > '2014-01-01' AND timestamp < '2014-01-31'; username timestamp agent ip_address ----------+--------------------------+--------+---------------- bob 2014-01-23 01:12:49+0100 Chrome 205.29.190.116 But you still have to provide a row key: cqlsh:demo> SELECT * FROM logins WHERE timestamp > '2014-01-01' AND timestamp < '2014-01-31'; Bad Request: Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING

36 SECONDARY INDICES Queries involving a non-indexed field are not possible: cqlsh:demo> SELECT * FROM users WHERE email = 'bob@example.com'; Bad Request: No indexed columns present in by-columns clause with Equal operator Secondary indices can be defined for (single) fields: CREATE INDEX email_key ON users (email); SELECT * FROM users WHERE email = 'alice@example.com';

SECONDARY INDICES 37 Secondary indices only support equality predicate (=) in queries Each node maintains index for data it owns Request must be forwarded to all nodes Sometimes not the most efficient approach Often better to denormalize and manually maintain your own index

REPLICATION 38 Tunable replication factor (RF) RF > 1: rows are automatically replicated to next RF-1 nodes Node 1 Token 0 Replica 1 of row «foobar» Tunable replication strategy «Ensure two replicas in different data centers, racks, etc.» Node 4 Token 192 Node 2 Token 64 Node 3 Token 128 Replica 2 of row «foobar»

CLIENT ACCESS 39 Clients can send read and write requests to any node This node will act as coordinator Coordinator forwards request to nodes where data resides Node 1 Token 0 Replica 1 of row «alice» Client Node 4 Token 192 Node 2 Token 64 Request: INSERT INTO users(username, email) VALUES ('alice', 'alice@example.com') Node 3 Token 128 Replica 2 of row «alice»

40 CONSISTENCY LEVELS Cassandra offers tunable consistency For all requests, clients can set a consistency level (CL) For writes: CL defines how many replicas must be written before «success» is returned to client For reads: CL defines how many replicas must respond before a result is returned to client Consistency levels: ONE QUORUM ALL (data center-aware levels)

41 INCONSISTENT DATA Example scenario: Replication factor 2 Two existing replica for row «foobar» Client overwrites existing data in «foobar» Replica 2 is down What happens: Cells are updated in replica 1, but not replica 2 (even with CL=ALL!) Timestamps to the rescue Every cell has a timestamp Timestamps are supplied by clients Upon read, the cell with the latest timestamp wins Use NTP

42 PREVENTING INCONSISTENCIES Read repair Hinted handoff Anti entropy

43 EXPIRING DATA Data will be deleted automatically after a given amount of time INSERT INTO users (username, email, phone) VALUES ('alice', 'alice@example.com', '123-456-7890') USING TTL 86400;

44 DISTRIBUTED COUNTERS Useful for analytics applications Atomic increment operation UPDATE counters SET access = access + 1 WHERE url = 'http://www.example.com/foo/bar'

PRODUCTION EXPERIENCE: CLUSTER AT SCANDIT 45 We ve had Cassandra in production use for almost 4 years Nodes in three data centers Linux machines Identical setup on every node Allows for easy failover

46 PRODUCTION EXPERIENCE Mature, no stability issues Very fast Language bindings don t always have the same quality Sometimes out of sync with server, buggy Data model is a mental twist Design-time decisions sometimes hard to change No support for geospatial data

TRYING OUT CASSANDRA 48 Set up a single-node cluster Install binary: Debian, Ubuntu, RHEL, CentOS packages Windows 7 MSI installer Mac OS X (tarball) Amazon Machine Image

DOCUMENTATION 49 DataStax website Company founded by Cassandra developers Apache website Mailing lists

THANK YOU! Questions? (By the way, we re hiring )