$30 off During Our Annual Pro Sale. View Details »

Breaking the Monolith - Microservices on AWS

Frank Munz
October 25, 2019

Breaking the Monolith - Microservices on AWS

Breaking the Monolith. Sam New, Chris Richardson, the Inverse Conway Manoeuvre?

AWS has integrated building blocks that support the development of microservices. Two popular approaches are using AWS Lambda and Docker containers with AWS Fargate.

With AWS Lambda, you simply upload your code and let Lambda take care of everything required to run and scale the execution to meet your actual demand curve with high availability. This means, there is no administration of infrastructure needed. Lambda supports several programming languages and can be triggered from other AWS services or be called directly from any web or mobile application. One of the biggest advantages of AWS Lambda is that you can move quickly: you can focus on your business logic because security and scaling are managed by AWS. Lambda’s opinionated approach drives the scalable platform.

Frank Munz

October 25, 2019
Tweet

More Decks by Frank Munz

Other Decks in Programming

Transcript

  1. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Breaking the Monolith
    Frank Munz
    Sr Technical Evangelist AWS
    D A C H 2 0 1 9
    @frankmunz

    View Slide

  2. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Monoliths and Microservices

    View Slide

  3. Definition of
    microservices
    Microservices are small,
    isolated services, each of
    which is independently
    deployable and owns its
    data

    View Slide

  4. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Structure apps as collections of microservices
    When the impact of change is small,
    release velocity can increase
    Monolithic application
    Does everything
    Shared release pipeline
    Rigid scaling
    High impact of change
    Hard to adopt new technologies
    Microservices
    Does one thing
    Independent deployments
    Independent scaling
    Small impact of change
    Choice of technology

    View Slide

  5. Do not break it.

    View Slide

  6. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    … so again, consider starting
    monolithic first and break
    things out when you’re
    stable. Many of the
    challenges you’re going to
    face with microservices get
    worse with scale. Sam Newman

    View Slide

  7. #7
    “…consider
    starting
    monolithic
    first …“

    View Slide

  8. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Chris Richardson

    View Slide

  9. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Understand performance…
    Systems Performance
    by Brendan Gregg

    View Slide

  10. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Monolith
    Does everything
    Monoliths are OK

    View Slide

  11. Monolith
    • Commit to deployment
    takes too long
    • Codebase too complex for single
    Developer
    • Development is slow (IDE, build,
    startup time)
    • Lock-in with obsolete tech stack
    • Scaling is difficult
    Hell

    View Slide

  12. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    https://martinfowler.com/bliki/MicroservicePrerequisites.html
    Microservices Prerequisites
    These capabilities imply an
    important organizational
    shift - close collaboration
    between developers and
    operations:
    the DevOpsCulture.
    Rapid provisioning
    Basic monitoring
    Rapid application
    deployment

    View Slide

  13. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    Organizational Challenge:
    Conway‘s Law

    View Slide

  14. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Options for Architecting your
    Microservices

    View Slide

  15. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    Options for architecting your microservices
    AWS
    Lambda
    Amazon EKS
    Amazon ECS
    AWS Fargate
    Containers Serverless
    AWS Services
    165+ Services

    View Slide

  16. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Requires
    <= 3 GB
    RAM?
    Yes
    Orchestration
    portability OR
    Kubernetes
    background?
    Amazon EKS
    Yes
    Manage your own
    infrastructure?
    No
    Amazon ECS
    AWS Fargate Yes
    No
    Deployment
    Package size
    <= 50MB
    Service
    runtime <=
    15 minutes?
    Yes Yes
    AWS Lambda
    No
    No No
    Decision Tree – well, almost!
    @sascha242
    AWS Lambda

    View Slide

  17. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Comparison of operational responsibility
    AWS Lambda
    Serverless functions
    AWS Fargate
    Serverless containers
    ECS/EKS
    Container-management as a service
    EC2
    Infrastructure-as-a-Service
    More opinionated
    Less opinionated
    AWS manages Customer manages
    • Data source integrations
    • Physical hardware, software, networking,
    and facilities
    • Provisioning
    • Application code
    • Container orchestration, provisioning
    • Cluster scaling
    • Physical hardware, host OS/kernel,
    networking, and facilities
    • Application code
    • Data source integrations
    • Security config and updates, network config,
    management tasks
    • Container orchestration control plane
    • Physical hardware software,
    networking, and facilities
    • Application code
    • Data source integrations
    • Work clusters
    • Security config and updates, network config,
    firewall, management tasks
    • Physical hardware software,
    networking, and facilities
    • Application code
    • Data source integrations
    • Scaling
    • Security config and updates, network config,
    management tasks
    • Provisioning, managing scaling and
    patching of servers

    View Slide

  18. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    AWS Lambda

    View Slide

  19. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Lambda Layers
    • Share code between functions
    (crosscutting concerns)
    • Promote separation of responsibilities
    • Upload layer once, reference up to 5 layers
    within any function (one can be custom
    runtime)
    • Built in support for secure sharing by
    ecosystem

    View Slide

  20. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Custom Runtimes
    Bring any Linux compatible language
    runtime
    Powered by new Runtime API
    Custom runtimes distributed as “layers”

    View Slide

  21. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Amazon
    Elastic Container Service

    View Slide

  22. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    S U M M I T
    Amazon ECS
    Easiest way to deploy and manage
    containers at scale
    Integration with entire AWS platform
    ALB, Auto Scaling, Batch, Elastic Beanstalk,
    CloudFormation, CloudTrail, CloudWatch
    Events, CloudWatch Logs, CloudWatch
    Metrics, ECR, EC2 Spot, IAM, NLB, Parameter
    Store, and VPC
    Scales to support clusters of any size
    Service integrations (like ALB and NLB) are
    at container level
    1
    2
    3

    View Slide

  23. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    S U M M I T
    ECS EC2 vs. ECS Fargate
    EC2 Fargate
    Managed by Customer AWS
    Storage Ephemeral or Persistent Only Ephemeral
    Sidecar pattern Yes Yes
    Network Mode Bridge or VPC Mode VPC Mode
    Daemons Yes No
    SSH into host Yes No
    Privileged
    Containers
    Yes No

    View Slide

  24. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Infrastructure as Code

    View Slide

  25. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    S U M M I T
    AWS CDK
    Contribute
    Code
    AWS Cloud Development Kit
    Define cloud infrastructure and reusable components in “real
    code“ and provision through AWS CloudFormation
    Stack(s)
    CDK Application
    Construct Construct
    CloudFormation
    template
    Resources

    View Slide

  26. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    S U M M I T
    ECS Pattern: Load Balanced Fargate Service
    Basic constructs:
    Cluster, Task Definition,
    Task, Service, etc.
    Common architecture
    patterns:
    load balanced service
    …this TypeScript generates 568 CloudFormation LOC

    View Slide

  27. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Amazon
    Elastic Kubernetes Service

    View Slide

  28. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    S U M M I T
    “Run Kubernetes for me.”

    View Slide

  29. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    S U M M I T
    Availability
    Zone 1
    Availability
    Zone 2
    Availability
    Zone 3
    Kubectl
    Amazon EKS Architecture
    CloudWatch Container Insights for Amazon EKS and ECS

    View Slide

  30. https://eksctl.io/
    Tip: Easy way to create an EKS cluster:
    $ eksctl create cluster --name meshtest --appmesh-access

    View Slide

  31. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Languages and Frameworks

    View Slide

  32. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Container Base Images

    View Slide

  33. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Go
    • Modern language
    • Docker is implemented
    in Go
    • Native concurrency
    • Low startup time
    • Small, static binaries
    • Easy cross compilation

    View Slide

  34. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Java – Open Source Cloud Native Stacks
    Polyglot, declarative, reactive, microservices frameworks like
    Micronaut or Quarkus based on Graal VM.
    • Dead code eliminiation
    • Aggressive Advance of Time Compliation (AOT)
    • Native image generation
    • Docker and Kubernetes YAML file generation
    • Startup times in milliseconds
    https://quarkus.io/vision/container-first

    View Slide

  35. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Services Meshes

    View Slide

  36. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    OSSC libraries:
    code changes required,
    language specific
    Service Mesh:
    decentral, language agnostic,
    polyglot, light-weight
    https://www.infoq.com/articles/microservices-post-kubernetes
    Need for a Service Mesh

    View Slide

  37. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    App Mesh works across compute services
    Amazon ECS
    AWS Fargate
    Amazon EKS
    Amazon EC2
    Kubernetes on EC2
    Based on Envoy proxy
    It‘s free (you only pay for resources used)
    Helps to migrate from monolith

    View Slide

  38. Mesh – [myapp]
    Virtual
    Node A
    Service
    Discovery
    Backend
    Listener
    Virtual router
    Domains
    action:
    match: /
    B
    B’
    Service B
    Service B’
    Virtual
    Node B’
    Service
    Discovery
    Listener Backends
    Virtual
    Node B
    Service
    Discovery
    Listener Backends
    AWS App Mesh
    EKS
    EC2

    View Slide

  39. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    Demo: Install AppMesh
    # AppMesh Installation with Grafana/Prometheus
    # and Envoy, AWS X-Ray daemon sidecar
    # and StatsD Prometheus exporter
    $ helm install -n aws-appmesh \
    --namespace appmesh-system \
    https://github.com/PaulMaddox/ \
    aws-appmesh-helm/releases/ \
    latest/download/aws-appmesh.tgz
    https://github.com/PaulMaddox/aws-appmesh-helm

    View Slide

  40. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    Install Demo App
    # create namespace & enable auto-injection
    $ kubectl create ns appmesh-demo
    $ kubectl label namespace appmesh-demo
    appmesh.k8s.aws/sidecarInjectorWebhook=enabled
    # deploy the demo
    $ helm install -n aws-appmesh-demo \
    --namespace appmesh-demo \
    https://github.com/.../aws-appmesh-demo.tgz

    View Slide

  41. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Strangle the Monolith

    View Slide

  42. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Strangler Pattern

    View Slide

  43. Strangler Pattern Part I
    • Work incrementally
    • Law of holes: Implement new features as services
    • Separate presentation tier from backend
    • Decouple business capabilites into services, not code.
    -> IKEA effect
    • Choose services that give greatest benefit:
    • Accelerate development
    • Solve performance, scalability or reliability problem

    View Slide

  44. Strangler Pattern Part II
    • Splitting the domain model (class references become PKs)
    • Refactoring the database (Split Table refactoring, use data
    replication to avoid larger changes )
    • API GW or service mesh and „glue code“
    • Dependencies from monolith to strangler is preferred direction
    (if „buy“ uses „promotion“, then decouple promotion first)
    • Distributed database TXs become SAGAs
    • Stop doing this at some point. https://microservices.io≈

    View Slide

  45. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    Monolith and
    Strangler App
    https://microservices.io

    View Slide

  46. Thank you!
    © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    frankmunz
    @frankmunz https://medium.com/@frank.munz
    (Blog)
    https://speakerdeck.com/fmunz
    (Slides)

    View Slide

  47. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    Deep Dive on Containers
    https://www.youtube.com/watch?v=OYPGRMEdH9M

    View Slide

  48. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    Open-source Istio and Enovy on AWS EKS
    https://www.youtube.com/watch?v=fDmJf9kWFws

    View Slide