Daniel Bass
Serverless Slack
Bots with Azure
Durable Functions
Daniel Bass
Senior Developer in Private Credit at M&G plc
https://amzn.to/2O1mJePhttps://amzn.to/2vovaKW https://www.danielbass.dev
The Problem
Trade Awareness
Fund Manager places order
for assets, which then get
bought or sold
Analyst that covers assets
may be unaware
Fund Managers team and
support team may be
unaware
My Customer
• Analyst working for one of our Private Credit teams
• Constructed manual report every morning
Solution
Durable Functions
Define Workflows
using real code
Execution is reliably
saved and can last for
hours, months or
indefinitely
Operation is entirely
Serverless
Hand off calculations
and data retrieval to
Azure Functions
Durable Orchestration
Get Configs Send to Slack
Get Trades Filter Trades
Durable Orchestrator
Notification Configuration Screen
Storage Account
CRUD Azure Functions
Azure Active Directory
Table Storage
React App
Notification Configuration Screen
Notification Configuration Screen
Why this architecture?
Secure Scalable
Rapid Development Scale to Zero
The Result
Automated Regular Notifications
Fund Manager places order
for assets, which then get
bought or sold
Analyst receives a
notification the next
morning for any assets they
cover
Fund Managers team and
support team receives
notification an hour later
Customer
• No longer needs to construct his manual report
• Can tweak and configure however much he wants
• Total reliability and earlier execution
Problems
Problem
Users began to report slow loading times
• Application Insights indicated these incidents were approximately 12 seconds in length
• They didn’t occur over 20 minutes after the hourly notification went off
• They were always accompanied by ‘startup’ traces that Durable Functions always does
when it starts and checks the state of all outstanding orchestrators
Problem
Problem
Enormous node_modules folder – 60mb!
Solution
Rewrite code to remove
need for dependencies
Introduce build tool that ‘Tree-
shakes’ dependencies
Add Keep Alive function to
Function App
Future Extensions
Workflow Management
Slack Interactive Messages with Bolt Durable Functions Workflows
Bolt on Azure Functions
• Slack model is event-based – when a user interacts with your bot they issue a message
describing that event to your registered publically available url
• Slack have produced a convenient developer framework that uses Express on Node.js
called Bolt which will set up everything required to receive these events and validate
they are actually from Slack
• This previously did not place nice with Azure Functions, as the runtime handles
requests, not a framework like express
• There are other issues, like Slack requiring a response within 3 seconds, which
terminates an Azure Functions execution
Bolt on Azure Functions
• I have released an open source npm library called ‘bolt-azure-functions-receiver' which
implements the logic you need to replace the built in Express method and use Bolt
• You can then kick off a Durable Functions orchestrator and respond within 3 seconds
easily
Durable Orchestrator
Azure Function
invokes library
and starts Bolt
framework to
help with
handling the
request
Orchestrator
continues as
background
process and
completes
action
Slack User
clicks on your
message and
Slack sends
you an event
to HTTP
triggered
function
Starts
Orchestrator
and returns
200 OK
We’re Hiring:
global.mandg.com/careers

Integration-Monday-Serverless-Slackbots-with-Azure-Durable-Functions

  • 1.
    Daniel Bass Serverless Slack Botswith Azure Durable Functions
  • 2.
    Daniel Bass Senior Developerin Private Credit at M&G plc https://amzn.to/2O1mJePhttps://amzn.to/2vovaKW https://www.danielbass.dev
  • 3.
  • 4.
    Trade Awareness Fund Managerplaces order for assets, which then get bought or sold Analyst that covers assets may be unaware Fund Managers team and support team may be unaware
  • 5.
    My Customer • Analystworking for one of our Private Credit teams • Constructed manual report every morning
  • 6.
  • 7.
    Durable Functions Define Workflows usingreal code Execution is reliably saved and can last for hours, months or indefinitely Operation is entirely Serverless Hand off calculations and data retrieval to Azure Functions
  • 8.
    Durable Orchestration Get ConfigsSend to Slack Get Trades Filter Trades
  • 9.
  • 10.
    Notification Configuration Screen StorageAccount CRUD Azure Functions Azure Active Directory Table Storage React App
  • 11.
  • 12.
  • 13.
    Why this architecture? SecureScalable Rapid Development Scale to Zero
  • 14.
  • 15.
    Automated Regular Notifications FundManager places order for assets, which then get bought or sold Analyst receives a notification the next morning for any assets they cover Fund Managers team and support team receives notification an hour later
  • 16.
    Customer • No longerneeds to construct his manual report • Can tweak and configure however much he wants • Total reliability and earlier execution
  • 17.
  • 18.
    Problem Users began toreport slow loading times • Application Insights indicated these incidents were approximately 12 seconds in length • They didn’t occur over 20 minutes after the hourly notification went off • They were always accompanied by ‘startup’ traces that Durable Functions always does when it starts and checks the state of all outstanding orchestrators
  • 19.
  • 20.
  • 21.
    Solution Rewrite code toremove need for dependencies Introduce build tool that ‘Tree- shakes’ dependencies Add Keep Alive function to Function App
  • 22.
  • 23.
    Workflow Management Slack InteractiveMessages with Bolt Durable Functions Workflows
  • 24.
    Bolt on AzureFunctions • Slack model is event-based – when a user interacts with your bot they issue a message describing that event to your registered publically available url • Slack have produced a convenient developer framework that uses Express on Node.js called Bolt which will set up everything required to receive these events and validate they are actually from Slack • This previously did not place nice with Azure Functions, as the runtime handles requests, not a framework like express • There are other issues, like Slack requiring a response within 3 seconds, which terminates an Azure Functions execution
  • 25.
    Bolt on AzureFunctions • I have released an open source npm library called ‘bolt-azure-functions-receiver' which implements the logic you need to replace the built in Express method and use Bolt • You can then kick off a Durable Functions orchestrator and respond within 3 seconds easily
  • 26.
    Durable Orchestrator Azure Function invokeslibrary and starts Bolt framework to help with handling the request Orchestrator continues as background process and completes action Slack User clicks on your message and Slack sends you an event to HTTP triggered function Starts Orchestrator and returns 200 OK
  • 27.