AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

98
Distributed Out of the Box! AWS Simple Workflow Serhiy Batyuk Morning@Lohika May 14, 2016

Transcript of AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Page 1: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Distributed Out of the Box!AWS Simple Workflow

Serhiy Batyuk Morning@Lohika

May 14, 2016

Page 2: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

My Interests

Page 3: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Tech Lead at

Page 4: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

AWS SWF 1 year>

Page 5: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Agenda

SWF Overview

Page 6: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Agenda

SWF Overview Demo

Page 7: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Agenda

SWF Overview Demo Our Experience

Page 8: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

What Is AWS Simple Workflow?

Page 9: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

AWS SWF Use Cases

https://www.youtube.com/watch?v=DYmJIQO2ZyQ&t=83

Media Processing Infrastructure Provisioning

Business ProcessesReport GenerationData Processing

Page 10: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

https://globallogic.com.ua/speaking-event/jeeconf-2015

Page 11: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Preparing to Attend JEEConf

Page 12: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Preparing to Attend JEEConf

Page 13: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Preparing to Attend JEEConf

Page 14: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Preparing to Attend JEEConf

Page 15: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Preparing to Attend JEEConf

PROGRAM

STEPS

Page 16: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Preparing to Attend JEEConf

Page 17: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Preparing to Attend JEEConf

Page 18: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Preparing to Attend JEEConf

Page 19: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Preparing to Attend JEEConf

Page 20: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

AWS SWF

https://aws.amazon.com/swf

Page 21: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Workflows and Activities

WORKFLOW

ACTIVITIES

Page 22: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

SWF Application Architecture

WorkerDecider

Page 23: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

SWF Application Architecture

WorkerDecider

AWS SWF

Page 24: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

AWS SWF

AWS SWF Message Flow

WorkerDecider

Page 25: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

AWS SWF

AWS SWF Message Flow

WorkerDecider

START

Page 26: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

AWS SWF

AWS SWF Message Flow

WorkerDecider

MAKE A DECISION

Page 27: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

AWS SWFGET

HISTORY

AWS SWF Message Flow

WorkerDecider

Page 28: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

AWS SWF

AWS SWF Message Flow

WorkerDecider

BUY TICKET

Page 29: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

AWS SWF

AWS SWF Message Flow

WorkerDecider

BUY TICKET

Page 30: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

AWS SWF

AWS SWF Message Flow

WorkerDecider

TICKET CONFIRMATION

Page 31: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

AWS SWF

AWS SWF Message Flow

WorkerDecider

Page 32: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

AWS SWF

AWS SWF Message Flow

WorkerDecider

MAKE A DECISION

Page 33: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

AWS SWFGET

HISTORY

AWS SWF Message Flow

WorkerDecider

Page 34: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

AWS SWF

AWS SWF Message Flow

WorkerDecider

BOOK HOTEL

Page 35: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

AWS SWF

AWS SWF Message Flow

WorkerDecider

BOOK HOTEL

Page 36: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

AWS SWF

AWS SWF Message Flow

WorkerDecider

HOTEL CONFIRMATION

Page 37: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

AWS SWF

AWS SWF Message Flow

WorkerDecider

Page 38: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

AWS SWF

AWS SWF Message Flow

WorkerDecider

Page 39: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

AWS SWF

AWS SWF Message Flow

WorkerDecider

RESULT

Page 40: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Task Lists and Routing

WorkerDecider

SWF

Page 41: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

AWS SWF API

PollForDecisionTask GetWorkflowExecutionHistory RespondDecisionTaskCompleted

PollForActivityTask RespondActivityTaskCompleted RespondActivityTaskFailed

StartWorkflowExecution

http://docs.aws.amazon.com/amazonswf/latest/apireference

Page 42: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

AWS SWF API

RegisterWorkflowType

RegisterActivityType

http://docs.aws.amazon.com/amazonswf/latest/apireference

Page 43: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

AWS SWF Flow Framework

AWS SWFSWF API

.Net, Python, others

SWF Flow Framework

Java, Ruby

Page 44: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Java Flow Framework

Workflow Worker

Decider

Workflow Implementation

Activities Client

Activities Worker

Worker

Activities Implementations

Workflow Starter

Client app

Workflow Client

SWF

http://docs.aws.amazon.com/amazonswf/latest/awsflowguide/awsflow-basics-application-structure.html

