SlideShare a Scribd company logo
Azure Nights Melbourne
Paco de la Cruz
Durable Functions
Serverless and Stateful Orchestrations
on Azure
Azure Nights Melbourne
Azure Nights Melbourne
@pacodelacruz
slideshare.net/pacodelac
pacodelacruzag.wordpress.com
Azure Nights Melbourne
Agenda
Azure Nights Melbourne
Evolution of Application Platforms
On-premises IaaS PaaS Serverless
Azure Nights Melbourne
“Serverless” and its benefits
Event-driven scaling
not resource-driven
Pay only for what
you use
Server abstraction
Focus on value
Azure Nights Melbourne
Azure Functions in a nutshell
Event Triggers Code Outputs
React and get inputs from
a growing list of services
(triggers and input
bindings)
C#, F#,
node.js, Java,
Phyton
Send results to a
growing list of services
(output bindings)
Azure Nights Melbourne
Some challenges of Azure Functions
Manageable Sequencing
+ Error Handling / Compensation
Fanning-out & Fanning-in Http-based
Async Long-running APIs
Human InteractionFlexible Automated Long-running
Process Monitoring
External Events Correlation
Start
Get Status
Azure Nights Melbourne
Durable Function Patterns
1: Function Chaining 2: Fanning-out & Fanning-in 3: Async HTTP APIs
5: Human Interaction4: Monitoring ?: External Events Correlation
Start
Get Status
Azure Nights Melbourne
Durable Functions in a nutshell
Based on
Durable Task Framework
Using Azure Storage
(Fully Managed and Abstracted)
To Implement stateful
workflows-as-code
(C#, F# and Node.js in
preview)
Azure Functions
Extension
Azure Nights Melbourne
Durable Functions Components
Activity Function Activity Function Activity Function
Orchestrator Function
Orchestration Client
Start
Get Status
Send Event
Wait for Completion
Terminate
Stateless
Single Step
Inputs and Outputs
Stateful
Process Manager
Call Activity Functions
Error Handling and Compensation
Checkpointing
Dehydrates during activities
Rehydrates at responses / events
Azure Nights Melbourne
Function Chaining Pattern
public static async Task<object> Run(
[OrchestrationTrigger] DurableOrchestrationContext ctx)
{
try
{
var x = await ctx.CallActivityAsync<object>("F1");
var y = await ctx.CallActivityAsync<object>("F2", x);
return await ctx.CallActivityAsync<object>("F3", y);
}
catch (Exception ex)
{
// error handling / compensation
}
}
Azure Nights Melbourne
Fan-out & Fan-In Pattern
public static async Task<int> Run(
[OrchestrationTrigger] DurableOrchestrationContext ctx)
{
object[] workBatch = await ctx.CallActivityAsync<object[]>("F1");
var tasks = new Task<long>[workBatch.Length];
for (int i = 0; i < workBatch.Length; i++)
{
tasks[i] = ctx.CallActivityAsync<int>("F2", workBatch[i]);
}
await Task.WhenAll(tasks);
long sum = tasks.Sum(t => t.Result);
return sum;
}
Azure Nights Melbourne
Orchestration Client
public static async Task<HttpResponseMessage> Run(
[HttpTrigger(AuthorizationLevel.Function, methods: "post",
Route = "orchestrators/{functionName}")] HttpRequestMessage req,
[OrchestrationClient] DurableOrchestrationClientBase starter, ILogger log)
{
// Function input comes from the request content.
dynamic eventData = await req.Content.ReadAsAsync<object>();
string instanceId = await starter.StartNewAsync("myOrchestrator", eventData);
log.LogInformation($"Started orchestration with ID = '{instanceId}'.");
var res = starter.CreateCheckStatusResponse(req, instanceId);
return res;
}
Azure Nights Melbourne
Durable Functions vs Logic Apps?
vs
Durable Functions Logic Apps
Both allow implementing advanced workflow patterns
C#, F# and JavaScript in preview Visual designer and WDL
Bindings (~ 20 supported) 200+ connectors
Portable Runtime Run only on Azure
Monitoring based on App Insights & APIs Rich monitoring & management tools
Serverless, dedicated and isolated Serverless only
(dedicated in the future [ISE])
blog.mexia.com.au/azure-durable-functions-vs-logic-apps
Azure Nights Melbourne
Additional Resources
Twitter @azurefunctions
Documentation aka.ms/durablefunctions
Live Web Cast aka.ms/azurefunctionslive
Repos github.com/Azure/azure-functions-durable-extension
github.com/Azure/azure-functions-durable-js
Samples github.com/Azure/azure-functions-durable-
extension/tree/master/samples
Pluralsight course app.pluralsight.com/library/courses/
azure-durable-functions-fundamentals
Azure Nights Melbourne
Any questions so far?
Azure Nights Melbourne
Demo 1
Development and Debugging
Furry Models
Cat Application Approval
github.com/pacodelacruz/
DurableFunctions-AzureNights
Azure Nights Melbourne
Orchestration
Function
Start
Send Approval
Request via Email
Create Timer
External
Event
Timer
Expires
WhenAny
Move Blob to
Corresponding Container
End
(Requests
blob container)
(Approved or Rejected
blob container)
Azure Nights Melbourne
Orchestration
Function
Start
Send Approval
Request via Email
Create Timer
External
Event
Timer
Expires
WhenAny
Move Blob to
Corresponding Container
End
BlobTrigger
Function
HttpTrigger
Process Approval
(Requests
blob container)
(Approved or Rejected
blob container)
Orchestration Client Activity Functions
ActivityTrigger
Send Approval
Request via Email
ActivityTrigger
Move Blob to
Corresponding Container
HttpTrigger
Check Status
Azure Nights Melbourne
Demo 2
Execution & Monitoring on Azure
github.com/pacodelacruz/
DurableFunctions-AzureNights
Azure Nights Melbourne
Orchestration
Function
Start
Send Approval
Request via Slack
Create Timer
External
Event
Timer
Expires
WhenAny
Move Blob to
Corresponding Container
End
BlobTrigger
Function
HttpTrigger
Process Approval
(Requests
blob container)
(Approved or Rejected
blob container)
Orchestration Client Activity Functions
ActivityTrigger
Send Approval
Request via Slack
ActivityTrigger
Move Blob to
Corresponding Container
HttpTrigger
Check Status
Azure Nights Melbourne
Let your Cat apply!
Great opportunity to get famous!
Send an email to: …
Subject: I want to be a Furry Model!
Attach your cat best picture
Azure Nights Melbourne
Details about the demos:
blog.mexia.com.au/azure-durable-functions-approval-workflow-with-sendgrid
blog.mexia.com.au/azure-durable-functions-approval-workflow-with-slack
github.com/pacodelacruz/
DurableFunctions-AzureNights
Azure Nights Melbourne
Q & A
Azure Nights Melbourne
@pacodelacruz
slideshare.net/pacodelac
pacodelacruzag.wordpress.com
Azure Nights Melbourne
Thanks!

