Azure Serverless
Architecture
AZURE FUNCTION ON COSMOS DB
Hansamali Gamage
MVP in Visual Studio & Development Technologies
MVP in Visual Studio & Development Technologies
Senior Software Engineer at TIQRI (Pvt) Ltd
Coder, Blogger & Speaker
Email : hansamaligamage@gmail.com
Blog : http://hansamaligamage.blogspot.com/
Twitter : @hansamaligamage
About Me
Azure Serverless Architecture
•Build apps using serverless functions
•No need to handle servers or infrastructure
•Stop worrying about infrastructure, OS, configuration
•Focus on the function implementation
•Scale on demand
Azure Function
•Create functions in any language you want Javascript, C#, Java, Python, Php, PowerShell
•Write code on web interface or upload precompiled code
•Continuous deployment & integrate with DevOps pipeline
•Interact with different azure services as CosmosDB, Storage, Queues, Service bus,
EventHub, EventGrid, NotificationHub
•External services Twillio, Sendgrid, Github
•Save cost
•Less code to maintain
Real Stories
•FujiFilm
•Firstgas – Gas pipeline business in New Zealand
•Navitime – Navigation technology company creates chatbots to help tourists to
go around japan
•Quest – provides software tools to make IT management simpler, California
•Plexure – Help retailers to bring digital marketing to brick and motor shopping
•CarMax – Largest car retailer in US, Car shopping online and on mobile
Type of Functions
•Timer based processing
•Event based activity processing
•Serverless web application
•Serverless mobile backend
•Real time stream processing
•Real time bot messaging
Pricing - Plans
Consumption Plan
•Allocates compute power when your code is running
•Charged for compute resources only when your function is running
•Billing based on no of executions, execution time and memory
Azure App Service Plan
•Similar to Web apps, API apps, mobile apps
•Dedicated vms are allocated to your app service
•Function host is always running,
•When your app need to run continuously, app service plan is cost effective
Azure Cosmos DB
•A database service
•Multi model & Multi API support
•Global Distribution
•Low latency
•Elastic scale out
•Comprehensive SLAs
Cosmos DB multi
modal & multi APIs
•SQL API
•MongoDB API
•Graph API
•Table API
•Cassandra API
Demo
1. Print a text on the screen
HttpTrigger -> return text
2. Notify a CosmosDB document change (Event based Trigger)
CosmosDBTrigger -> return text
Demo – Highway Accident Prevention System
I want to send a sms message when a vehicle exceeds a specific speed limit
Function 1
•CosmosDBTrigger
•Out – Queue Storage
Function 2
•QueueTrigger
•Out – Twillio SMS
Try it yourself !!
You can check this article,
Azure Function App: Create a trigger on Cosmos DB
Demo Code,
https://github.com/hansamaligamage/functionappon
cosmosdb
Thank You 
Email : hansamaligamage@gmail.com
Blog : http://hansamaligamage.blogspot.com/
Twitter : @hansamaligamage
LinkedIn : https://goo.gl/DWDzdg
TechNet : https://goo.gl/7Pa5X8
Feedback 
https://www.rateevent.com/SpeechQR?speechcode=SCAAA443
LOCAL
ORGANIZERS
SILVER SPONSORSHIP
BRONZE SPONSORSHIP
GENERAL SPONSORSHIP
PRINTED MEDIA PARTNER
ORGANIZING SUPPORT PARTNER
OTHER SPONSORSHIPS
GLOBAL SPONSORSHIPS

