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

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
  2. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Monoliths and Microservices
  3. Definition of microservices Microservices are small, isolated services, each of

    which is independently deployable and owns its data
  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
  5. © 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
  6. © 2019, Amazon Web Services, Inc. or its affiliates. All

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

    rights reserved. Monolith Does everything Monoliths are OK
  8. 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
  9. © 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
  10. © 2018, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Organizational Challenge: Conway‘s Law
  11. © 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
  12. © 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
  13. © 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
  14. © 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
  15. © 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
  16. © 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”
  17. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Elastic Container Service
  18. © 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
  19. © 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
  20. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Infrastructure as Code
  21. © 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
  22. © 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
  23. © 2019, Amazon Web Services, Inc. or its affiliates. All

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

    rights reserved. S U M M I T “Run Kubernetes for me.”
  25. © 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
  26. https://eksctl.io/ Tip: Easy way to create an EKS cluster: $

    eksctl create cluster --name meshtest --appmesh-access
  27. © 2019, Amazon Web Services, Inc. or its affiliates. All

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

    rights reserved. Container Base Images
  29. © 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
  30. © 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
  31. © 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
  32. © 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
  33. 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
  34. © 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
  35. © 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
  36. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Strangle the Monolith
  37. 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
  38. 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≈
  39. © 2019, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Monolith and Strangler App https://microservices.io
  40. 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)
  41. © 2018, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Deep Dive on Containers https://www.youtube.com/watch?v=OYPGRMEdH9M
  42. © 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