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

Serverless - Lessons Learned - Nike Brown Bag

Serverless - Lessons Learned - Nike Brown Bag

Brown Bag @ Nike on 03/2019.
- Serverless Deployment Framework (Serverless, Terraform, AWS SAM)
- Deployment Best Practises
- Serverless Performance (Coldstart, VPC, Runtimes, GraalVM)

Avatar for Driss Amri

Driss Amri

March 28, 2019
Tweet

More Decks by Driss Amri

Other Decks in Programming

Transcript

  1. “Everything we hear is an opinion, not a fact. Everything

    we see is a perspective, not the truth.” - Marcus Aurelius, Mediations
  2. Serverless Framework • Most widely used Serverless toolkit • Released

    in 2015 • Simple Developer Experience • Focus on Functions, not Cloud Infrastructure • Cloud-agnostic - AWS provider: - Compiles to CloudFormation - deployed as CloudFormation Stack
  3. AWS SAM • Official AWS deployment framework • Released in

    2016 • Built on top of CloudFormation - Deployed as CloudFormation Stack
  4. AWS SAM CLI sam init --runtime java8 sam package \

    --output-template-file packaged.yaml \ --s3-bucket bucketname sam deploy \ --template-file packaged.yaml \ --stack-name sam-app \ --capabilities CAPABILITY_IAM \ --region eu-west-1 aws cloudformation delete-stack --stack-name sam-app
  5. Deployment Frameworks AWS SAM Terraform + Easy to use +

    Official AWS Support + SAM Local Docker - Missing basic features - AWS only + Great for infrastructure + Cloud agnostic - Verbose - No extra Serverless support - Steap learning curve Serverless Framework + Easy to use + Cloud agnostic + Biggest community + Easy local testing* - Limited local testing for Java
  6. Deployment best practises • Two phase deployment & destroy -

    Stateful resources (DynamoDB, RDS, SQS, …) - Stateless resources (Lambda, Gateway, Cloudwatch, ...) • Safe deployments - Canary - Linear - AllAtOnce
  7. Latency UX • Synchronous requests - User waiting: < 1

    sec - AWS & Google: 100-500 ms delays has huge impact • Asynchronous requests - Depends on requirements - Batch reports < 30 sec - Any request > 5 sec should provide feedback
  8. When do coldstarts happen? • First invocation instance • Concurrent

    invocations • After provider resource clean up • After deployment & configuration change
  9. When to use a VPC? • Access to Amazon RDS,

    Elasticache, RedShift, … • Private API Gateway • On-premise services over VPN/Direct Connect • ...
  10. Minimize bootstrap • Keep function single purposed • Minimize dependencies

    & use lightweight frameworks - serverless-optimizer-plugin, webpack,… • Prefer low overhead runtime (node.js, Python, Go) • Choose the best memory size - 2x Memory = > 2x CPU = Possibly Faster & Cheaper
  11. Runtime: Java Global app init: Static + Constructor Java runtime

    initialization: ~200 ms Function execution • Java 8 + Gradle • DynamoDB AWS SDK 2 + AWS HTTP Client + Dagger 2 Latency: ~3.9s drissamri/aws-lambda-runtime-coldstart - java
  12. Runtime: node.js • Node.js v8 + TypeScript + Webpack •

    DynamoDB Client drissamri/aws-lambda-runtime-coldstart - nodejs Node.js runtime initialization: ~200 ms Global app init Function execution Latency: ~560ms
  13. AWS Lambda Custom Runtime • Implement AWS Lambda in ANY

    language • Runtime triggers the Lambda function handler • Can be included in the Function deployment - Executable file: bootstrap
  14. GraalVM • Create native images: self contained executable • Lightning

    fast startup • Low memory consumption • Polyglot programming
  15. GraalVM Lambda • Possible with AWS Lambda Custom Runtime •

    Framework support: - Micronaut: workable - Quarkus: experimental - Spring Fu: experimental
  16. Conclusion • Deployment ✅ Serverless Framework or AWS SAM ✅

    Safe deployments with CodeDeploy ✅ Separate stateful and stateless parts of build • Performance ✅ Critical latency: nodejs ✅ Keep an eye on GraalVM
  17. Get started! Amazon Web Services — a practical guide https://github.com/open-guides/og-aws

    AWS Certification preparation https://bit.ly/2aroFYb Serverless framework https://serverless.com AWS Well-Architected https://aws.amazon.com/architecture/well-architected The Burning Monk - Yan Cui https://theburningmonk.com/
  18. Links AWS re:Invent 2017: Become a Serverless Black Belt https://www.youtube.com/watch?v=oQFORsso2go

    A Serverless Journey: Under the Hood of AWS Lambda https://youtu.be/QdzV04T_kec