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)

Driss Amri

March 28, 2019
Tweet

More Decks by Driss Amri

Other Decks in Programming

Transcript

  1. Serverless on AWS
    LESSONS LEARNED
    Driss Amri
    @drams88

    View full-size slide

  2. Who is Driss Amri?
    Blogger at drissamri.be
    Traveler, Diver, Developer

    View full-size slide

  3. Agenda
    ● Deployment
    - Frameworks
    - Best practises
    ● Performance
    - Cold start
    - VPC
    - Runtimes

    View full-size slide

  4. “Everything we hear is an opinion, not a fact.
    Everything we see is a perspective, not the truth.”
    - Marcus Aurelius, Mediations

    View full-size slide

  5. Deployment toolkits
    ● Terraform
    ● Serverless Framework
    ● AWS Serverless Application Model (SAM)

    View full-size slide

  6. 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

    View full-size slide

  7. Serverless Framework

    View full-size slide

  8. Serverless Framework CLI
    serverless create --template aws-java-gradle --name sls-app
    serverless deploy --region eu-west-1
    serverless remove

    View full-size slide

  9. AWS SAM
    ● Official AWS deployment framework
    ● Released in 2016
    ● Built on top of CloudFormation
    - Deployed as CloudFormation Stack

    View full-size slide

  10. 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

    View full-size slide

  11. AWS Serverless Application Model (SAM)

    View full-size slide

  12. 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

    View full-size slide

  13. Deployment best practises
    ● Two phase deployment & destroy
    - Stateful resources (DynamoDB, RDS, SQS, …)
    - Stateless resources (Lambda, Gateway, Cloudwatch, ...)
    ● Safe deployments
    - Canary
    - Linear
    - AllAtOnce

    View full-size slide

  14. 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

    View full-size slide

  15. When do coldstarts happen?
    ● First invocation instance
    ● Concurrent invocations
    ● After provider resource clean up
    ● After deployment & configuration change

    View full-size slide

  16. The Burning Monk - I’m afraid you’re thinking about AWS Lambda cold starts all wrong

    View full-size slide

  17. The Burning Monk - I’m afraid you’re thinking about AWS Lambda cold starts all wrong

    View full-size slide

  18. The Burning Monk - I’m afraid you’re thinking about AWS Lambda cold starts all wrong

    View full-size slide

  19. The Burning Monk - I’m afraid you’re thinking about AWS Lambda cold starts all wrong

    View full-size slide

  20. - https://youtu.be/QdzV04T_kec
    - https://www.slideshare.net/AmazonWebServices/a-serverless-journey-aws-lambda-un
    der-the-hood-srv409r1-aws-reinvent-2018
    AWS re:Invent 2018

    View full-size slide

  21. When to use a VPC?
    ● Access to Amazon RDS, Elasticache, RedShift, …
    ● Private API Gateway
    ● On-premise services over VPN/Direct Connect
    ● ...

    View full-size slide

  22. Runtime
    Coldstart Performance

    View full-size slide

  23. The Burning Monk - AWS Lambda Compare Coldstart

    View full-size slide

  24. 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

    View full-size slide

  25. AWS Lambda Power Tuning
    AWS Lambda Power Tuning

    View full-size slide

  26. Real world example

    View full-size slide

  27. 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

    View full-size slide

  28. 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

    View full-size slide

  29. 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

    View full-size slide

  30. First.. What is Graal?

    View full-size slide

  31. a dynamic just-in-time compiler that
    improves efficiency and speed

    View full-size slide

  32. A (JIT) compiler for Java transforms
    bytecode to machine code

    View full-size slide

  33. -XX:+UnlockExperimentalVMOptions
    -XX:+EnableJVMCI
    -XX:+UseJVMCICompiler

    View full-size slide

  34. What about GraalVM?

    View full-size slide

  35. GraalVM
    ● Create native images: self contained executable
    ● Lightning fast startup
    ● Low memory consumption
    ● Polyglot programming

    View full-size slide

  36. GraalVM Limitations

    View full-size slide

  37. Cloud-Native Frameworks

    View full-size slide

  38. GraalVM Lambda
    ● Possible with AWS Lambda Custom Runtime
    ● Framework support:
    - Micronaut: workable
    - Quarkus: experimental
    - Spring Fu: experimental

    View full-size slide

  39. GraalVM Lambda

    View full-size slide

  40. 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

    View full-size slide

  41. 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/

    View full-size slide

  42. 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

    View full-size slide