Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

Mikhail Shilkov Software Developer Microsoft Azure MVP Serverless Azure Functions Functional Programming F# @MikhailShilkov https://mikhail.io

Slide 3

Slide 3 text

Stateful Workflows Stateless Serverless Cloud Functions

Slide 4

Slide 4 text

Stateful Workflows Stateless Serverless Cloud Functions

Slide 5

Slide 5 text

Stateful Workflows Stateless Serverless Cloud Functions

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Module A Module B Module C Shared Database

Slide 8

Slide 8 text

Service A Service B Service C Database A Database B Database C

Slide 9

Slide 9 text

Service A Service B Unreliable Network Database A Database B

Slide 10

Slide 10 text

Service A Service B Service C HTTP(S) HTTP(S)

Slide 11

Slide 11 text

Service A Service B Service C HTTP(S) HTTP(S)

Slide 12

Slide 12 text

Service A Service B Service C HTTP(S) HTTP(S)

Slide 13

Slide 13 text

Service A Service B Service C HTTP(S) HTTP(S)

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Service A Service B Service C Event Event

Slide 16

Slide 16 text

Ignite Ticket Booked Conference Planning Started Flight to Singapore Booked Hotel Room Reserved Event Log

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

• • • •

Slide 22

Slide 22 text

• • • •    

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

$

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

Book Conf. Book Flight Book Hotel Event Event

Slide 30

Slide 30 text

Book Conf. Book Flight Book Hotel Event Event Book Flight Event Book Conf. Event Book Hotel

Slide 31

Slide 31 text

Book Conf. Book Flight Event

Slide 32

Slide 32 text

Book Conf. Book Flight Event Book Train

Slide 33

Slide 33 text

Plan Tour Plan Milan Report Expenses Plan Berlin Event Event Event

Slide 34

Slide 34 text

Plan Ignite The Tour Singapore Book Conf. Book Flight Book Hotel

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

long-running orchestrations single function maintaining local state complex transactions code-only C#, F#, JavaScript

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

Book Conf. Book Flight Book Hotel

Slide 39

Slide 39 text

[FunctionName("BookConference")] public static string BookConference( [ActivityTrigger] string name) { var ticket = BookingService.Book(name); return $"Ticket is {ticket}"; }

Slide 40

Slide 40 text

[FunctionName("BookConference")] public static string BookConference( [ActivityTrigger] string name) { var ticket = BookingService.Book(name); return $"Ticket is {ticket}"; }

Slide 41

Slide 41 text

[FunctionName("BookConference")] public static string BookConference( [ActivityTrigger] string name) { var ticket = BookingService.Book(name); return $"Ticket is {ticket}"; }

Slide 42

Slide 42 text

Plan Trip to Ignite Singapore Book Conf. Book Flight Book Hotel

Slide 43

Slide 43 text

[FunctionName("TrivialOrchestrator")] public static async Task Trivial( [OrchestrationTrigger] DurableOrchestrationContext context) { await context.CallActivityAsync ("BookConference", "Codemotion Milan"); }

Slide 44

Slide 44 text

[FunctionName("TrivialOrchestrator")] public static async Task Trivial( [OrchestrationTrigger] DurableOrchestrationContext context) { await context.CallActivityAsync ("BookConference", "Codemotion Milan"); }

Slide 45

Slide 45 text

[FunctionName("TrivialOrchestrator")] public static async Task Trivial( [OrchestrationTrigger] DurableOrchestrationContext context) { await context.CallActivityAsync ("BookConference", "Ignite Singapore"); }

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

Plan Ignite The Tour Singapore Book Conf. Book Flight Book Hotel 1 2 3

Slide 49

Slide 49 text

public static async Task Sequential(DurableOrchestrationContext context) { var conf = await context.CallActivityAsync ("BookConference", "Ignite Singapore"); var flight = await context.CallActivityAsync ("BookFlight", conf.Dates); await context.CallActivityAsync("BookHotel", flight.Dates); }

Slide 50

Slide 50 text

Orchestrator Activity Message Message Activity is scheduled Activity result is reported back

Slide 51

Slide 51 text

1. Orchestrator Started 2. ExecutionStarted: PlanTrip 3. TaskScheduled: BookConference 4. OrchestratorCompleted 5. TaskCompleted: "Ticket is 000123" 6. OrchestratorStarted 7. TaskScheduled: BookFlight 8. OrchestratorCompleted 9. TaskCompleted: “Reservation UY9H2J"

Slide 52

Slide 52 text

public static async Task Sequential(DurableOrchestrationContext context) { var conf = await context.CallActivityAsync ("BookConference", "Ignite Singapore"); var flight = await context.CallActivityAsync ("BookFlight", conf.Dates); await context.CallActivityAsync("BookHotel", flight.Dates); }

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

Parent Orchest- rator Sub- Orchestrator Sub- Orchestrator

Slide 56

Slide 56 text

public static async Task SuperOrchestrator( DurableOrchestrationContext context) { await context.CallSubOrchestratorAsync ("BookTrip", igniteSingapore); await context.CallSubOrchestratorAsync ("BookTrip", igniteLondon); }

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

Plan Ignite The Tour Singapore Book Conf. Book Flight Book Hotel 1 2

Slide 59

Slide 59 text

