We went from physical servers to the cloud and from running VMs in the cloud to running services in the cloud. And although the infrastructure got better and better, we still had to manage everything on our own. This is not the case anymore. Nowadays, we have the “serverless” services.
There are many implementations to the idea. The most famous are the AWS Lambda and the Azure Functions. They provide a robust infrastructure for running your code in a scalable manner in a cloud environment. And since the solution is scalable, it is, by definition, a stateless solution. Does this mean that serverless is not a good solution? Is it just a cool gimmick?
In this session, you are going to learn how we can manage state in a stateless, serverless environment on Azure, by utilizing Azure Durable Functions and how we can use the eco-system to build entire systems, completely serverless.
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
State in stateless serverless functions
1. @AlexPshul
State in Stateless Serverless Functions
Alex Pshul
Embrace the serverless
@AlexPshul
alex@pshul.com
https://pshul.com
https://meetup.com/Code-Digest
3. @AlexPshul
Agenda
Serverless Functions - Recap
Pros
Cons
Functions Demo
State in Stateless?
Durable Functions
Durable Entities
Another Demo!
3
Agenda
4. @AlexPshul
About Me
4
Alex Pshul
Architect, Microsoft Azure MVP, Consultant, Lecturer & Tech Freak
More than 10 years of hands-on experience
More than 30 projects
Co-organizer of the Code.Digest Meetup
https://www.meetup.com/Code-Digest/
Talk to me about:
8. @AlexPshul
Flexible
Run native on cloud
Or in a container
Rich out-of-the-box solutions suite
Http
Message Bus
Timer
Easy to start
Easy to deploy
8
9. @AlexPshul
But…
Latency
Constant high load
Premium functions (Azure)
Provisioned Concurrency (AWS)
Resource intensive computing
Stateful server requests
Long running tasks
State
9
13. @AlexPshul
What is it?
Azure Function Extension
Supports in a variety of languages
C#
JavaScript/TypeScript
Python
F#
PowerShell
Uses a storage account for persistency
Supports various scenarios
13
14. @AlexPshul
Function Chaining
14
const df = require("durable-functions");
module.exports = df.orchestrator(function*(context) {
try {
const x = yield context.df.callActivity("F1");
const y = yield context.df.callActivity("F2", x);
const z = yield context.df.callActivity("F3", y);
return yield context.df.callActivity("F4", z);
} catch (error) {
// Error handling or compensation goes here.
}
});
15. @AlexPshul
Fan Out - Fan In
15
import azure.durable_functions as df
def orchestrator_function(context: df.DurableOrchestrationContext):
# Get a list of N work items to process in parallel.
work_batch = yield context.call_activity("F1", None)
parallel_tasks = [ context.call_activity("F2", b) for b in work_batch
]
outputs = yield context.task_all(parallel_tasks)
# Aggregate all N outputs and send the result to F3.
total = sum(outputs)
yield context.call_activity("F3", total)
main = df.Orchestrator.create(orchestrator_function)
17. @AlexPshul
Durable Entities
17
Allows to store data “in memory”
Backed by Durable functions
C#
JavaScript/TypeScript
Python
Uses a storage account for persistency
Can be accessed from different functions
19. @AlexPshul
Summary
19
Serverless
Easy
Scalable
Supported by many languages
C#
JavaScript/TypeScript
Python
F# (No durable support)
PowerShell (No durable support)
State in stateless functions with Durable Functions
Functions on steroid