Azure Functions Real World Examples
Yochay Kiriaty
Oct 2nd 2016
Yochay KiriatyPrincipal Program Manager @ MicrosoftAzure / App Service Tech Evangelist Various Start Ups
https://blogs.msdn.microsoft.com/appserviceteam@[email protected]
Agenda• Why Serverless?• What is serverless? • Intro Azure Functions• Serverless patterns / Real-world examples
Before cloud
On-PremiseCo-Lo
Before cloud
How many servers do I need?
Which OS should I use?
How often should I patch my servers?
What size of servers
should I buy?
How often should I backup
my server?
How can I increase server utilization?
How I deploy new code to my server?
Which packages should be on my server?
It takes how long to provision a new server?
Are my server in a
secure location?
What happens if
the
power goes out?Do I n
eed secondary
network connection?
What is th
e right si
ze of
servers for m
y business n
eeds?
Who has physical
access to my servers?
Do I need a UPS?
What media should I
use to keep backup?
What storage I need to use?
How I scale my app?
What happens in case of
server hardware failure?
How can I d
ynamically
configure my app?
Who monitors
my Servers?Who monitors
my App?
Then came IaaS …
How many servers do I need?
Which OS should I use?
How often should I patch my servers?
What size of servers
should I buy?
How often should I backup
my server?
How can I increase server utilization?
How I deploy new code to my server?
Which packages should be on my server?
It takes how long to provision a new server?
Are my server in a
secure location?
What happens if
the
power goes out?Do I n
eed secondary
network connection?
What is th
e right si
ze of
servers for m
y business n
eeds?
Who has physical
access to my servers?
Do I need a UPS?
What media should I
use to keep backup?
What storage I need to use?
How I scale my app?
What happens in case of
server hardware failure?
How can I d
ynamically
configure my app?
Who monitors
my Servers?Who monitors
my App?
Is it PaaS time?
How many servers do I need?
Which OS should I use?
How often should I patch my servers?
How often should I backup
my server?
How can I increase server utilization?
How I deploy new code to my server?
Which packages should be on my server?
What is th
e right si
ze of
servers for m
y business n
eeds?
How I scale my app?
How can I d
ynamically
configure my app?
Who monitors
my App?
Is it PaaS time?
How many servers do I need?
Which OS should I use?
How often should I patch my servers?
How often should I backup
my server?
How can I increase server utilization?
How I deploy new code to my server?
Which packages should be on my server?
What is th
e right si
ze of
servers for m
y business n
eeds?
How I scale my app?
How can I d
ynamically
configure my app?
Who monitors
my App?
Serverless . . .
How many servers do I need?
How can I increase server utilization?What is
the rig
ht size of
servers for m
y business n
eeds?
How I scale my app?
Event-driven/ instant scale
Sub-second billing
Abstraction of
servers
What is Serverless?
Focus on Business
LogicReduced Time To Market
Reduced DevOps
Benefits of Serverless?
Application’s evolution
Ship.
Acct. Mang.
Hist.
Database
Client
Ship.
DB
Client
Hist.
DB
Mang.
DB
Acct.
DB
POST
GET
POST
UPDATE
Monolithic Microservices
Application’s evolution
Ship.
Acct. Mang.
Hist.
Database
Client
Monolithic
Ship.
DB
Client
Hist.
DB
Mang.
DB
Acct.
DB
POST
GET
POST
UPDATE
Microservices
Application’s evolution
Ship.
DB
Client
Hist.
DB
Mang.
DB
Acct.
DB
POST
GET
POST
UPDATE
Microservices
Application’s evolution
Client Mang.
DB
Microservices
POST Users
Users/Id
Users/Id
Users/Id
CreatUser
GetUser
UpdateUser
DeleteUser
GET
UPDATE
DELETE
Serverless
Microsoft Serverless
App ServiceCortana Management Suite
Media ServicesLogic AppFunctionsStorage
Traffic Manager
Visual StudioServices
OMS Management SuitMachine LearningCDNDocument DB
Search
Scheduler
Active Directory Key Vault App Insights Cognitive Services Embedded Power BI
Hockey AppStream AnalyticsNotification HubIoT Hub Service Bus
Azure FunctionsProcess events with Serverless code.
Make composing Cloud Apps insanely easyDevelop Functions in C#, Node.js, F#, Python, PHP, Batch and more Easily schedule event-driven tasks across servicesExpose Functions as HTTP API endpointsScale Functions based on customer demandEasily integrate with Logic Apps
Code Events + dataAzure Functions
Functions Hello WorldDemo
Functions Programming ModelTrigger(data) Input Input
code
Output
Output
• Function as a single unit of work• Functions are executed per trigger • Functions have inputs and outputs
Input
Triggers and
bindings
Image Processing
Demo
Dual abstraction
Business Logic
Serverless PaaS
Other Services
• Serverless compute abstracts away the compute• Azure Functions Bindings abstract away the services you interact with
Building Applications With FunctionsInstead of …• implementing a route inside of a Web Application server, I
write a function.• pulling – triggers • ‘SDK’ – bindings• writing large functional tests against a server, your
functional tests look more like unit tests per function.• building and deploying servers, deploy collections of
Functions
Functions Programming Model - Best Practices• Functions should “do one thing”• Functions should be stateless• Functions should be idempotent• Functions should finish as quickly as possible
1
Serverless Patterns
Every 15 minutes Clean tableFind and clean invalid data
ApplicationsExample: Timer based processing
FTP Download Function
Blob Replication
Blob Storage Cool Storage
Abnormal behavior
Problem• Replicate logs from
one data center to another • Analyze the logs• Take action
Using Functions• Setup a VM/
Container/ WebJobs• Build/ patch/ deploy• Monitor• Manage FTP cred• Use FTP library• Use Azure SDK
Before Functions• Setup a VM/
Container/ WebJobs• Build/ patch/ deploy• Monitor• Manage FTP cred• Use FTP library• Use Azure SDK
FTP Download Function
Blob Replication
Blob Storage Cool Storage
Abnormal behavior
Blob Replication
Blob Storage Cool Storage
Abnormal behavior
FTP Download Manager Function
Single Folder Single Folder Single Folder
File added toBlob Storage
Transform CSV to datarows Power BIChart graphic
ApplicationsExample: Azure service event processing
Photo taken andWebHook called Stores in blob storage Produces scaled images
Async background processingExample: Serverless Mobile back ends
API
Photo taken andWebHook called
Problem• Expose REST API• Upload data to
storage• Process data
Using Functions• Setup a VM/
Container/ WebJobs• Build/ patch/ deploy• Monitor• Use Azure SDK• Async data
processing (scale)
Before Functions• Setup a VM/
Container/ WebJobs• Build/ patch/ deploy• Monitor• Use Azure SDK• Async data
processing (scale)
Photo taken andWebHook called
Loaded web pagecallsWebHook
Completed pageCreate ad based on user profile
ApplicationsExample: Serverless Web Applications architectures
Millionsof devices feedinto Stream Analytics
Store data inSQL Online
Transform to structured data
ApplicationsExample: Real-time stream processing
Problem• Collect tweets• Analyze tweets• Display rich analysis
Using Serverless• Setup a VM/ Container/
WebJobs• Build/ patch/ deploy• Monitor• Connect (auth)to twitter • Using Twitter API (SDK)• Analyze tweets• Build rich client to show
results
Before Serverless• Setup a VM/ Container/
WebJobs• Build/ patch/ deploy• Monitor• Connect (auth)to twitter • Using Twitter API (SDK)• Analyze tweets• Build rich client to show
results
•Thick clients; thin & stateless backends• SPAs like Angular/React are your friend• Be sure to enable CORS
•Sync is nice, but Async is nicer• Async, queue based systems are more resilient• Read and internalize the reactive manifesto - http://www.reactivemanifesto.org/ • While synchronous work will happen, minimize the work done in a sync function and
kick off to a queue based async process (HTTP status code 202, not 201 )
•Live and die by the cloud• Like never before, develop on the cloud, test on the cloud, ship on the cloud• Not just FaaS, but use other serverless tech that best solves the problem (like Logic
Apps)
General practices for serverless
Microsoft and ServerlessTry Functions – https://functions.azure.comTry App Service – https://tryappservice.azure.com