Making the Switch to “Serverless” Full-Stack Development David Aktary Founder, Aktarytech
Total Page:16
File Type:pdf, Size:1020Kb
SATURN 2017 Making the Switch to “Serverless” Full-Stack Development David Aktary Founder, AktaryTech TitleMaking of thethe PresentationSwitch to “Serverless” Goes Here Full-Stack Development © 2017 AktaryTech[Copyright Owner[s]] 1 SATURN 2017 Agenda • Introduction • “Serverless” Overview • What it is • Benefits • Platforms & Tools Making the Switch to “Serverless” Full-Stack Development © 2017 AktaryTech 2 SATURN 2017 Agenda • Serverless in Practice • Architecture • Greenfield • Migrations • Impact on Workflow • Pitfalls and Gotchas • Workshop Making the Switch to “Serverless” Full-Stack Development © 2017 AktaryTech 3 SATURN 2017 Caveats • Rapidly changing • AWS more mature • Not exhaustive • Node.js-focused • Developer-centric Making the Switch to “Serverless” Full-Stack Development © 2017 AktaryTech 4 SATURN 2017 Introduction • BS Computer Science, Michigan • MBA, Duke • 8 Years at IBM • 3 Years VP Tech @ Nestle Digital Agency • Founder of AktaryTech • Custom Dev Shop • Full-Stack JS Specialists • LA & Austin Making the Switch to “Serverless” Full-Stack Development © 2017 AktaryTech 5 SATURN 2017 SATURN 2017 “Serverless” Overview TitleMaking of thethe PresentationSwitch to “Serverless” Goes Here Full-Stack Development © 2017 AktaryTech[Copyright Owner[s]] 6 SATURN 2017 What it is The term “serverless” • BaaS: pre-built, 3rd-party application service • FaaS: custom application Similarities: • Pay-as-you-execute • Managed server • Auto-scaling Making the Switch to “Serverless” Full-Stack Development © 2017 AktaryTech 7 SATURN 2017 What it is Function (“Action”) • Containerized custom-written application code • Should include bundled dependencies & binaries Resource • Memory & execution time limits Triggers (“Events”) • Launches Function execution Trigger Function Resource • Can be another Function Resources • External PaaS/BaaS/FaaS services Resource Making the Switch to “Serverless” Full-Stack Development © 2017 AktaryTech 8 SATURN 2017 What it is Traditional Serverless N-Tier Message-driven Making the Switch to “Serverless” Full-Stack Development Images from https://martinfowler.com/articles/serverless.html#ACoupleOfExamples © 2017 AktaryTech 9 SATURN 2017 SATURN 2017 Benefits TitleMaking of thethe PresentationSwitch to “Serverless” Goes Here Full-Stack Development © 2017 AktaryTech[Copyright Owner[s]] 10 SATURN 2017 Benefits Making the Switch to “Serverless” Full-Stack Development © 2017 AktaryTech Source: https://www.slideshare.net/AmazonWebServices/building-a-development-workflow-for-serverless- 11 applications-march-2017-aws-online-tech-talks SATURN 2017 Benefits: Cost Bustle Case study*: • “With AWS Lambda, the engineering team now puts zero thought into scaling applications. There is an extremely low cost for any engineer to deploy production-ready code that will scale. No one has to deal with infrastructure management, so every engineer can focus on building out new features and innovating.” • “With no operational maintenance of servers, the team can remain small, with half the people normally required to build and operate sites of Bustle’s scale.” • “Bustle has also experienced approximately 84% cost savings by moving to a serverless architecture.” Calculator (beta): http://serverlesscalc.com Making the Switch to “Serverless” Full-Stack Development *Source: https://aws.amazon.com/solutions/case-studies/bustle/ © 2017 AktaryTech 12 SATURN 2017 Benefits: Cost Lightweight and low-traffic website • 10,000 hits/day • perhaps 200 ms of execution time per hit at 256MB • → 432,000 requests per month and 2160 GB-sec of compute per month • → about $0.31/mo … less than 1/10th the cost of even a t2.nano, the smallest EC2 instance! Periodic Scheduled Job • A scheduled job that runs every hour with 1GB RAM for 2 minutes • → 86,400 GB-sec of compute per month and 720 requests per month • → $1.44/mo … still less than 1/3rd of a t2.nano! Making the Switch to “Serverless” Full-Stack Development Source: https://www.trek10.com/blog/lambda-cost/ © 2017 AktaryTech 13 SATURN 2017 Benefits: Cost Lambda Breakeven Analysis for an m4.large Instance m4.large, 2 vCPU, 8 GB RAM costs $0.12/hr or ~$86/month in N. Virginia region. Function Execution Requests per Hour Required for Requests Memory & Time Lambda Cost to Equal EC2 Cost per Second 100 ms @ 128 MB 295,000 81.9 200 ms @ 512 MB 64,000 17.8 200 ms @ 1 GB 34,000 9.4 1 sec @ 1 GB 7,100 2.0 Making the Switch to “Serverless” Full-Stack Development Source: https://www.trek10.com/blog/lambda-cost/ © 2017 AktaryTech 14 SATURN 2017 Benefits:12-Factor Architecture I Codebase Handled by developer (Manage versioning of functions on their own) II Dependencies Handled by developer, facilitated by serverless platform (Runtimes and packages) III Configuration Handled by platform (Environment variables or injected event parameters) IV Backing services Handled by platform (Connection information injected as event parameters) V Build, release, run Handled by platform (Deployed resources are immutable and internally versioned) VI Processes Handled by platform (Single stateless containers often used) VII Port binding Handled by platform (Actions or functions are automatically discovered) VIII Concurrency Handled by platform (Process model is hidden and scales in response to demand) IX Disposability Handled by platform (Lifecycle is hidden from the user, fast startup and elastic scale is prioritized) X Dev/prod parity Handled by developer (The developer is the deployer. Scope of what differs is narrower) XI Logs Handled by platform (Developer writes to console.log, platform handles log streaming) XII Admin processes Handled by developer (No distinction between one off processes and long running) Making the Switch to “Serverless” Full-Stack Development Source: https://developer.ibm.com/opentech/2016/09/06/what-makes-serverless-attractive/ © 2017 AktaryTech 15 SATURN 2017 SATURN 2017 Platforms & Tools TitleMaking of thethe PresentationSwitch to “Serverless” Goes Here Full-Stack Development © 2017 AktaryTech[Copyright Owner[s]] 16 SATURN 2017 Platforms & Tools Hosted • Amazon Lambda • Azure Functions • Google Cloud Functions • IBM Bluemix OpenWhisk* • Auth0 Webtask On-Prem • Apache OpenWhisk* (https://github.com/openwhisk) • IronFunctions (https://github.com/iron-io/functions) • Functions as a Service (https://github.com/alexellis/faas) • Funcatron* (https://funcatron.org) Making the Switch to “Serverless” Full-Stack Development * Claim to minimize vendor lock-in © 2017 AktaryTech This list is not exhaustive. Visit https://github.com/anaibol/awesome-serverless for a more detailed list 17 SATURN 2017 Platforms & Tools - Rolling Your Own Virtualization/Orchestration: • Docker / Docker Swarm • Vagrant • Kubernetes FaaS • Mesos Messaging: • Kafka Funcatron • RabbitMQ Metrics/Monitoring: Prometheus API Definition: Swagger OpenWhisk Making the Switch to “Serverless” Full-Stack Development © 2017 AktaryTech 18 SATURN 2017 Platforms & Tools - Frameworks Language Platform API Gateway Node.js Python Java Golang Closure Rust Scala AWS Azure OpenWhisk Integration Serverless X X X X X X X * Claudia X X AWS Apex X X X X X X X Lambada Framework X AWS Framework Zappa X AWS Gordon X X X X X X Making the Switch to “Serverless” Full-Stack Development © 2017 AktaryTech 19 SATURN 2017 SATURN 2017 Serverless in practice TitleMaking of thethe PresentationSwitch to “Serverless” Goes Here Full-Stack Development © 2017 AktaryTech[Copyright Owner[s]] 20 SATURN 2017 Serverless in Practice - Architecture Design Patterns • Event-driven data processing • Web applications • Mobile applications • Internet-of-Things applications • Real-time stream processing Making the Switch to “Serverless” Full-Stack Development © 2017 AktaryTech 21 Source: http://www.allthingsdistributed.com/2016/05/aws-lambda-serverless-reference-architectures.html SATURN 2017 Serverless in Practice - Architecture • Event-driven data processing Making the Switch to “Serverless” Full-Stack Development Reference architecture: https://github.com/awslabs/lambda-refarch-fileprocessing © 2017 AktaryTech 22 Source: http://www.allthingsdistributed.com/2016/05/aws-lambda-serverless-reference-architectures.html SATURN 2017 Serverless in Practice - Architecture • Web applications Making the Switch to “Serverless” Full-Stack Development Reference architecture: https://github.com/awslabs/lambda-refarch-webapp © 2017 AktaryTech 23 Source: http://www.allthingsdistributed.com/2016/05/aws-lambda-serverless-reference-architectures.html SATURN 2017 Serverless in Practice - Architecture • Mobile applications Making the Switch to “Serverless” Full-Stack Development Reference architecture: https://github.com/awslabs/lambda-refarch-mobilebackend © 2017 AktaryTech 24 Source: http://www.allthingsdistributed.com/2016/05/aws-lambda-serverless-reference-architectures.html SATURN 2017 Serverless in Practice - Architecture • Internet-of-Things applications Making the Switch to “Serverless” Full-Stack Development Reference architecture: https://github.com/awslabs/lambda-refarch-iotbackend © 2017 AktaryTech 25 Source: http://www.allthingsdistributed.com/2016/05/aws-lambda-serverless-reference-architectures.html SATURN 2017 Serverless in Practice - Architecture • Real-time stream processing Making the Switch to “Serverless” Full-Stack Development Reference architecture: https://github.com/awslabs/lambda-refarch-streamprocessing © 2017 AktaryTech 26 Source: http://www.allthingsdistributed.com/2016/05/aws-lambda-serverless-reference-architectures.html SATURN 2017 Serverless in Practice - Architecture