SlideShare a Scribd company logo
1 of 25
urable Functions
MATTI PETRELIUS
@mattipet
We’re hiring!
If interested go check out www.devisioona.fi
Fill out a form and we will be in contact with you!
Azure Functions
Orchestration
ff
f
f
ff
Handling state
Long-running Long-running
Answer:
urable Functions
WebJobs
as a Service
=
Azure Functions
Durable Task Framework
as a Service
=
Durable Functions
Coordination Patterns
• Function Chaining
• Fan-out, Fan-in
• Stateful Singleton
• Human Interaction
Function Chaining
F1 F2 F3 F4
[FunctionName("E1_HelloSequence")]
public static async Task<List<string>> Run(
[OrchestrationTrigger] DurableOrchestrationContext context) {
var outputs = new List<string>();
outputs.Add(await context.CallFunctionAsync<string>("E1_SayHello", "Tokyo"));
outputs.Add(await context.CallFunctionAsync<string>("E1_SayHello",
"Seattle"));
outputs.Add(await context.CallFunctionAsync<string>("E1_SayHello", "London"));
// returns ["Hello Tokyo!", "Hello Seattle!", "Hello London!"]
return outputs;
}
[FunctionName("E1_SayHello")]
public static string SayHello(
[ActivityTrigger] string name) {
return $"Hello {name}!";
}
Event Sourcing
• Does not simply persist the current state
• Uses an append-only store to record the full series of actions
• Kind of like Redux
Presentation
Cart created
Item 1 added
Item 2 added
Item 1 removed
Shipping information added
Event Store
Materialized View
External
systems
Cart ID
Date
Items
Query state
of entity
Replay events
Publish events
Benefits of Event Sourcing
• Performance
• Scalability
• Responsiveness
• Consistency for transactional data
• Full audit trails/history
Orchestrator
Function
Durable Task
Framework
await CallFunctionAsync(...)
Execution History
append action
Message Queue
schedule function call
receive result
re-execute from start
unload from memory
await CallFunctionAsync(...)
check if executed
return result from history
immediately return result
add result
Orchestration code constraints
• Must be deterministic
• Non-blocking
• Only async operations in DurableOrchestrationContext
• No other input/output bindings
• Infinite loops should be avoided
Apply only to orchestration functions and not activity functions!
Fan-out, Fan-in
F1
F2
F3
[FunctionName("E2_BackupSiteContent")]
public static async Task<long> Run(
[OrchestrationTrigger] DurableOrchestrationContext backupContext) {
string rootDirectory = backupContext.GetInput<string>()?.Trim();
if (string.IsNullOrEmpty(rootDirectory)) {
rootDirectory = Environment.CurrentDirectory;
}
string[] files = await backupContext.CallFunctionAsync<string[]>(
"E2_GetFileList",
rootDirectory);
var tasks = new Task<long>[files.Length];
for (int i = 0; i < files.Length; i++) {
tasks[i] = backupContext.CallFunctionAsync<long>("E2_CopyFileToBlob",
files[i]);
}
await Task.WhenAll(tasks);
long totalBytes = tasks.Sum(t => t.Result);
return totalBytes;
}
Stateful Singleton
[FunctionName("E3_Counter")]
public static async Task<int> Run(
[OrchestrationTrigger] DurableOrchestrationContext counterContext) {
int counterState = counterContext.GetInput<int>();
string operation = await counterContext.WaitForExternalEvent<string>("operation");
operation = operation?.ToLowerInvariant();
if (operation == "incr") {
counterState++;
} else if (operation == "decr") {
counterState--;
}
if (operation != "end") {
counterContext.ContinueAsNew(counterState);
}
return counterState;
}
Human Interaction
Request Two-factor
authentication
!
Authenticate
Time-out
DEMO
... so what’s the catch?
• Very early alpha
• Only C#
• Full VS2017 required
Thank you!

More Related Content

What's hot

c++ Lecture 2
c++ Lecture 2c++ Lecture 2
c++ Lecture 2
sajidpk92
 

What's hot (20)

Python unittest
Python unittestPython unittest
Python unittest
 
The Ring programming language version 1.10 book - Part 35 of 212
The Ring programming language version 1.10 book - Part 35 of 212The Ring programming language version 1.10 book - Part 35 of 212
The Ring programming language version 1.10 book - Part 35 of 212
 
Introducing to Asynchronous Programming
Introducing to Asynchronous  ProgrammingIntroducing to Asynchronous  Programming
Introducing to Asynchronous Programming
 
