2. Five years of Cassandra
0.1
Jul-08
...
0.3
Jul-09
0.6
May-10
0.7
Feb-11
1.0
Dec-11
DSE
1.2
Oct-12
2.0
Jul-13
3.
4. Application/Use Case
• Social Signals: like/want/own
features for eBay product and item
pages
• Hunch taste graph for eBay users
and items
• Many time series use cases
Why Cassandra?
• Multi-datacenter
• Scalable
• Write performance
• Distributed counters
• Hadoop support
ACE
28. Ease of use
CREATE TABLE users (
id uuid PRIMARY KEY,
name text,
state text,
birth_date int
);
CREATE INDEX ON
users(state);
SELECT * FROM users
WHERE state=‘Texas’
AND birth_date > 1950;
33. Partitioning
Primary key determines placement*
jim
age: 36
car: camaro gender: M
carol
age: 37
car: subaru gender: F
johnny
age:12
gender: M
suzy
age:10
gender: F
66. Race condition
#CASSANDRAEU
SELECT name
FROM users
WHERE username = 'pmcfadin';
(0 rows)
SELECT name
FROM users
WHERE username = 'pmcfadin';
INSERT INTO users
(username, name, email,
password, created_date)
VALUES ('pmcfadin',
'Patrick McFadin',
['patrick@datastax.com'],
'ba27e03fd9...',
'2011-06-20 13:50:00');
(0 rows)
67. Race condition
#CASSANDRAEU
SELECT name
FROM users
WHERE username = 'pmcfadin';
(0 rows)
SELECT name
FROM users
WHERE username = 'pmcfadin';
INSERT INTO users
(username, name, email,
password, created_date)
VALUES ('pmcfadin',
'Patrick McFadin',
['patrick@datastax.com'],
'ba27e03fd9...',
'2011-06-20 13:50:00');
(0 rows)
INSERT INTO users
(username, name, email,
password, created_date)
VALUES ('pmcfadin',
'Patrick McFadin',
['patrick@datastax.com'],
'ea24e13ad9...',
'2011-06-20 13:50:01');
68. Race condition
#CASSANDRAEU
SELECT name
FROM users
WHERE username = 'pmcfadin';
(0 rows)
SELECT name
FROM users
WHERE username = 'pmcfadin';
INSERT INTO users
(username, name, email,
password, created_date)
VALUES ('pmcfadin',
'Patrick McFadin',
['patrick@datastax.com'],
'ba27e03fd9...',
'2011-06-20 13:50:00');
(0 rows)
This one wins
INSERT INTO users
(username, name, email,
password, created_date)
VALUES ('pmcfadin',
'Patrick McFadin',
['patrick@datastax.com'],
'ea24e13ad9...',
'2011-06-20 13:50:01');
69. Lightweight transactions
INSERT INTO users
(username, name, email,
password, created_date)
VALUES ('pmcfadin',
'Patrick McFadin',
['patrick@datastax.com'],
'ba27e03fd9...',
'2011-06-20 13:50:00')
IF NOT EXISTS;
#CASSANDRAEU
70. Lightweight transactions
INSERT INTO users
(username, name, email,
password, created_date)
VALUES ('pmcfadin',
'Patrick McFadin',
['patrick@datastax.com'],
'ba27e03fd9...',
'2011-06-20 13:50:00')
IF NOT EXISTS;
[applied]
----------True
#CASSANDRAEU
INSERT INTO users
(username, name, email,
password, created_date)
VALUES ('pmcfadin',
'Patrick McFadin',
['patrick@datastax.com'],
'ea24e13ad9...',
'2011-06-20 13:50:01')
IF NOT EXISTS;
71. Lightweight transactions
INSERT INTO users
(username, name, email,
password, created_date)
VALUES ('pmcfadin',
'Patrick McFadin',
['patrick@datastax.com'],
'ba27e03fd9...',
'2011-06-20 13:50:00')
IF NOT EXISTS;
[applied]
----------True
#CASSANDRAEU
INSERT INTO users
(username, name, email,
password, created_date)
VALUES ('pmcfadin',
'Patrick McFadin',
['patrick@datastax.com'],
'ea24e13ad9...',
'2011-06-20 13:50:01')
IF NOT EXISTS;
[applied] | username | created_date
| name
-----------+----------+----------------+---------------False | pmcfadin | 2011-06-20 ... | Patrick McFadin
72. Paxos
•All operations are quorum-based
•Each replica sends information about unfinished
operations to the leader during prepare
•Paxos made Simple
73. Details
•4 round trips vs 1 for normal updates
•Paxos state is durable
•Immediate consistency with no leader election or failover
•ConsistencyLevel.SERIAL
•http://www.datastax.com/dev/blog/lightweighttransactions-in-cassandra-2-0
74. Use with caution
•Great for 1% of your application
•Eventual consistency is your friend
• http://www.slideshare.net/planetcassandra/c-summit-2013-
eventual-consistency-hopeful-consistency-by-christos-kalantzis
76. User defined types
CREATE TYPE address (
street text,
city text,
zip_code int,
phones set<text>
)
CREATE TABLE users (
id uuid PRIMARY KEY,
name text,
addresses map<text, address>
)
SELECT id, name, addresses.city, addresses.phones FROM users;
id |
name | addresses.city |
addresses.phones
--------------------+----------------+-------------------------63bf691f | jbellis |
Austin | {'512-4567', '512-9999'}
77. Collection indexing
CREATE TABLE songs (
id uuid PRIMARY KEY,
artist text,
album text,
title text,
data blob,
tags set<text>
);
CREATE INDEX song_tags_idx ON songs(tags);
SELECT * FROM songs WHERE 'blues' IN tags;
id
| album
| artist
| tags
| title
----------+---------------+-------------------+-----------------------+-----------------5027b27e | Country Blues | Lightnin' Hopkins | {'acoustic', 'blues'} | Worrying My Mind