public static async Task ErrorHandling(DurableOrchestrationContext context) { await context.CallActivityAsync("BookConference", "Ignite Singapore"); try { var itinerary = MakeItinerary(...); await context.CallActivityAsync("BookFlight", itinerary); } catch (FunctionFailedException) { var alternativeItinerary = MakeAnotherItinerary(...); await context.CallActivityAsync("BookFlight", alternativeItinerary); } await context.CallActivityAsync("BookHotel", stay); }

Slide 60

Slide 60 text

public static async Task ErrorHandling(DurableOrchestrationContext context) { await context.CallActivityAsync("BookConference", "Ignite Singapore"); try { var itinerary = MakeItinerary(...); await context.CallActivityAsync("BookFlight", itinerary); } catch (FunctionFailedException) { var alternativeItinerary = MakeAnotherItinerary(...); await context.CallActivityAsync("BookFlight", alternativeItinerary); } await context.CallActivityAsync("BookHotel", stay); }

Slide 61

Slide 61 text

Plan Trip to Ignite Singapore Book Conf. Book Flight Book Hotel 1 2

Slide 62

Slide 62 text

public static async Task Retries(DurableOrchestrationContext context) { await context.CallActivityAsync("BookConference", "Ignite Singapore"); var options = new RetryOptions( firstRetryInterval: TimeSpan.FromMinutes(1), maxNumberOfAttempts: 3); options.BackoffCoefficient = 2.0; await context.CallActivityWithRetryAsync("BookFlight", options, itinerary); await context.CallActivityAsync("BookHotel", stay); }

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

Plan Ignite The Tour Plan Milan Report Expenses Plan Berlin 1 2 1

Slide 65

Slide 65 text

public static async Task Parallel(DurableOrchestrationContext cxt) { var milan = cxt.CallSubOrchestratorAsync ("BookTrip", igniteMilan); var berlin = cxt.CallSubOrchestratorAsync ("BookTrip", igniteBerlin); var bookings = await Task.WhenAll(milan, berlin); await cxt.CallActivityAsync("ReportExpenses", bookings); }

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

Report Expenses At Schedule E-mail Result or Timeout Human Approves Timeout

Slide 68

Slide 68 text

// Schedule an e-mail with link to approve/reject var sendAt = context.CurrentUtcDateTime.Date.Add(OneDay); await context.CreateTimer(sendAt); await context.CallActivityAsync("SendEmail", email); // Wait for result with timeout var activityTask = context.WaitForExternalEvent("Approval"); var timeoutTask = context.CreateTimer(deadline); var winner = await Task.WhenAny(activityTask, timeoutTask); // Determine the outcome return winner == activityTask && activityTask.Result;

Slide 69

Slide 69 text

// Schedule an e-mail with link to approve/reject var sendAt = context.CurrentUtcDateTime.Date.Add(OneDay); await context.CreateTimer(sendAt); await context.CallActivityAsync("SendEmail", email); // Wait for result with timeout var activityTask = context.WaitForExternalEvent("Approval"); var timeoutTask = context.CreateTimer(deadline); var winner = await Task.WhenAny(activityTask, timeoutTask); // Determine the outcome return winner == activityTask && activityTask.Result;

Slide 70

Slide 70 text

// Schedule an e-mail with link to approve/reject var sendAt = context.CurrentUtcDateTime.Date.Add(OneDay); await context.CreateTimer(sendAt); await context.CallActivityAsync("SendEmail", email); // Wait for result with timeout var activityTask = context.WaitForExternalEvent("Approval"); var timeoutTask = context.CreateTimer(deadline); var winner = await Task.WhenAny(activityTask, timeoutTask); // Determine the outcome return winner == activityTask && activityTask.Result;

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

// activity.js module.exports = function(context) { return `Hello ${context.bindings.name}!`; }; // orchestrator.js const df = require("durable-functions"); module.exports = df.orchestrator(function*(context) { const output = []; output.push(yield context.df.callActivity("E1_SayHello", "Tokyo")); output.push(yield context.df.callActivity("E1_SayHello", "Seattle")); output.push(yield context.df.callActivity("E1_SayHello", "London")); return output; });

Slide 73

Slide 73 text

// activity.js module.exports = function(context) { return `Hello ${context.bindings.name}!`; }; // orchestrator.js const df = require("durable-functions"); module.exports = df.orchestrator(function*(context) { const output = []; output.push(yield context.df.callActivity("E1_SayHello", "Tokyo")); output.push(yield context.df.callActivity("E1_SayHello", "Seattle")); output.push(yield context.df.callActivity("E1_SayHello", "London")); return output; });

Slide 74

Slide 74 text

// Activity let sayHello = Activity.define "SayHello" (sprintf "Hello %s!") // Orchestrator let workflow = orchestrator { let! hello1 = Activity.call sayHello "Tokyo" let! hello2 = Activity.call sayHello "Seattle" let! hello3 = Activity.call sayHello "London" return [hello1; hello2; hello3] }

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

 Event-Driven  Managed Cloud Services  Rapid Development  Pay-as-you-Go

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

https://mikhail.io/2018/12/making-sense-of-azure-durable-functions/ https://aka.ms/durablefunctions https://github.com/Azure/azure-functions-durable-extension https://github.com/Azure/durabletask/tree/azure-functions

Slide 80

Slide 80 text

No content