Async Microservices with Twitter's Finagle
Async Microservices with Twitter's FinagleAsync Microservices with Twitter's Finagle
Async Microservices with Twitter's Finagle
 
Меняем javascript с помощью javascript
Меняем javascript с помощью javascriptМеняем javascript с помощью javascript
Меняем javascript с помощью javascript
 
Linked list : Doubly Linked List
Linked list : Doubly Linked ListLinked list : Doubly Linked List
Linked list : Doubly Linked List
 
The Ring programming language version 1.7 book - Part 30 of 196
The Ring programming language version 1.7 book - Part 30 of 196The Ring programming language version 1.7 book - Part 30 of 196
The Ring programming language version 1.7 book - Part 30 of 196
 
MUST CS101 Lab11
MUST CS101 Lab11 MUST CS101 Lab11
MUST CS101 Lab11
 
The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.2 book - Part 26 of 181The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.2 book - Part 26 of 181
 
The Ring programming language version 1.2 book - Part 16 of 84
The Ring programming language version 1.2 book - Part 16 of 84The Ring programming language version 1.2 book - Part 16 of 84
The Ring programming language version 1.2 book - Part 16 of 84
 
Sharding and Load Balancing in Scala - Twitter's Finagle
Sharding and Load Balancing in Scala - Twitter's FinagleSharding and Load Balancing in Scala - Twitter's Finagle
Sharding and Load Balancing in Scala - Twitter's Finagle
 
All you need to know about Callbacks, Promises, Generators
All you need to know about Callbacks, Promises, GeneratorsAll you need to know about Callbacks, Promises, Generators
All you need to know about Callbacks, Promises, Generators
 
Java practice programs for beginners
Java practice programs for beginnersJava practice programs for beginners
Java practice programs for beginners
 
Infinum Android Talks #16 - Retrofit 2 by Kristijan Jurkovic
Infinum Android Talks #16 - Retrofit 2 by Kristijan JurkovicInfinum Android Talks #16 - Retrofit 2 by Kristijan Jurkovic
Infinum Android Talks #16 - Retrofit 2 by Kristijan Jurkovic
 
Using OTP and gen_server Effectively
Using OTP and gen_server EffectivelyUsing OTP and gen_server Effectively
Using OTP and gen_server Effectively
 
Request process
Request processRequest process
Request process
 
c++ Lecture 2
c++ Lecture 2c++ Lecture 2
c++ Lecture 2
 
Retrofit 2 - O que devemos saber
Retrofit 2 - O que devemos saberRetrofit 2 - O que devemos saber
Retrofit 2 - O que devemos saber
 
The Ring programming language version 1.8 book - Part 88 of 202
The Ring programming language version 1.8 book - Part 88 of 202The Ring programming language version 1.8 book - Part 88 of 202
The Ring programming language version 1.8 book - Part 88 of 202
 
Using Grafana with InfluxDB 2.0 and Flux Lang by Jacob Lisi
Using Grafana with InfluxDB 2.0 and Flux Lang by Jacob LisiUsing Grafana with InfluxDB 2.0 and Flux Lang by Jacob Lisi
Using Grafana with InfluxDB 2.0 and Flux Lang by Jacob Lisi
 

Similar to Durable Functions

Concurrency and Thread-Safe Data Processing in Background Tasks
Concurrency and Thread-Safe Data Processing in Background TasksConcurrency and Thread-Safe Data Processing in Background Tasks
Concurrency and Thread-Safe Data Processing in Background Tasks
WO Community
 
Orsiso
OrsisoOrsiso
Orsiso
e27
 

Similar to Durable Functions (20)

Azure Durable Functions (2019-04-27)
Azure Durable Functions (2019-04-27)Azure Durable Functions (2019-04-27)
Azure Durable Functions (2019-04-27)
 
Durable functions
Durable functionsDurable functions
Durable functions
 
Azure Durable Functions (2019-03-30)
Azure Durable Functions (2019-03-30) Azure Durable Functions (2019-03-30)
Azure Durable Functions (2019-03-30)
 
Integration-Monday-Stateful-Programming-Models-Serverless-Functions
Integration-Monday-Stateful-Programming-Models-Serverless-FunctionsIntegration-Monday-Stateful-Programming-Models-Serverless-Functions
Integration-Monday-Stateful-Programming-Models-Serverless-Functions
 
[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless
 
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
 
Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)
 
Concurrency and Thread-Safe Data Processing in Background Tasks
Concurrency and Thread-Safe Data Processing in Background TasksConcurrency and Thread-Safe Data Processing in Background Tasks
Concurrency and Thread-Safe Data Processing in Background Tasks
 
