Customer Loyalty – Cinema – Global Marketing



Customer Loyalty – Cinema – Global Marketing

0 0


cassandra-basic-presentation

Repo for my basic cassandra presentations

On Github kalmanb / cassandra-basic-presentation

Customer Loyalty

Cinema

Global Marketing

USA - 18 million
Canada - 3.7 million
Australia / NZ - 4.3 million
World wide customers - 30 million

So what's the problem?

2M members = 4 CPU thingees
4M members = 16 CPU thingees
20M members = oh no!
  • Aggregation
  • Tuning
  • SSD's
  • ...

Solutions

Big data

Options

Hadoop / Mongo / Redis / CouchDB / HBase / Riak / Neo4j ???

Why Cassandra

Linear scalability
Simple clustering HA

Cassandra

  • Amazon Dynamo (ring)
  • Google Bigtable
CAP Theorem - Consistency, Availability, Partition Tolerance Cassandra = AP ACID - Atomicity, Consistency, Isolation, DurabilityCassandra = Eventual consistency - weak
  • Write vs Read
  • Know your queries
  • No joins
  • No transactions
Idempotent
UPDATE member SET name = 'Kal'
Not
UPDATE member SET time = NOW()
Alternative
var now = CurrentTime()
try {
  execute("UPDATE member SET time = ${now}")
} ...

Tools

Key value lookup
SELECT * FROM member WHERE id = 123
* Linear scale
Range Queries
SELECT * FROM member WHERE time > '2011-02-03' AND time <= '2012-01-01'
* Very fast but need to be sharded

Queries

Think SQL
SELECT * 
FROM member 
WHERE id = 15
        
key columns... 15 nameSam cityAuckland time2011-05-22 16 nameJoe cityWellington time2012-09-23
No Schema
SELECT * 
FROM member 
WHERE id = 15
        
key columns... 15 nameSam cityAuckland genderMale time2011-05-22 16 nameJoe cityWellington time2012-09-23
Wide Rows
SELECT id 
FROM member 
WHERE city = 'Auckland'
        
key columns... Auckland 10_ 11_ 15_ 19_ 33_ 36_ 49_ ..._ Wellington 12_ 16_ 25_ ..._
Range Queries
SELECT id 
FROM member 
WHERE time > '2011-02-03'  
  AND time < '2012-01-01'
        
key columns... . 2009-01-2315 2011-05-2010 2013-01-0311 ......
Multiple Params
SELECT id 
FROM member 
WHERE city = 'Auckland' 
  AND time > '2011-02-03'  
  AND time < '2012-01-01'
        
key columns... Auckland 2009-01-2315 2011-05-2010 2013-01-0311 ...... Wellington 2009-02-0316 2011-07-2212 2013-09-0625 ......
Even More Params
SELECT id 
FROM member 
WHERE city = 'Auckland' 
  AND status = 'VIP' 
  AND time > '2011-02-03' 
  AND time < '2012-01-01'
        
key columns... Auckland status:vip|time:2009_01_2315 status:std|time:2011_05_2010 ......
Auckland status:vip|time:2009_01_23|id:15_ status:std|time:2011_05_20|id:10_ ......
Auckland vip|2009_01_23|15_ std|2011_05_20|10_ ......
Auckland vip|2009_01_23|15_ std|2011_05_20|10_ ......
Auckland:vip 2009_01_23|15_ ...... Auckland:std 2011_05_20|10_ ......
SELECT id 
FROM member 
WHERE time > '2011-02-03'  
  AND time < '2012-01-01' 
  AND city = 'Auckland' 
        
We can only have a single range query and it must be at the last field

Architecture

Replication

RF:3 - CL One - CL Quorum - CL ALL

HA

Other

CQL

UPDATE UserActions 
SET total = total + 2 
WHERE user = '9908-4AE3'
    AND action = 'click';
DELETE phone 
FROM Users 
WHERE userid 
  IN ('AF08-40F3', '9908-4AE3');

CQL

CREATE TABLE monkeySpecies (
    species text PRIMARY KEY,
    common_name text,
    population varint,
    average_size int
) WITH comment='Important biological records'
   AND read_repair_chance = 1.0;

CREATE TABLE timeline (
    userid uuid,
    posted_month int,
    posted_time uuid,
    body text,
    posted_by text,
    PRIMARY KEY (userid, posted_month, posted_time)
) WITH compaction = { 'class' : 'LeveledCompactionStrategy' };
Batches
BEGIN BATCH
    INSERT INTO users (userid, password, name) 
        VALUES ('user2', 'ch@ngem3b', 'second user');
    UPDATE users SET password = 'ps22dhds' WHERE userid = 'user3';
    INSERT INTO users (userid, password) VALUES ('user4', 'ch@ngem3c');
    DELETE name FROM users WHERE userid = 'user1';
APPLY BATCH;
If any of the batch succeeds then all of it will
Secondary Indexes (Low cardinality)
Specify Timestamps
TTL's
Tombstones GC Grace
Counters
ID's
Filtering
Joins (Denormalisation)

Collections

  • Maps
  • Sets
  • Lists

Maps

CREATE TABLE member (
    id text PRIMARY KEY,
    favs map<text, text="">   // A map of text keys, and text values
)

// Inserting (or Updating)
INSERT INTO members (id, favs)
    VALUES ('jsmith', { 'fruit' : 'apple', 'band' : 'Beatles' })</text,>

Lightweight Transactions

INSERT INTO member (name, city) 
VALUES (‘John’, ‘Auckland’)
IF NOT EXISTS;
UPDATE member
SET email = 'new@gmail.com'
IF email = 'orig@gmail.com';

Questions?

http://movio.co @kalmanb