reactive supply to changing demand

101
Reactive Supply to Changing Demand Jonas Bonér Typesafe CTO & co-founder @jboner Building Elastic Reactive Systems

Upload: jonas-boner

Post on 21-Apr-2017

4.055 views

Category:

Engineering


2 download

TRANSCRIPT

Page 1: Reactive Supply To Changing Demand

Reactive Supply to Changing Demand

Jonas Bonér Typesafe

CTO & co-founder @jboner

Building Elastic Reactive Systems

Page 2: Reactive Supply To Changing Demand

Outline

1. Introduction

2. Scale Up

3. Scale Out

4. Bring It Together

2

Page 3: Reactive Supply To Changing Demand

Outline

1. Introduction

2. Scale Up

3. Scale Out

4. Bring It Together

3

Page 4: Reactive Supply To Changing Demand

The rules of the game

have changed

Page 5: Reactive Supply To Changing Demand

5

Yesterday Today

Page 6: Reactive Supply To Changing Demand

5

Yesterday TodaySingle machines

Page 7: Reactive Supply To Changing Demand

5

Yesterday TodaySingle machines Clusters of machines

Page 8: Reactive Supply To Changing Demand

5

Yesterday TodaySingle machines Clusters of machines

Single core processors

Page 9: Reactive Supply To Changing Demand

5

Yesterday TodaySingle machines Clusters of machines

Single core processors Multicore processors

Page 10: Reactive Supply To Changing Demand

5

Yesterday TodaySingle machines Clusters of machines

Single core processors Multicore processors

Expensive RAM

Page 11: Reactive Supply To Changing Demand

5

Yesterday TodaySingle machines Clusters of machines

Single core processors Multicore processors

Expensive RAM Cheap RAM

Page 12: Reactive Supply To Changing Demand

5

Yesterday TodaySingle machines Clusters of machines

Single core processors Multicore processors

Expensive RAM Cheap RAM

Expensive disk

Page 13: Reactive Supply To Changing Demand

5

Yesterday TodaySingle machines Clusters of machines

Single core processors Multicore processors

Expensive RAM Cheap RAM

Expensive disk Cheap disk

Page 14: Reactive Supply To Changing Demand

5

Yesterday TodaySingle machines Clusters of machines

Single core processors Multicore processors

Expensive RAM Cheap RAM

Expensive disk Cheap disk

Slow networks

Page 15: Reactive Supply To Changing Demand

5

Yesterday TodaySingle machines Clusters of machines

Single core processors Multicore processors

Expensive RAM Cheap RAM

Expensive disk Cheap disk

Slow networks Fast networks

Page 16: Reactive Supply To Changing Demand

5

Yesterday TodaySingle machines Clusters of machines

Single core processors Multicore processors

Expensive RAM Cheap RAM

Expensive disk Cheap disk

Slow networks Fast networks

Few concurrent users

Page 17: Reactive Supply To Changing Demand

5

Yesterday TodaySingle machines Clusters of machines

Single core processors Multicore processors

Expensive RAM Cheap RAM

Expensive disk Cheap disk

Slow networks Fast networks

Few concurrent users Lots of concurrent users

Page 18: Reactive Supply To Changing Demand

5

Yesterday TodaySingle machines Clusters of machines

Single core processors Multicore processors

Expensive RAM Cheap RAM

Expensive disk Cheap disk

Slow networks Fast networks

Few concurrent users Lots of concurrent users

Small data sets

Page 19: Reactive Supply To Changing Demand

5

Yesterday TodaySingle machines Clusters of machines

Single core processors Multicore processors

Expensive RAM Cheap RAM

Expensive disk Cheap disk

Slow networks Fast networks

Few concurrent users Lots of concurrent users

Small data sets Large data sets

Page 20: Reactive Supply To Changing Demand

5

Yesterday TodaySingle machines Clusters of machines

Single core processors Multicore processors

Expensive RAM Cheap RAM

Expensive disk Cheap disk

Slow networks Fast networks

Few concurrent users Lots of concurrent users

Small data sets Large data sets

Latency in seconds

Page 21: Reactive Supply To Changing Demand

5

Yesterday TodaySingle machines Clusters of machines

Single core processors Multicore processors

Expensive RAM Cheap RAM

Expensive disk Cheap disk

Slow networks Fast networks

Few concurrent users Lots of concurrent users

Small data sets Large data sets

Latency in seconds Latency in milliseconds

Page 22: Reactive Supply To Changing Demand
Page 23: Reactive Supply To Changing Demand

Cost Gravity is at Work