Threads, Queues, and More: Async Programming in iOS
Threads, Queues, and More: Async Programming in iOSThreads, Queues, and More: Async Programming in iOS
Threads, Queues, and More: Async Programming in iOS
 
NDC Sydney 2019 - Async Demystified -- Karel Zikmund
NDC Sydney 2019 - Async Demystified -- Karel ZikmundNDC Sydney 2019 - Async Demystified -- Karel Zikmund
NDC Sydney 2019 - Async Demystified -- Karel Zikmund
 
.NET Core Summer event 2019 in Brno, CZ - Async demystified -- Karel Zikmund
.NET Core Summer event 2019 in Brno, CZ - Async demystified -- Karel Zikmund.NET Core Summer event 2019 in Brno, CZ - Async demystified -- Karel Zikmund
.NET Core Summer event 2019 in Brno, CZ - Async demystified -- Karel Zikmund
 
Workflow as code with Azure Durable Functions
Workflow as code with Azure Durable FunctionsWorkflow as code with Azure Durable Functions
Workflow as code with Azure Durable Functions
 
Time for Functions
Time for FunctionsTime for Functions
Time for Functions
 
RxJava on Android
RxJava on AndroidRxJava on Android
RxJava on Android
 
Dallas Scala Meetup
Dallas Scala MeetupDallas Scala Meetup
Dallas Scala Meetup
 
State in stateless serverless functions
State in stateless serverless functionsState in stateless serverless functions
State in stateless serverless functions
 
State in stateless serverless functions - Alex Pshul
State in stateless serverless functions - Alex PshulState in stateless serverless functions - Alex Pshul
State in stateless serverless functions - Alex Pshul
 
Advanced patterns in asynchronous programming
Advanced patterns in asynchronous programmingAdvanced patterns in asynchronous programming
Advanced patterns in asynchronous programming
 
Orsiso
OrsisoOrsiso
Orsiso
 
Modern C++ Concurrency API
Modern C++ Concurrency APIModern C++ Concurrency API
Modern C++ Concurrency API
 

Recently uploaded

Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac Folorunso
Kayode Fayemi
 
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
raffaeleoman
 
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
Sheetaleventcompany
 

Recently uploaded (20)

BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
 
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxMohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
 
My Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle BaileyMy Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle Bailey
 
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
 
ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docxANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
 
Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)
 
Dreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio IIIDreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio III
 
ICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdfICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdf
 
lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.
 
Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510
 
Dreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video TreatmentDreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video Treatment
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac Folorunso
 
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesVVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
 
SaaStr Workshop Wednesday w/ Lucas Price, Yardstick
SaaStr Workshop Wednesday w/ Lucas Price, YardstickSaaStr Workshop Wednesday w/ Lucas Price, Yardstick
SaaStr Workshop Wednesday w/ Lucas Price, Yardstick
 
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
 
Report Writing Webinar Training
Report Writing Webinar TrainingReport Writing Webinar Training
Report Writing Webinar Training
 
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdfAWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
 
Presentation on Engagement in Book Clubs
Presentation on Engagement in Book ClubsPresentation on Engagement in Book Clubs
Presentation on Engagement in Book Clubs
 
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdfThe workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
 
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
 

Durable Functions

