building reactive applications with akka

Post on 02-Jul-2015

1.594 Views

Category:

Software

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

Knoldus organized a Meetp up on Wednesday, 29 Oct 2014 at 5:00PM. Mr. Nilanjan Raychaudhuri from Typesafe presented this session on "Building Reactive applications with Akka". He did the session remotely from Germany and it was very well accepted by the audience at the meetup. Nilanjan is a consultant/trainer and member of Play framework team. He works for Typesafe. He has more than 14 years of experience managing and developing software solutions in Java, Ruby, Groovy and also in Scala. He is zealous about programming in Scala ever since he got introduced to this beautiful language. He enjoys sharing his experience via talks in various conferences and he is also the author of the “Scala in Action” book. We would like to thank Nilanjan for his time and his valuable insights. Checkout this presentation to find how Akka help you to build Reactive applications.

TRANSCRIPT

Building Reactive applicationsusing Akka

Nilanjan Raychaudhuri@nraychaudhuri

Reactive  Applications

3

@nraychaudhuri

Essence of Reactive applications

Reactive Traits

Akka is enabler of Reactive applications

Reactive  Applications

• Individual entities that can only communicate by passing messages

• Excellent for isolating mutable state and protecting it without locks

• Location transparency for remote and clustered topologies

• Supervision

• Well-suited for creating state machines

• Fault tolerance via Supervision

8

Reactive  Applications

Reference Architecture

9

Play  Server

Play  Server

Play  Server

Play  Server

Web  Tier  (Play) Work  Tier  (Akka)

Akka  Master  Router

Akka  Router  Standby

Akka  Worker

Akka  Worker

Akka  Worker

Akka  Worker

Akka  Worker

responsive event drivenscalableresilient

Message-driven

Reactive applications are architected based on loosely coupled design

Reactive  Applications

Message-Driven• Loosely coupled architecture, easier to extend, maintain, evolve

• Asynchronous and non-blocking• Concurrent by design, immutable state• Lower latency and higher throughput

11

“Clearly, the goal is to do these operations concurrently and non-blocking, so that entire blocks of seats or sections are not locked.

We’re able to find and allocate seats under load in less than 20ms without trying very hard to achieve it.”  

Andrew Headrick, Platform Architect, Ticketfly

Introducing Actor Model

13

A computational model that embodies:

✓ Processing

✓ Storage

✓ Communication

Supports 3 axioms—when an Actor receives a message it can:

1.Create new Actors

2.Send messages to Actors it knows

3.Designate how it should handle the next message it receives

Actor model

Thread pool

Actor modelActor model

Actor Actor

Akka  actor  -­‐  Definition

15

Akka  actor  -­‐  Create

16

Akka  actor  -­‐  Send

17

Elastic

Reactive applications scale up and down to meet demand

Elastic• Scalability and elasticity to embrace the Cloud

• Leverage all cores via asynchronous programming• Clustered servers support joining and leaving of nodes• More cost-efficient utilization of hardware

“Our traffic can increase by as much as 100x for 15 minutes each day. Until a couple of years ago, noon was a stressful time.

Nowadays, it’s usually a non-event.”  

Eric Bowman, VP Architecture, Gilt Groupe

19

20

FlightSearchActor

21

FlightSearch Actor - I

22

FlightSearch Actor - II

23

FlightSearchActor

24

SearchWorker - I

25

SearchWorker - II

26

ProviderProxyActor

27

ProviderProxy - I

28

ProviderProxy - II

29

Flight search flow

30

Let it crash

Reactive applications are architected to handle failure at all levels.

Resilient• Failure is embraced as a natural state in the app lifecycle

• Resilience is a first-class construct• Failure is detected, isolated, and managed• Applications self heal

33

“The Typesafe Reactive Platform helps us maintain a very aggressive development and deployment cycle, all in a fail-forward manner.

It’s now the default choice for developing all new services.”  

Peter Hausel, VP Engineering, Gawker Media

Failure?

34

Think Vending Machine

Coffee MachineProgrammer

Inserts coins

Gets coffee

Add more coins

Think Vending Machine

Coffee MachineProgrammer

Service Guy

Inserts coins

Gets coffee

Out of coffee beans

error

Adds more beans

Think Vending Machine

Out of coffee beans errorWrong

The Right Way

ServiceClient

Supervisor

Request

Response

Validation Error

Application Error

Manages Failure

Supervision

39

A

B

BarFoo

C

BE

A

C

system.actorOf(Props[Foo], “Foo”)

context.actorOf(Props[A], “A”)

Actor Topology

OneForOne

AllForOne

Reactive  Applications

Isolate failure at all levels• Within one node

• Across many nodes (JVMs)

• Across many physical servers

• Across data centers

43

Scale out

45

Akka clustering

Reactive  Applications

IoT

46

Reactive  Applications

Precision Farming

47

Akka ClusterJournal

Code

Q & Option[A]

@nraychaudhuri

©Typesafe 2014 – All Rights Reserved

top related