7

Page 24: Reactive Supply To Changing Demand

Cost Gravity is at Work

7

Page 25: Reactive Supply To Changing Demand

The Principles of Reactive Systems

Page 26: Reactive Supply To Changing Demand

The Principles of Reactive Systems

Page 27: Reactive Supply To Changing Demand

Elastic “Capable of ready change or easy expansion or contraction”

- Merriam Webster

Page 28: Reactive Supply To Changing Demand

Scale on Demand?Why do we need to

Page 29: Reactive Supply To Changing Demand

scalability?what is

Page 30: Reactive Supply To Changing Demand

12

“Capable of being easily expanded or upgraded on demand” - Merriam Webster Dictionary

Page 31: Reactive Supply To Changing Demand

13

“The house in which Amdahl wakes up very early each day and

rules with an iron fist.” - Martin Thompson (originally Gil Tene)

Page 32: Reactive Supply To Changing Demand

13

“The house in which Amdahl wakes up very early each day and

rules with an iron fist.” - Martin Thompson (originally Gil Tene)

Page 33: Reactive Supply To Changing Demand

14

“A service is said to be scalable if when we increase the

resources in a system, it results in increased performance

in a manner proportional to resources added.” - Werner Vogels

Page 34: Reactive Supply To Changing Demand

vs Scalability Performance

Page 35: Reactive Supply To Changing Demand

Outline

1. Introduction

2. Scale Up

3. Scale Out

4. Bring It Together

16

Page 36: Reactive Supply To Changing Demand

UPScale

Page 37: Reactive Supply To Changing Demand

UPScale

and down

Page 38: Reactive Supply To Changing Demand

18

Modern CPU architecture

Page 39: Reactive Supply To Changing Demand

18

Modern CPU architecture

Page 40: Reactive Supply To Changing Demand

18

Modern CPU architecture

Page 41: Reactive Supply To Changing Demand

18

Modern CPU architecture

Page 42: Reactive Supply To Changing Demand

The CPU is gambling—taking bets

19

Page 43: Reactive Supply To Changing Demand

MaximizeLocality of Reference

Page 44: Reactive Supply To Changing Demand

MinimizeContention

Page 45: Reactive Supply To Changing Demand

Common points of

22

ApplicationPhysical

contention

Page 46: Reactive Supply To Changing Demand

23

Neverever

Page 47: Reactive Supply To Changing Demand

23

Neverever

Page 48: Reactive Supply To Changing Demand

Block

23

Neverever

Page 49: Reactive Supply To Changing Demand

24

GO

Page 50: Reactive Supply To Changing Demand

Async

24

GO

Page 51: Reactive Supply To Changing Demand

25

NOTHINGshare

Page 52: Reactive Supply To Changing Demand

Divide & Conquer

26

Page 53: Reactive Supply To Changing Demand

27

Single Writer Principle

Page 54: Reactive Supply To Changing Demand

27

Single Writer PrincipleIO deviceProducers

SERIAL & CONTENDED

Page 55: Reactive Supply To Changing Demand

27

Single Writer PrincipleIO deviceProducers

SERIAL & CONTENDED

IO deviceProducers Actor or Queue

BATCHED & UNCONTENDED

Page 56: Reactive Supply To Changing Demand

28

Page 57: Reactive Supply To Changing Demand

29

Needs to be async and non-blocking all the way down

Page 58: Reactive Supply To Changing Demand

29

Needs to be async and non-blocking all the way down

Page 59: Reactive Supply To Changing Demand

The Role of Immutable State

30

Page 60: Reactive Supply To Changing Demand

The Role of Immutable State

30

Page 61: Reactive Supply To Changing Demand

The Role of Immutable State• Great to represent facts

• Messages and Events

• Database snapshots

• Representing the succession of time

30

Page 62: Reactive Supply To Changing Demand

The Role of Immutable State• Great to represent facts

• Messages and Events

• Database snapshots

• Representing the succession of time

• Mutable State is ok if local and contained

• Allows Single-threaded processing

• Allows single writer principle

• Feels more natural

• Publish the results to the world as Immutable State

30

Page 63: Reactive Supply To Changing Demand

on DemandScale

Page 64: Reactive Supply To Changing Demand

Outline

1. Introduction

2. Scale Up

3. Scale Out

4. Bring It Together

32

Page 65: Reactive Supply To Changing Demand

OUTScale

Page 66: Reactive Supply To Changing Demand

OUTScale

and in

Page 67: Reactive Supply To Changing Demand

• Mobile

• Cloud Services, REST etc.

