High Availability,
Cost Effective Messenger Bot with AWS Lambda Serverless Infrastructure
Rizki Romadhoni - 22.02.2017
[ , ].concat([ ])
===
High Availability
Refers to a system or component that is continuously operational for a desirably long length of time.
Availability can be measured relative to "100% operational" or "never failing."
Cost Effective
Producing good results without costing a lot of money.
Based on the traffic model of your app.
Chatbot
Example
Chatbot Advantages
Becoming hype
Messaging app installs doesn't seem to decrease. Meanwhile, app uninstall rate stays high
Chatbot - Messenger Platform
Inbound - Messenger Webhook
Your entrypoint to receive messages from Messenger Webhook.
Responder - AI, dumb bot, human, IoT, etc.
Listens incoming messages in order to reply it with the desired response according to the message itself.
Outbound - Messenger Send API
Send responses to Messenger Send API.
Event-Driven Architecture
A software architecture pattern promoting the production, detection, consumption of, and reaction to events.
Chatbot - Event-Driven Architecture
Messenger Webhook
Inbound
Outbound
Messenger Send API
Responder 1
Responder 2
Responder n
Message in
Message out
Inbound Message Queue
Outbound Message Queue
Serverless,
why?
AWS Lambda Pricing:
$0.0000002 / 100ms execution
Means $0.2 / 1M 100ms execution
Serverless Architecture
Overlapping Definition
There’s no one clear view of what ‘Serverless’ is, coming from two different but overlapping areas:
(Mobile) Backend as a Service
Function as a Service
How does this FaaS thingy work?
Client
Amazon API Gateway*
AWS
Lambda
HTTP Req
Trigger a Function
Node.js App
Container Cache
Exec Function
Result
Result
Spawned
Spawn App
Callback
HTTP Resp
Serverless Infrastructure
Serverless Frameworks
Events
Functions in FaaS are triggered by event types defined by the provider (AWS in this case:).
Functions
Chatbot - Serverless Infrastructure
Messenger Webhook
Messenger Send API
Message in
Message out
Inbound Function
Inbound Topic
Outbound Topic
Outbound Function
Responder n Function
Responder 1 Function
Responder 2 Function
CLI Cheatsheet
# Install serverless globally
$ npm install serverless -g
# Create an AWS Lambda function in Node.js
$ serverless create --template aws-nodejs
# Deploy to live AWS account
$ serverless deploy
# Function deployed!
$ http://api.amazon.com/users/update
Operational Cost - AWS
Assumption:
Operational Cost - AWS
Monthly operational cost:
Operational Cost - AWS
Total per month:
Total: $0.9 + $6.37 + $1.5 = $8.77 per month for ~3M in/out messages.
These pricing are based on singapore region.
https://aws.amazon.com/sns/pricing/
https://aws.amazon.com/lambda/pricing/
References
Serverless allows us to build a highly available messenger bot without worrying about operational cost and scale out.