More Related Content

Azure Durable Functions (2018-06-13)

  • 1. Azure Nights Melbourne Paco de la Cruz Durable Functions Serverless and Stateful Orchestrations on Azure Azure Nights Melbourne
  • 4. Azure Nights Melbourne Evolution of Application Platforms On-premises IaaS PaaS Serverless
  • 5. Azure Nights Melbourne “Serverless” and its benefits Event-driven scaling not resource-driven Pay only for what you use Server abstraction Focus on value
  • 6. Azure Nights Melbourne Azure Functions in a nutshell Event Triggers Code Outputs React and get inputs from a growing list of services (triggers and input bindings) C#, F#, node.js, Java, Phyton Send results to a growing list of services (output bindings)
  • 7. Azure Nights Melbourne Some challenges of Azure Functions Manageable Sequencing + Error Handling / Compensation Fanning-out & Fanning-in Http-based Async Long-running APIs Human InteractionFlexible Automated Long-running Process Monitoring External Events Correlation Start Get Status
  • 8. Azure Nights Melbourne Durable Function Patterns 1: Function Chaining 2: Fanning-out & Fanning-in 3: Async HTTP APIs 5: Human Interaction4: Monitoring ?: External Events Correlation Start Get Status
  • 9. Azure Nights Melbourne Durable Functions in a nutshell Based on Durable Task Framework Using Azure Storage (Fully Managed and Abstracted) To Implement stateful workflows-as-code (C#, F# and Node.js in preview) Azure Functions Extension
  • 10. Azure Nights Melbourne Durable Functions Components Activity Function Activity Function Activity Function Orchestrator Function Orchestration Client Start Get Status Send Event Wait for Completion Terminate Stateless Single Step Inputs and Outputs Stateful Process Manager Call Activity Functions Error Handling and Compensation Checkpointing Dehydrates during activities Rehydrates at responses / events
  • 11. Azure Nights Melbourne Function Chaining Pattern public static async Task<object> Run( [OrchestrationTrigger] DurableOrchestrationContext ctx) { try { var x = await ctx.CallActivityAsync<object>("F1"); var y = await ctx.CallActivityAsync<object>("F2", x); return await ctx.CallActivityAsync<object>("F3", y); } catch (Exception ex) { // error handling / compensation } }
  • 12. Azure Nights Melbourne Fan-out & Fan-In Pattern public static async Task<int> Run( [OrchestrationTrigger] DurableOrchestrationContext ctx) { object[] workBatch = await ctx.CallActivityAsync<object[]>("F1"); var tasks = new Task<long>[workBatch.Length]; for (int i = 0; i < workBatch.Length; i++) { tasks[i] = ctx.CallActivityAsync<int>("F2", workBatch[i]); } await Task.WhenAll(tasks); long sum = tasks.Sum(t => t.Result); return sum; }
  • 13. Azure Nights Melbourne Orchestration Client public static async Task<HttpResponseMessage> Run( [HttpTrigger(AuthorizationLevel.Function, methods: "post", Route = "orchestrators/{functionName}")] HttpRequestMessage req, [OrchestrationClient] DurableOrchestrationClientBase starter, ILogger log) { // Function input comes from the request content. dynamic eventData = await req.Content.ReadAsAsync<object>(); string instanceId = await starter.StartNewAsync("myOrchestrator", eventData); log.LogInformation($"Started orchestration with ID = '{instanceId}'."); var res = starter.CreateCheckStatusResponse(req, instanceId); return res; }
  • 14. Azure Nights Melbourne Durable Functions vs Logic Apps? vs Durable Functions Logic Apps Both allow implementing advanced workflow patterns C#, F# and JavaScript in preview Visual designer and WDL Bindings (~ 20 supported) 200+ connectors Portable Runtime Run only on Azure Monitoring based on App Insights & APIs Rich monitoring & management tools Serverless, dedicated and isolated Serverless only (dedicated in the future [ISE]) blog.mexia.com.au/azure-durable-functions-vs-logic-apps
  • 15. Azure Nights Melbourne Additional Resources Twitter @azurefunctions Documentation aka.ms/durablefunctions Live Web Cast aka.ms/azurefunctionslive Repos github.com/Azure/azure-functions-durable-extension github.com/Azure/azure-functions-durable-js Samples github.com/Azure/azure-functions-durable- extension/tree/master/samples Pluralsight course app.pluralsight.com/library/courses/ azure-durable-functions-fundamentals
  • 16. Azure Nights Melbourne Any questions so far?
  • 17. Azure Nights Melbourne Demo 1 Development and Debugging Furry Models Cat Application Approval github.com/pacodelacruz/ DurableFunctions-AzureNights
  • 18. Azure Nights Melbourne Orchestration Function Start Send Approval Request via Email Create Timer External Event Timer Expires WhenAny Move Blob to Corresponding Container End (Requests blob container) (Approved or Rejected blob container)
  • 19. Azure Nights Melbourne Orchestration Function Start Send Approval Request via Email Create Timer External Event Timer Expires WhenAny Move Blob to Corresponding Container End BlobTrigger Function HttpTrigger Process Approval (Requests blob container) (Approved or Rejected blob container) Orchestration Client Activity Functions ActivityTrigger Send Approval Request via Email ActivityTrigger Move Blob to Corresponding Container HttpTrigger Check Status
  • 20. Azure Nights Melbourne Demo 2 Execution & Monitoring on Azure github.com/pacodelacruz/ DurableFunctions-AzureNights
  • 21. Azure Nights Melbourne Orchestration Function Start Send Approval Request via Slack Create Timer External Event Timer Expires WhenAny Move Blob to Corresponding Container End BlobTrigger Function HttpTrigger Process Approval (Requests blob container) (Approved or Rejected blob container) Orchestration Client Activity Functions ActivityTrigger Send Approval Request via Slack ActivityTrigger Move Blob to Corresponding Container HttpTrigger Check Status
  • 22. Azure Nights Melbourne Let your Cat apply! Great opportunity to get famous! Send an email to: … Subject: I want to be a Furry Model! Attach your cat best picture
  • 23. Azure Nights Melbourne Details about the demos: blog.mexia.com.au/azure-durable-functions-approval-workflow-with-sendgrid blog.mexia.com.au/azure-durable-functions-approval-workflow-with-slack github.com/pacodelacruz/ DurableFunctions-AzureNights