How to create a Function App on Cosmos DB

  • 1.
    Azure Serverless Architecture AZURE FUNCTIONON COSMOS DB Hansamali Gamage MVP in Visual Studio & Development Technologies
  • 2.
    MVP in VisualStudio & Development Technologies Senior Software Engineer at TIQRI (Pvt) Ltd Coder, Blogger & Speaker Email : hansamaligamage@gmail.com Blog : http://hansamaligamage.blogspot.com/ Twitter : @hansamaligamage About Me
  • 3.
    Azure Serverless Architecture •Buildapps using serverless functions •No need to handle servers or infrastructure •Stop worrying about infrastructure, OS, configuration •Focus on the function implementation •Scale on demand
  • 4.
    Azure Function •Create functionsin any language you want Javascript, C#, Java, Python, Php, PowerShell •Write code on web interface or upload precompiled code •Continuous deployment & integrate with DevOps pipeline •Interact with different azure services as CosmosDB, Storage, Queues, Service bus, EventHub, EventGrid, NotificationHub •External services Twillio, Sendgrid, Github •Save cost •Less code to maintain
  • 5.
    Real Stories •FujiFilm •Firstgas –Gas pipeline business in New Zealand •Navitime – Navigation technology company creates chatbots to help tourists to go around japan •Quest – provides software tools to make IT management simpler, California •Plexure – Help retailers to bring digital marketing to brick and motor shopping •CarMax – Largest car retailer in US, Car shopping online and on mobile
  • 6.
    Type of Functions •Timerbased processing •Event based activity processing •Serverless web application •Serverless mobile backend •Real time stream processing •Real time bot messaging
  • 7.
    Pricing - Plans ConsumptionPlan •Allocates compute power when your code is running •Charged for compute resources only when your function is running •Billing based on no of executions, execution time and memory Azure App Service Plan •Similar to Web apps, API apps, mobile apps •Dedicated vms are allocated to your app service •Function host is always running, •When your app need to run continuously, app service plan is cost effective
  • 8.
    Azure Cosmos DB •Adatabase service •Multi model & Multi API support •Global Distribution •Low latency •Elastic scale out •Comprehensive SLAs
  • 9.
    Cosmos DB multi modal& multi APIs •SQL API •MongoDB API •Graph API •Table API •Cassandra API
  • 10.
    Demo 1. Print atext on the screen HttpTrigger -> return text 2. Notify a CosmosDB document change (Event based Trigger) CosmosDBTrigger -> return text
  • 11.
    Demo – HighwayAccident Prevention System I want to send a sms message when a vehicle exceeds a specific speed limit Function 1 •CosmosDBTrigger •Out – Queue Storage Function 2 •QueueTrigger •Out – Twillio SMS
  • 12.
    Try it yourself!! You can check this article, Azure Function App: Create a trigger on Cosmos DB Demo Code, https://github.com/hansamaligamage/functionappon cosmosdb
  • 13.
    Thank You  Email: hansamaligamage@gmail.com Blog : http://hansamaligamage.blogspot.com/ Twitter : @hansamaligamage LinkedIn : https://goo.gl/DWDzdg TechNet : https://goo.gl/7Pa5X8
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.

Editor's Notes

  • #4 You don’t need a server to compute or run your funcation, and no need to worry about the infrastructure, you can focus only about the functionality you want to write You can scale the resources of your function when its needed, initially plan for something simple and you can scale it when its needed You can focus on building your application, no need to worry about maintaining servers when your workload grows, you can scale it on demand, when its required You can select a familiar language to build up the function, Javascript, C#, Java, scripting language like Python, Php, bash, batch and powershell. You can use web based interface to write the code or can upload a precompiled code, You can use continuous deployment to integrate with your deployment pipeline
  • #5 You can interact with different Azure and external services, Easily interact with Azure CosmosDB, storage, eventhub, eventgrid, notification hub. Servuce bus, and external services like Twillio, SendGrid, github You can save cost and maintain less code
  • #7 Timer – evenet based on timer, execute code every 15 mins to clean up the database table based on a custom logic written in a function Azure service event processing – trigger an event based on an activity in azure service, execute log file in a blob and transform into a row in sql db Serverless web app – function can act as a single page app, app calls function using webhook url, save data, read data and decide what to do Serverless mobile backends – mobile app capture an image and call a function to resize the image to be mobile friendly Real time stream processing – IOT device send message to streat analytics and call a function to process and save data into a sql db Real time bot messaging – Create a function that processes a message using cortana analytics and call it using ms bot framework
  • #8 Automatically allocates compute power when your code is running, you are charged for compute resources only when your function is running, You can scale out when load increases, and scale down when code is not running, no need to pay for idle VMs pay only when your function is running Billing based on no of executions, execution time and memory Similar to web apps, API apps, mobile apps dedicated vms are allocated to your app service apps Function host is always running, When your app need to run continuously, app sevice plan is cost effective When you need more cpu and memory that what is provided in consumption plan You need to run longer than maximum execution time allowed in consumption plan (10 mins) When you want to run your function apps on linux, or you want to provide a custom image on which to run your functions