go reactive: building responsive, resilient, elastic & message-driven systems

Post on 21-Apr-2017

6.318 Views

Category:

Engineering

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Jonas Bonér CTO Typesafe

@jboner

Go ReactiveBuilding Responsive, Resilient,

Elastic & Message-Driven Systems

The rules of the game

have changed

3

Yesterday Today

3

Yesterday Today

Single machines Clusters of machines

3

Yesterday Today

Single machines Clusters of machines

Single core processors Multicore processors

3

Yesterday Today

Single machines Clusters of machines

Single core processors Multicore processors

Expensive RAM Cheap RAM

3

Yesterday Today

Single machines Clusters of machines

Single core processors Multicore processors

Expensive RAM Cheap RAM

Expensive disk Cheap disk

3

Yesterday Today

Single machines Clusters of machines

Single core processors Multicore processors

Expensive RAM Cheap RAM

Expensive disk Cheap disk

Slow networks Fast networks

3

Yesterday Today

Single 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

3

Yesterday Today

Single 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

3

Yesterday Today

Single 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

Reactive “Readily responsive to a stimulus”

- Merriam Webster

Reactive  Applications

The Principles of Reactive Systems

6

http://reactivemanifesto.org

Responsive “Quick to respond or react appropriately”

- Merriam Webster

9

The system should always be responsive

9

1. Blue skies2. Heavy load3. Failures

The system should always be responsive

Resilient “The ability of a substance or object to spring back into shape”

“The capacity to recover quickly from difficulties” - Merriam Webster

Think Vending Machine

Coffee Machine

Programmer

Think Vending Machine

Coffee Machine

Programmer

Inserts coins

Think Vending Machine

Coffee Machine

Programmer

Inserts coins

Add more coins

Think Vending Machine

Coffee Machine

Programmer

Inserts coins

Gets coffee

Add more coins

Think Vending Machine

Coffee Machine

Programmer

Think Vending Machine

Coffee Machine

Programmer

Inserts coins

Think Vending Machine

Coffee Machine

Programmer

Inserts coins

Think Vending Machine

Out of coffee beans error

Coffee Machine

Programmer

Inserts coins

Think Vending Machine

Out of coffee beans error

WRONG

Coffee Machine

Programmer

Inserts coins

Think Vending Machine

Coffee Machine

Programmer

Inserts coins

Out of coffee beans

failure

Think Vending Machine

Coffee Machine

Programmer

Service Guy

Inserts coins

Out of coffee beans

failure

Think Vending Machine

Coffee Machine

Programmer

Service Guy

Inserts coins

Out of coffee beans

failure

Adds more beans

Think Vending Machine

Coffee Machine

Programmer

Service Guy

Inserts coins

Gets coffee

Out of coffee beans

failure

Adds more beans

Think Vending Machine

The Right Way

ServiceClient

The Right Way

ServiceClient

Request

The Right Way

ServiceClient

Request

Response

The Right Way

ServiceClient

Request

Response

Validation Error

The Right Way

ServiceClient

Request

Response

Validation Error

Application Failure

The Right Way

ServiceClient

Supervisor

Request

Response

Validation Error

Application Failure

The Right Way

ServiceClient

Supervisor

Request

Response

Validation Error

Application Failure

Manages Failure

Resilience IsBy Design

1. Isolate the failure

2. Compartmentalize

3. Manage failure locally

4. Avoid cascading failures

Use Bulkheads

1. Isolate the failure

2. Compartmentalize

3. Manage failure locally

4. Avoid cascading failures

Use Bulkheads

Enter Supervision

A

B

BarFoo

C

BE

A

D

C

Automatic and mandatory supervisionSupervisor hierarchies

A

B

BarFoo

C

E

A

D

C

Automatic and mandatory supervisionSupervisor hierarchies

B

19

Every single actor has a default supervisor strategy. Which is usually sufficient. But it can be overridden.

Supervision in Akka

19

class Supervisor extends AbstractActor { private SupervisorStrategy strategy = new OneForOneStrategy( 10, Duration.create(1, TimeUnit.MINUTES), DirectiveBuilder. match(ArithmeticException.class, e -> resume()). match(NullPointerException.class, e -> restart()). matchAny( e -> escalate()). build()); … // rest of actor omitted

} }

Supervision in Akka

Resilience requires aMessage-DrivenArchitecture

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

- Merriam Webster

UPScale

UPScale

and down

1. Minimize Contention 2. Maximize Locality of Reference

23

We need to

Common points of

24

ApplicationPhysical

contention

25

GO

Async

25

GO

26

Neverever

26

Neverever

Block

26

Neverever

27

NOTHINGshare

28

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

28

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

29

Single Writer Principle

29

Single Writer PrincipleIO deviceProducers

SERIAL & CONTENDED

29

Single Writer PrincipleIO deviceProducers

SERIAL & CONTENDED

IO deviceProducers Actor or Queue

BATCHED & UNCONTENDED

The Role of Immutable State

30

The Role of Immutable State

30

The Role of Immutable State• Great to represent facts • Messages and Events

• Database snapshots

• Representing the succession of time

30

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

Divide & Conquer

31

32

Pipelining

ON DEMAND

33

scale

OUTScale

OUTScale

and in

• Mobile

• Cloud Services, REST etc.

• NOSQL DBs

• Big Data

35

Distributed Computing is the

new normal

What is the essence of distributed systems?

36

What is the essence of distributed systems?

To try to overcome that1. Information travels at the speed of light

2. Independent things fail independently

36

Slow node

Dead node

No difference

37

and a

Between a

The network is

38

The network is

38

http://aphyr.com/posts/288-the-network-is-reliable

Inherently Unreliable

39

Graveyard of distributed systems

39

Graveyard of distributed systems• Distributed Shared Mutable State

• EVIL (where N is number of nodes)N

39

Graveyard of distributed systems• Distributed Shared Mutable State

• EVIL (where N is number of nodes)N

• Serializable Distributed Transactions

39

Graveyard of distributed systems• Distributed Shared Mutable State

• EVIL (where N is number of nodes)N

• Serializable Distributed Transactions

• Synchronous RPC

39

Graveyard of distributed systems• Distributed Shared Mutable State

• EVIL (where N is number of nodes)N

• Serializable Distributed Transactions

• Synchronous RPC

• Guaranteed Delivery

39

Graveyard of distributed systems• Distributed Shared Mutable State

• EVIL (where N is number of nodes)N

• Serializable Distributed Transactions

• Synchronous RPC

• Guaranteed Delivery

• Distributed Objects

• “Sucks like an inverted hurricane” - Martin Fowler

Instead

40

Embrace the Network

Instead

40

and be d

one with itUse

Asynchronous Message Passing

TRANSPARENCY

41

location

42

42

Scaling Up and Out is essentially

the same thing

Elasticity requires aMessage-DrivenArchitecture

AsynchronousMessage-Passingis the enabler

45

Typesafe Reactive Platform

• Actors are lightweight, isolated and and communicate via asynchronous message passing

• Supervision and clustering in support of fault tolerance

• Purely asynchronous and non-blocking web framework

• No container required, no inherent bottlenecks in session management

• Asynchronous and immutable programming constructs

• Composable abstractions enabling simpler concurrency and parallelism

Typesafe Activatorhttp://typesafe.com/platform/getstarted

47

Finance Internet/Social Media Mfg/Hardware Government Retail

Jonas Bonér CTO Typesafe

@jboner

Go ReactiveBuilding Responsive, Resilient,

Elastic & Message-Driven Systems

top related