© Copyright Microsoft Corporation. All rights reserved.
Serverless Middleware
in Azure Functions
Divakar Kumar
Senior Software Engineer @Prokarma
https://www.linkedin.com/in/divakar-kumar/
https://github.com/Divakar-kumar
👋 Hi
https://www.linkedin.com/in/divakar-kumar/
https://github.com/Divakar-kumar
🏆 Certifications:
✔️ Microsoft Certified Trainer
✔️ Microsoft Certified: DevOps Engineer Expert
✔️ Microsoft Certified: Azure Developer Associate
✔️ Microsoft Certified: Azure IoT Developer Specialty
✔️ Microsoft Certified: Azure Fundamentals
✔️ Aviatrix Certified Engineer - Multi-Cloud Network Associate
👨‍
💻
© Copyright Microsoft Corporation. All rights reserved.
Agenda
Middleware
Serverless Architecture
Middleware compatibility in Azure functions
Demo
Recreate middleware pipeline in current runtime
Microsoft Announcement
© Copyright Microsoft Corporation. All rights reserved.
Middleware
• Handle HTTP Request or Response
• Holds HTTP context and Requestdelegate
• In ASP .NET core we have 3 middleware options
• Use()
• Run()
• Map()
• Process an incoming HTTP request, modify it,
and pass it on to another piece of middleware.
• Handle an incoming HTTP request by generating
an HTTP response.
• Reroute an incoming HTTP request to another
middleware or web server
Middleware & Configuration options
ASP.NET Core in Action - What is middleware?
Andrew
https://andrewlock.net/asp-net-core-in-action-what-is-middleware/
© Copyright Microsoft Corporation. All rights reserved.
Agenda
Middleware
Serverless Architecture
Middleware compatibility in Azure functions
Demo
Recreate middleware pipeline in current runtime
Microsoft Announcement
©Microsoft Corporation
Azure
• Low management overhead
• Pay per use
• Elastically scalable
Benefits
Serverless to the Max: Doing Big Things for Small Dollars with Cloudflare Workers
and Azure Functions
- Troy
https://www.troyhunt.com/serverless-to-the-max-doing-big-things-for-small-
dollars-with-cloudflare-workers-and-azure-functions/
Don’t use Azure Functions as a web application
- Maarten
https://blog.maartenballiauw.be/post/2019/10/02/dont-use-azure-functions-as-
a-web-application.html
©Microsoft Corporation
Azure
• Logging
• Exception handling
• Tracing
• CORS
• Authentication
• Authorization
• Caching
• Data validation
• Monitoring
• Health check
Challenges in Serverless Architecture
© Copyright Microsoft Corporation. All rights reserved.
Agenda
Middleware
Serverless Architecture
Middleware compatibility in Azure functions
Demo
Recreate middleware pipeline in current runtime
Microsoft Announcement
©Microsoft Corporation
Azure
• Tightly coupled
• Target framework
• Dependent on host .NET runtime version
• In-process model
• Access to invocation pipeline is not possible
Middleware compatibility in Azure Functions (1.x to 3.x )
© Copyright Microsoft Corporation. All rights reserved.
Agenda
Middleware
Serverless Architecture
Middleware compatibility in Azure functions
Demo
Recreate middleware pipeline in current runtime
Microsoft Announcement
©Microsoft Corporation
Azure
© Copyright Microsoft Corporation. All rights reserved.
Out-of-process Model
©Microsoft Corporation
Azure
Out-of-process model
• Proxies through IIS
• Built in kestrel web server in ASP
.NET core
• Edge server
• Performance issues
ASP.NET Core In Process Hosting on IIS with ASP.NET Core
- Rick
https://weblog.west-wind.com/posts/2019/Mar/16/ASPNET-Core-Hosting-on-IIS-
with-ASPNET-Core-22
© Copyright Microsoft Corporation. All rights reserved.
.NET 5 Worker Process
©Microsoft Corporation
Azure
• Standalone Process
• Decouples .NET function from Azure function host
• Out of process model
.NET 5 worker process
© Copyright Microsoft Corporation. All rights reserved.
Visualizing .NET 5 worker process in Azure Functions
©Microsoft Corporation
Azure
.NET 5 worker process model
• 2 separate process
• gRPC communication
• Preview stage
© Copyright Microsoft Corporation. All rights reserved.
Benefits of .NET5 worker process
©Microsoft Corporation
Azure
• Fewer conflicts
• Full control of the process
• Dependency injection
Benefits
©Microsoft Corporation
Azure
Azure Functions Roadmap
© Copyright Microsoft Corporation. All rights reserved.
Required Artifacts - .NET 5 Azure Function App
local.settings.json
FunctionApp.csproj
Nuget packages:
Glance at Program.cs file :
Configureworker:
Demonstration: .NET 5 worker process
• Run local solution
• Host in azure functions
© Copyright Microsoft Corporation. All rights reserved.
Agenda
Middleware
Serverless Architecture
Middleware compatibility in Azure functions
Demo
Recreate middleware pipeline in current runtime
Microsoft Announcement
• Understanding OWIN
• Guide for Running Azure Functions on .NET 5
• .NET on Azure Functions Roadmap
• Source Code – Serverless Middleware
• Learn (http://aka.ms/learn)
Thank
you!
Danke
Grazie
Obrigado
Gracias
Teşekkürler
ありがとう
धन्यवाद
Merci
感謝你
唔該
‫شكر‬
Kiitos
감사합니다
Takk
Dzięki
‫مرسي‬
Спасибо
Ευχαριστώ

SERVERLESS MIDDLEWARE IN AZURE FUNCTIONS