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 Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View 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 Slide

  7. Serverless Framework

    View Slide

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

    View Slide

  9. View Slide

  10. View Slide

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

    View Slide

  12. AWS SAM

    View Slide

  13. 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 Slide

  14. AWS Serverless Application Model (SAM)

    View Slide

  15. 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 Slide

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

    View Slide

  17. View Slide

  18. View Slide

  19. View Slide

  20. View Slide

  21. View Slide

  22. View Slide

  23. Performance

    View Slide

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

  25. View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  31. View Slide

  32. View Slide

  33. View Slide

  34. View Slide

  35. - 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 Slide

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

    View Slide

  37. View Slide

  38. View Slide

  39. Runtime
    Coldstart Performance

    View Slide

  40. View Slide

  41. The Burning Monk - AWS Lambda Compare Coldstart

    View Slide

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

  43. AWS Lambda Power Tuning
    AWS Lambda Power Tuning

    View Slide

  44. Real world example

    View Slide

  45. 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 Slide

  46. 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 Slide

  47. View Slide

  48. 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 Slide

  49. View Slide

  50. GraalVM

    View Slide

  51. First.. What is Graal?

    View Slide

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

    View Slide

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

    View Slide

  54. View Slide

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

    View Slide

  56. What about GraalVM?

    View Slide

  57. View Slide

  58. View Slide

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

    View Slide

  60. GraalVM

    View Slide

  61. GraalVM Limitations

    View Slide

  62. Cloud-Native Frameworks

    View Slide

  63. Quarkus

    View Slide

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

    View Slide

  65. GraalVM Lambda

    View Slide

  66. 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 Slide

  67. Learn...

    View Slide

  68. 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 Slide

  69. 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 Slide