Editor's Notes

  1. Hello everyone, my name is Matti Petrelius I’m going to be talking about Durable Functions that is a new extension to Azure Functions
  2. I work for a company called Devisioona and we are in fact hiring We do a lot of different kind of software projects from Integration and IoT to web and mobile applications Most of our projects have something to do with Azure We are looking for good people, talented coders and other IT-professionals If you’re interest you should go check out our website at www.devisioona.fi and fill out a form and we will be in contact with you!
  3. Durable Functions is something new in the Azure Serverless offering and fits it really well Serverless is a terrible name, but it is an awesome technology Serverless allows you to only pay for what you use in the cloud And it does all the boring boilerplate stuff for you and let’s you concentrate on the code that is valuable to your business
  4. What Azure Functions is is probably best described as Azure’s offering of Functions as a Service Allows you to run independent function sized event-based pieces of code if the cloud without having to deal with the infrastructure Similar to AWS Lambda or Google Cloud Functions One of the most exciting new services on Azure Announced at Build 2016 and has been continuosly evolving ever since
  5. Azure Functions and serverless in general are great technologies but they are not without some problems If you have ever used Azure Functions in real-life scenarios you have probably run into situations that are difficult to implement with the current tooling
  6. First if you run just a single independent function everything is simple But when you have multiple functions that are somehow dependent on each other thing start to get complicated Going from a single monolith application to small function size nanoservices means there’s a lot more stuff to take care of This requires orchestration and coordination It is possible to handle this with traditional functions but it requires a lot of work
  7. Also state and handling it is difficult with just regular Azure Functions First of all normal Azure Functions are stateless If you want to share state with other functions you have to persist it somewhere If there are errors or the VM is shutdown for some reason the state can be lost and you may have to restart the whole process
  8. Last but not least having long running functions is difficult if not impossible at the moment The time limit for Azure Functions was increased from 5 minutes to 10 minutes but still you cannot have a regular function running longer than that Also having long running functions kind of conflicts with the idea of functions being event based and only running when needed And if an exception occurs or the function gets shut down it might be difficult to know what the state was when it was stopped
  9. And the answer to these problems is of course Durable Functions It literally describes itself as a long-running stateful orchestration What is important to understand about Durable Functions is that They don’t magically make regular functions long-running and stateful Regular functions are called activity functions in Durable Functions land and have the limitations of being stateless and 10 minute running time But what is different is that Durable Functions introduce orchestrator functions that do not have these limitations The way you manage these orchestrations in Durable Functions is by writing C# code, no graphical UI or magical JSON files are needed What the orchestrations for example can do is to call other functions asynchronously or synchronously and saving their output to local variables
  10. And in the same way that Azure Functions is basically WebJobs as a Service, Durable Functions is actually Durable Task Framework as a Service So Durable Task Framework is what allows writing long running persistent workflows in C# using the async/await capabilities It is heavily used at Microsoft and other companies to automate mission-critical processes And it’s a really good fit for the serverless Azure Functions environment
  11. The primary use case for Durable Functions is simplifying complex, stateful coordination problems in serverless application Here are some of the most common coordination patterns You could implement at least some of these with regular Azure Functions but Durable Functions makes it a lot more less painful During this talk I will go through all of these four patterns and highlight all the interesting parts
  12. Let’s start of with Function Chaining It is a very simple pattern where we execute functions in a sequence so that usually the output of the previous function is used as the input of the next function Finally the output from the last function is returned from the orchestration as an output You could implement this pattern with just regular Azure Functions but Durable Functions makes it very easy
  13. Here we have all the code needed for a simple Function Chaining pattern There are two functions and the first one is an orchestrator function and the second one is an activity function First I would like to point out that the orchestrator function gets an orchestration trigger and activity function gets an activity trigger These are new trigger types introduced by the Durable Functions Also the terms orchestrator function and activity function are important in Durable Functions, Orchestrator functions do the orchestration and activity functions are functions that the orchestrator function can call, I will be using these terms a lot during this talk so I want to make sure they are clear The next thing to notice is this await ctx.CallFunctionAsync call here, There is actually quite a lot going on here First it calls the activity function named E1_SayHello but it also checkpoints the state of the orchestration function because in an orchestration function each time an external resource is awaited the current state is persisted And the way that these checkpoints are made is with a pattern called Event Sourcing
  14. Some of you might not be that familiar with event sourcing pattern so we should probably go through a little bit about what it means Instead of simply persisting all of the current state with a CRUD-style pattern we have a append-only store that we send a series of actions to These actions describe that changes made to the state and can be replayed to get back the current state If you are familiar with front-end web development then you might be familiar with Redux which is not too far from event sourcing pattern
  15. Here’s a simple example of a shopping cart implemented with the Event Sourcing Pattern First the presentation layer send actions to the event store that describe how what the user does is changing the state of the cart The cart is created, two items are added, one items is removed and then some shipping information is added These actions are persisted in the event store but they are also published so that materialized views can be made of them for the presentation layer to use Also external systems and applications can subscribe to get the published events And what you can also do is to simply replay the events in the event store to get the current state
  16. There are some clear benefits of using Event Sourcing First of all performance is better than in traditional CRUD because you don’t have to directly access the data store It is more scalable because dealing with concurrent updates is easier Applications are more responsive because the entire state is not always dumped and events are handled in the background Consistency is also easier to achieve because of the publishing of the events And the event store can also work as a log of everything that has been done with the data
  17. Let’s look at what happens in Durable Functions when an orchestrator function calls an activity function First orchestrator function calls CallFunctionAsync and yields control to the Durable Task Framework Dispatcher Durable Task Framework then makes a commit which means the action is appended to the execution history and the actual task of calling the activity function is added to queue After that the orchestrator function can be unloaded from memory Then when the result from the activity function is received the result is added to the execution history and the orchestrator function will be re-executed from start So the CallFunctionAsync method is called again but this time the Durable Task Framework will check if the function has already executed And since it has been, the result can be immediately returned and replayed by the orchestration function I think this whole automatic checkpointing is an awesome feature and makes using Azure Functions a lot more reliable
  18. Because of this use of the event sourcing pattern and replaying of the functions there are limitations to what you can do in orchestrator functions First of all orchestrator code must be deterministic because the values have to be the same on each replay This means there cannot be calls to get the current date or time, generating random numbers or ids or calling remote endpoints Because the orchestration code runs on a single thread there should be no blocking code like for example using Thread.Sleep You cannot also call other async operations than the ones exposed by the DurableOrchestrationContext because they might schedule other threads the orchestration thread cannot interact with And for the same reason orchestrator functions should never have other input or output bindings than the orchestrator trigger Because Durable Task Framework saves the execution history as the orchestration function progresses infinite loops should be avoided or they might run out of memory These limitations only apply to orchestration functions and you can do all the aforementioned stuff in activity functions and as a matter of a fact that is exactly what you should do
  19. Next I would like us to take a look at a bit more interesting pattern called Fan-out, Fan-in Let’s imagine we are building a backup task for all files in a given folder Files will be uploaded recursively to blob storage and the total number of bytes uploaded is counted during the process A naive way to implement this would be to write a single function to take care of everything but the main problem with that would be scalability A single function can only run in a single VM so you are limited to the throughput of that single VM The other problem is that if there is a failure midway or the exection lasts longer than 10 minutes the backup will fail in partial state and the whole process has to be restarted A better approach would be to write two functions: One which enumerates the files and adds the filenames to a queue and one that reads from the queue and uploads the files to storage This would introduce a lot more complexity especially in the part where you want to provide the total amount of bytes uploaded, which would be the fanning back in part Durable Functions makes implementing this relatively easy
  20. Here is just the orchestrator function part of our backup example, The activity functions are not reallly interesting so I left them out Here is the code that does the fanning out by calling CallFunctionAsync to get a task for each file Then the fanning back in is achieved simply by calling Task.WhenAll on all the tasks which makes the code wait until all the tasks are done After that the total number of bytes is calculated from the sum of the results of the tasks Also what happens behind the covers is that checkpoints are created for each upload so that it is easy to resume the backup in case of for example network failure This is a really powerful pattern and easy to implement with Durable Functions
  21. Next I would like us to take a look at a very different kind of pattern, the Stateful Singleton Most orchestrator functions have an explicit start and end and don’t directly interact with external event sources but Stateful Singleton is different Stateful Singletons are also know as lightweight actors and though Durable Functions is not a proper implementation of the Actor Model but it has some of the same characteristics Orchestrator functions are long-running, stateful, reliable, single-threaded, location transparent and globally addressable This allows orchestrator functions to be used in actor-like situations
  22. Here is all the code for a Stateful Singleton that acts as a counter The function listens to an external event and then either increments or decrements the value in it’s state After handling an event the function will continue waiting for new events until it is being given the end event Here where we call the WaitForExternalEvent method, the actual waiting for the event is done And here is the line that makes this orchestration long-running, because calling ContinueAsNew method makes it continue from the beginning What the ContinueAsNew also does is that it resets the execution history to make sure the orchestration process will not run out of memory as the execution progresses
  23. The last pattern I would like us to look at is the Human Interaction pattern Often in processes we need some kind of human envolvement What is tricky about humans is that they are a not always responsive or available This requires implementing timeouts and and other strategies And this time instead of just showing you the code I would like to actually show you a locally running two-factor authentication demo made with Durable Functions
  24. By now hopefully if I’ve been at all successful atleast some of you are excited about Durable Functions and are anxious to get to test it yourselves I have to give you a couple of words of caution though First of all Durable Functions is still in a very early preview, what it means that stuff will change rapidly and if you are going to use this in production then stuff will break Also right now and for the fore-seeable future orchestrator functions can only be written in C#, activity functions can be written in any language but return values only work in C# And lastly you need the full Visual Studio 2017 with the Azure Functions tooling to be able to run Durable Functions locally So you cannot run these locally with a Mac yet But if these things wont scare you then I suggest you go check out Durable Functions as soon as possible and test them out yourselves The documentation is actually quite good for an alpha release and there are downloadable examples of the different patterns and good installation notes for getting started
  25. So that’s all for me, thank you for listening! If you have questions go ahead and ask them or if were running out of time you can come see me afterwards I will be hanging out here for a while Thanks!