Page 45: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Java Flow Framework

Workflow Worker

Decider

Activities Client

Activities Worker

WorkerClient app

Workflow Client

SWF

http://docs.aws.amazon.com/amazonswf/latest/awsflowguide/awsflow-basics-application-structure.html

Page 46: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Java Flow Framework

Decider

Workflow Implementation

Worker

Activities Implementations

Workflow Starter

Client app

SWF

http://docs.aws.amazon.com/amazonswf/latest/awsflowguide/awsflow-basics-application-structure.html

Page 47: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Java Flow Framework Classes

@Activities

@Workflow Client to schedule workflows

Client to schedule activities

Page 48: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Java Flow Framework Classes

@Activities

@Workflow Client to schedule workflows

Client to schedule activities

WorkflowWorker

ActivitiesWorker

Handle decision tasks

Handle activity tasks

Page 49: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

DemoSWF

Page 50: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Visit Organizer Workflow

Page 51: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Visit Organizer Workflow

Page 52: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Visit Organizer Workflow

Page 53: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Visit Organizer Workflow

Page 54: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Preparing for JEEConf

Visit Organizer

Service

JEEConf Service

Travel Service

Page 55: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Preparing for JEEConf

Visit Organizer

Service

JEEConf Service

Travel Service

Buy tickets

Page 56: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Preparing for JEEConf

Visit Organizer

Service

JEEConf Service

Travel Service

Book hotelBuy

tickets

Page 57: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Preparing for JEEConf

Visit Organizer

Service

JEEConf Service

Travel Service

Book train tickets

Book hotelBuy

tickets

Page 58: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Time to see the code!

public class HelloWorld {

public static void main() { System.out.println(“Hi”); }

}

https://github.com/sbatyuk/aws-swf-sample

Page 59: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

http://info.thinkfun.com/stem-education/mark-engelberg-inventor-of-code-master-featured-in-getting-smart

EASY, RIGHT?

Page 60: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

FeaturesSWF

Page 61: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Fully Managed Service

Page 62: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Worker

Worker

Worker

Decider

Decider

Scalable

AWS SWF

My App

http://docs.aws.amazon.com/amazonswf/latest/awsflowguide/awsflow-basics-scalable.html

Page 63: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Worker

Worker

Worker

Decider

Decider

Scalable

AWS SWF

My App

http://docs.aws.amazon.com/amazonswf/latest/awsflowguide/awsflow-basics-scalable.html

Page 64: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Worker

Worker

Worker

Decider

Decider

Activity Retries

AWS SWF

My App

http://docs.aws.amazon.com/amazonswf/latest/awsflowguide/features-retry.html

Page 65: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Worker

Worker

Worker

Decider

Decider

Activity Retries

AWS SWF

My App

http://docs.aws.amazon.com/amazonswf/latest/awsflowguide/features-retry.html

Page 66: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Worker

Worker

Worker

Decider

Decider

Activity Retries

AWS SWF

My App

http://docs.aws.amazon.com/amazonswf/latest/awsflowguide/features-retry.html

Page 67: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Workflow Execution History

Page 68: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Exactly Once Delivery

= 1

Page 69: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Integration with Spring and JUnit

http://docs.aws.amazon.com/amazonswf/latest/awsflowguide/test.html

Page 70: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Other Features

Child workflows

Lamda tasks

Heartbeats

Continuous workflows

Timers

Signals

Page 71: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

AWS SWF Pricing

https://aws.amazon.com/swf/pricing

10,000 workflows in a day with 3 activities each:

$1.75

Page 72: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Lessons learntSWF

Page 73: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Workflow Replays

http://docs.aws.amazon.com/amazonswf/latest/awsflowguide/awsflow-basics-distributed-execution.html

@Overridepublic void prepareForJEEConf(String name, String email) { Promise<Integer> ticket = jeeConfService.buyTicket(name); Promise<Integer> hotel = travelService.bookHotel(name, ticket); Promise<Integer> train = travelService.bookTrainTickets(name, ticket); sendConfirmationEmail(email, ticket, hotel, train);}

Page 74: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Workflow Replay #1Workflow Activity Client Activity Workflow History

Page 75: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Workflow Replay #1Workflow Activity Client Activity Workflow History

Get history

Page 76: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Workflow Replay #1Workflow Activity Client Activity Workflow History

History

Get history

Page 77: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Workflow Replay #1

