SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick...

61
AARON MORTON THE LAST PICKLE SCALABLE IOT WITH APACHE CASSANDRA

Transcript of SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick...

Page 1: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

AARON MORTON THE LAST PICKLE

SCALABLE IOT WITH APACHE CASSANDRA

Page 2: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

QUICK LOOK AT A DEV CYCLE

Page 3: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

REQUIREMENTS IN IOT

Page 4: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

HIGH THROUGHPUTREQUIREMENT #1

Page 5: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

5

Page 6: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

6

Page 7: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

7

Page 8: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

TRAFFIC SPIKESREQUIREMENT #2

Page 9: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

9

IT’S 5PM, SEND THE

DATA!

Page 10: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

GEOGRAPHYREQUIREMENT #3

Page 11: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

11

Page 12: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

12

160ms260ms

Page 13: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

GROWTHREQUIREMENT #4

Page 14: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

14

Page 15: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

WHY CASSANDRA?

Page 16: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

LINEAR SCALABILITY

Page 17: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

17

the original ring 8 nodes

Page 18: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

18

12 nodes 50% improvement

Page 19: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

19

CREATE KEYSPACE my_first_keyspace WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': 3 };

Page 20: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

20

Page 21: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

HIGH AVAILABILITY

Page 22: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

22

Page 23: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

23

CREATE KEYSPACE iot WITH replication = { 'class':'NetworkTopologyStrategy', 'los_angeles': 3, 'london': 3 };

Page 24: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

24Los Angeles London

Page 25: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

25

160ms260ms

Page 26: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

DATA MODELING

Page 27: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

LOOKS LIKE RELATIONAL

SIMPLE TABLES

Page 28: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

create table sensor ( id text primary key, location text, date_installed timestamp );

Page 29: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

PARTITION KEY

Page 30: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

30

hash(partition)

hash(id=“mysensor”)

Page 31: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

31

hash(partition)

hash(id=“mysensor”)

Page 32: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

32

hash(id=“mysensor”)

Page 33: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

33

write

read ???

Page 34: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

CLUSTERING KEYSCOMPLEX TABLES

Page 35: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

35

CREATE TABLE clustered ( partition int, clustering_key int, primary key (partition, clustering_key) );

Page 36: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

36

partition=“my partition”

CLUSTERING_KEY=1 CLUSTERING_KEY=82

CLUSTERING_KEY=104

Page 37: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

CASSANDRA STORES ROWS IN SORTED ORDER

Page 38: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

38

INSERT INTO clustered (partition, clustering_key) VALUES (1, 1); INSERT INTO clustered (partition, clustering_key) VALUES (1, 2); INSERT INTO clustered (partition, clustering_key) VALUES (1, 3);

Page 39: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

39

cqlsh:iot> SELECT * FROM clustered WHERE partition = 1;

partition | clustering_key -----------+---------------- 1 | 1 1 | 2 1 | 3

(3 rows)

Page 40: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

40

cqlsh:iot> INSERT INTO clustered (partition, clustering_key) ... VALUES (1, -1); cqlsh:iot> SELECT * FROM clustered WHERE partition = 1;

partition | clustering_key -----------+---------------- 1 | -1 1 | 1 1 | 2 1 | 3

(4 rows)

Page 41: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

41

CREATE TABLE sensor_reading ( sensor text, created_at timestamp, reading int, primary key (sensor, created_at) ) WITH CLUSTERING ORDER BY (created_at DESC);

Page 42: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

42

INSERT INTO sensor_reading (sensor, created_at, reading) VALUES ('test', toTimestamp(now()), 1);

INSERT INTO sensor_reading (sensor, created_at, reading) VALUES ('test', toTimestamp(now()), 2);

INSERT INTO sensor_reading (sensor, created_at, reading) VALUES ('test', toTimestamp(now()), 3);

Page 43: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

43

cqlsh:iot> SELECT * from sensor_reading WHERE sensor = 'test';

sensor | created_at | reading --------+---------------------------------+--------- test | 2017-06-30 01:32:40.533000+0000 | 3 test | 2017-06-30 01:32:39.741000+0000 | 2 test | 2017-06-30 01:32:39.738000+0000 | 1

(3 rows)

Page 44: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

SCALE IT FURTHER

Page 45: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

45

partition: mysensor 100MM readings?

Page 46: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

46

CREATE TABLE sensor_reading_by_day ( sensor text, day date, created_at timestamp, reading int, primary key ((sensor, day), created_at) ) WITH CLUSTERING ORDER BY (created_at DESC);

Page 47: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

47

Page 48: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

48

CREATE TABLE daily_metrics ( sensor text, day date, readings counter, primary key (sensor, day) );

Page 49: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

49

UPDATE daily_metrics SET readings = readings + 1 WHERE sensor = 'mysensor' AND day = '2017-07-07';

Page 50: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

50

CREATE TABLE sensor_reading_by_day ( sensor text, day date, created_at timestamp, bucket int, reading int, primary key ((sensor, day, bucket), created_at) ) WITH CLUSTERING ORDER BY (created_at DESC);

Page 51: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

51

CREATE TABLE air_sensor_readings ( sensor text, day date, created_at timestamp, bucket int, temp float, humidity int, polution_ppm int, primary key ((sensor, day, bucket), created_at) ) WITH CLUSTERING ORDER BY (created_at DESC);

Page 52: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

52

SELECT temp, humidity, polution_ppm FROM air_sensor_readings WHERE sensor = ‘yow_conf' AND day = '2017-07-07' AND bucket = 0 LIMIT 5;

Page 53: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

53

temp | humidity | polution_ppm ------+----------+-------------- 27.1 | 50 | 62 27.1 | 50 | 52 27.1 | 50 | 51 27.1 | 50 | 51 27.1 | 50 | 51

(5 rows)

Page 54: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

TECHNOLOGY LANDSCAPE

Page 55: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

55

EVENTS

LONG TERM HISTORY

FAST ACCESS CURRENT STATE

BULK OPERATIONS

55

Page 56: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

56

DISASTER RECOVERY

WEB API STREAMING

INSIGHT PRODUCT DEV

EVENTS

Page 57: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

57

BLOB STORE LOW $ LOW PERF

DB HIGH $ HIGH PERF

BLOCKSTORE MID $ MID PERF

EVENTS

Page 58: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

58

DISASTER RECOVERY

WEB API STREAMING

INSIGHT PRODUCT DEV

REPUTATION RISK INCREASES

Page 59: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

59

ALL TIME BREAK INS

BREAKING IN NOW !

BREAK INS THIS MONTH

REPUTATION RISK INCREASES

Page 60: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

60

Page 61: SCALABLE IOT WITH APACHE CASSANDRA AARON MORTON … · scalable iot with apache cassandra. quick look at a dev cycle. requirements in iot. high throughput ... requirement #2. 9 it’s

QUESTIONS?