Upgrade to Pro — share decks privately, control downloads, hide ads and more …

High Availability, Cost Effective Messenger Bot...

High Availability, Cost Effective Messenger Bot with AWS Lambda Serverless Infrastructure

You can find the example code here: https://github.com/rromadhoni/jarwo

Apparently links can't be clicked here, please go to this presentation if you want to open reference links:
https://docs.google.com/presentation/d/1jLv0_eOQMH-lvfHaGPrHwgzKy9Y3SsovT659e4b7AY4/edit?usp=sharing

Avatar for Rizki Romadhoni

Rizki Romadhoni

February 22, 2017
Tweet

More Decks by Rizki Romadhoni

Other Decks in Technology

Transcript

  1. High Availability, Cost Effective Messenger Bot with AWS Lambda Serverless

    Infrastructure Rizki Romadhoni - 22.02.2017 [ , ].concat([ ]) ===
  2. 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."
  3. Cost Effective Producing good results without costing a lot of

    money. Based on the traffic model of your app.
  4. Chatbot Example • Mark Zuckerberg: After a year of coding,

    here's Jarvis. Chatbot Advantages • Single interface to do everything, (R.A.N) • No need to install apps • Feels natural Becoming hype Messaging app installs doesn't seem to decrease. Meanwhile, app uninstall rate stays high
  5. 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.
  6. Event-Driven Architecture A software architecture pattern promoting the production, detection,

    consumption of, and reaction to events. 1. Loosely coupled. 2. Highly distributed. 3. Flexible component layout.
  7. 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
  8. Serverless, why? • Reduced operational cost - effective computing output.

    • Horizontal scaling is completely automatic, elastic, and managed by the provider. • That’s it. AWS Lambda Pricing: $0.0000002 / 100ms execution Means $0.2 / 1M 100ms execution
  9. 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 (BaaS) • Function as a Service (FaaS)
  10. (Mobile) Backend as a Service • Everything is fully managed

    by provider. • Requires less or zero knowledge about system’s logic and state. • Less or zero control over system’s state.
  11. Function as a Service • Run code without thinking about

    servers. • Pay for only the compute time you consume. • Distributed compute service to execute application logic in response to events • Scale as it happens. • Flexible component layout. • Optimization directly affects operational cost. • Available programming languages: JavaScript, Python, Java ( any JVM language).
  12. [canReuse] [Else] 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
  13. Events Functions in FaaS are triggered by event types defined

    by the provider (AWS in this case:). • API Gateway (HTTP) • SNS (Event Notification) • DynamoDB / Kinesis Streams • S3 (File System) • Schedule • Alexa Skill
  14. 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
  15. 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
  16. Operational Cost - AWS Monthly operational cost: 1. 3M AWS

    Lambda execution for inbound and/or outbound layer. 1. (4.5 x 10^6) x (2 X 10^-7) = $0.9 Lambda i. 1.5 x 10^6 Inbound execution ii. 1.5 x 10^6 Responder execution iii. 1.5 x 10^6 Outbound execution 2. (1.5 x 10^6) x (4.25 x 10^-6) = $6.37 API Gateway i. 1.5 x 10^6 Inbound http event 3. (3 x 10^6) x (5 x 10^7) = $1.5 SNS Publish (Deliveries to Lambda are free) i. 1.5 x 10^6 Inbound message queue ii. 1.5 x 10^6 Outbound message queue
  17. 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/
  18. References • Mark Zuckerberg: After a year of coding, here's

    Jarvis. • Mark Zuckerberg: Building Jarvis. • Most popular mobile messaging apps worldwide as of January 2017, based on number of monthly active users (in millions) • Number of monthly active Facebook Messenger users from April 2014 to July 2016 (in millions) • Number of monthly active WhatsApp users worldwide from April 2013 to January 2017 (in millions) • Martin Fowler: Serverless Architecture • Understanding Container Reuse in AWS Lambda
  19. Serverless allows us to build a highly available messenger bot

    without worrying about operational cost and scale out.