Buy ticket

Workflow Activity Client Activity Workflow History

History

Get history

Page 78: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Workflow Replay #1

Buy ticketBuy ticket

Workflow Activity Client Activity Workflow History

History

Get history

Page 79: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Workflow Replay #1

Buy ticket

PromiseBuy ticket

Workflow Activity Client Activity Workflow History

History

Get history

Page 80: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Workflow Replay #1

Buy ticket

PromiseBuy ticket

Book hotel

Workflow Activity Client Activity Workflow History

History

Get history

Page 81: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Workflow Replay #1

Buy ticket

PromiseBuy ticket

Book hotel

Promise

Workflow Activity Client Activity Workflow History

History

Get history

Page 82: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Workflow Replay #1

Buy ticket

PromiseBuy ticket

Book hotel

Promise

Ticket confirmation

Workflow Activity Client Activity Workflow History

History

Get history

Page 83: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Workflow Replay #2Workflow Activity Client Activity Workflow History

Page 84: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Workflow Replay #2Workflow Activity Client Activity Workflow History

Get history

Page 85: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Workflow Replay #2Workflow Activity Client Activity Workflow History

History

Get history

Page 86: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Workflow Replay #2

Buy ticket

Workflow Activity Client Activity Workflow History

History

Get history

Page 87: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Workflow Replay #2

Buy ticket

Workflow Activity Client Activity Workflow History

History

Get history

Promise with confirmation

Page 88: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Workflow Replay #2

Buy ticket

Book hotel

Workflow Activity Client Activity Workflow History

History

Get history

Promise with confirmation

Page 89: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Workflow Replay #2

Buy ticket

Book hotelBook hotel

Workflow Activity Client Activity Workflow History

History

Get history

Promise with confirmation

Page 90: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Workflow Replay #2

Buy ticket

Book hotelBook hotel

Promise

Workflow Activity Client Activity Workflow History

History

Get history

Promise with confirmation

Page 91: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Workflow Replay #2

Buy ticket

Book hotelBook hotel

Promise

Hotel confirmation

Workflow Activity Client Activity Workflow History

History

Get history

Promise with confirmation

Page 92: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Activity Timeouts

Page 93: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Activity Heartbeats

Page 94: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Activity Heartbeats

Page 95: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Serialization of Exceptions

1 1 1 0 1 0 0 0 1 1 0 1 1 1 0 1 0 1 0 1 0 1 1 1 0 1 0 0 0 1 1 1 0 1 0 0 1 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 1 1 1 1 0 0 1 0 0 0 0 1 1 0 1 1 1 1 0 1 1 0 0 1 0 1 1 0 0 0 1 1 0 1 0 0 1 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 1 0 1 1 0 0 1 0 0 1 1 0 1 0 0 0 1 1 1 1 0 1 1 0 0 1 0 0 1 1 1 0 0 1 1 0 0 0 1 1 0 1 1 1 0 0 0 1 0 0 0 1 1 1 1 1 0 0 1 0 1 0 0 0 1 1 1 1 0 0 1 0 0 1 1 1 0 0 0 0 1 0 1 0 1 1 1 1 0 0 0 0 1 1 0 0 1 0 1 0 0 1 1 0 1 0 0 1 1 1 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 0 0 0 0 1 0 1 1 1 0 1 1 1 1 0 0 1 0 1 1 1 1 0 1 1 0 0 1 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 1 1 0 1 1 1 0 0 0 0 1 1 0 0 0 1 1 0 0 1 0 1 0 1 0 0 0 0 1 0 1 1 1 1 1 1 1 1 1 1 0 0 0 1 0 0 1 0 1 1 1 0 1 1 1 1 1 1 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 1 1 0 1 1 1 0 1 0 1 0 1 1 1 0 0 0 1 0 0 0 1 1 0 1 0 1 0 1 1 1 1 0 1 0 1 0 0 0 0 1 0 1 1 0 1 0 0 0 1 1 1 1 0 0 0 0 0 0 1 0 1 0 0 0 1 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/developerguide/swf-dg-limits.html

History events

32K

Message size (chars)

Page 97: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Summary

Programs with steps Scalability

Timeouts & Retries Java & Ruby

Page 98: AWS Simple Workflow: Distributed Out of the Box! - Morning@Lohika

Questions

Serhiy Batyuk [email protected]

@sbatyuk