• NOSQL DBs

• Big Data

• etc

34

Distributed Computing is the

new normal

Page 68: Reactive Supply To Changing Demand

What is the essence of distributed computing?

35

To try to overcome that

Page 69: Reactive Supply To Changing Demand

What is the essence of distributed computing?

1. Information travels at the speed of light

2. Independent things fail independently

35

To try to overcome that

Page 70: Reactive Supply To Changing Demand

36

Page 71: Reactive Supply To Changing Demand

Node Node Node

36

Node

Page 72: Reactive Supply To Changing Demand

Middleware

Node Node Node

36

Node

Page 73: Reactive Supply To Changing Demand

Cluster/Rack/Datacenter

Cluster/Rack/Datacenter

Cluster/Rack/Datacenter

Middleware

Node Node Node

36

Node

Page 74: Reactive Supply To Changing Demand

37

1. The network is reliable 2. Latency is zero 3. Bandwidth is infinite 4. The network is secure 5. Topology doesn't change 6. There is one administrator 7. Transport cost is zero 8. The network is homogeneous

Peter Deutsch’s 8 Fallacies of

Distributed Computing

Page 75: Reactive Supply To Changing Demand

The Graveyard of Distributed Systems

• Distributed Shared Mutable State

•⇒ EVIL (where N is number of nodes)

• Serializable Distributed Transactions

• Synchronous RPC

• Guaranteed Delivery

• Distributed Objects

• “Sucks like an inverted hurricane” - Martin Fowler

38

N

Page 76: Reactive Supply To Changing Demand

MaximizeLocality of Reference

Page 77: Reactive Supply To Changing Demand

Strong Consistency

Page 78: Reactive Supply To Changing Demand

41

Linearizability

“Under linearizable consistency, all operations appear to have

executed atomically in an order that is consistent with the

global real-time ordering of operations.” - Herlihy & Wing 1991

Page 79: Reactive Supply To Changing Demand

Strong Consistency Protocols

Page 80: Reactive Supply To Changing Demand

(Coordination in the Cluster)

MinimizeContention

Page 81: Reactive Supply To Changing Demand

44

CAPTheorem

Page 82: Reactive Supply To Changing Demand

44

CAPTheorem

Page 83: Reactive Supply To Changing Demand

ConsistencyEventual

Page 84: Reactive Supply To Changing Demand

46

CRDTCvRDTs/CmRDTs

Page 85: Reactive Supply To Changing Demand

47

“In general, application developers simply do not

implement large scalable applications assuming

distributed transactions.” -­‐  Pat Helland

Life beyond Distributed Transactions: an Apostate’s Opinion

Page 86: Reactive Supply To Changing Demand

48

“State transitions are an important part of our problem

space and should be modeled within our domain.”  - Greg Young

Domain Events

Page 87: Reactive Supply To Changing Demand

49

"The database is a cache of a subset of the log.” - Pat Helland

The Event Log

Page 88: Reactive Supply To Changing Demand

The Event Log• Append-Only Logging

• Database of Facts

• Two models:

• One single Event Log

• Strong Consistency

• Multiple sharded Event Logs

• Strong + Eventual Consistency

50

Page 89: Reactive Supply To Changing Demand

Outline

1. Introduction

2. Scale Up

3. Scale Out

4. Bring It Together

51

Page 90: Reactive Supply To Changing Demand

NOTHING

52

share

Page 91: Reactive Supply To Changing Demand

TRANSPARENCY

53

location

Page 92: Reactive Supply To Changing Demand

54

Page 93: Reactive Supply To Changing Demand

54

Page 94: Reactive Supply To Changing Demand

55

Page 95: Reactive Supply To Changing Demand

Data Center

55

Data Center

ClusterClusterMachineMachineJVMJVMNodeNodeThreadThreadCPUCPUCPU Socket

CPU Socket

CPU Core

CPU Core

CPU L1/L2 Cache

CPU L1/L2 Cache

Page 96: Reactive Supply To Changing Demand

56

Scaling Up and Out is essentially

the same thing

Page 97: Reactive Supply To Changing Demand

56

Scaling Up and Out is essentially

the same thing

Page 98: Reactive Supply To Changing Demand
Page 99: Reactive Supply To Changing Demand

Elasticity requires aMessage-DrivenArchitecture

Page 100: Reactive Supply To Changing Demand

Questions?

Page 101: Reactive Supply To Changing Demand

Reactive Supply to Changing Demand

Jonas Bonér Typesafe

CTO & co-founder @jboner

Building Elastic Reactive Systems