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

Breaking the Monolith: road to containerizing/...

Breaking the Monolith: road to containerizing/serverless your app

Following simple patterns of good application design can allow you to scale your application for your customers easily. We'll dive into the 12 factor application design and demo how this applies to containers and deployments on Amazon ECS and Fargate. We'll take a look at tooling that can be used to simplfy your work flow and help you adopt the principles of the 12 factor application.

More Decks by Sébastien Stormacq - AWS Developer Advocate

Other Decks in Technology

Transcript

  1. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 0 4 . 0 3 . 2 0 1 9 O S L O
  2. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. O S L O 0 4 . 0 3 . 2 0 1 9 Breaking the Monolith Modern Application Design with Containers and the 12 factors app Sébastien Stormacq Technical Evangelist, AWS @sebsto #AWSDevDay M A D 4
  3. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Best Software Architecture Practices Use declarative formats for setup automation, to minimize time and cost for new developers joining the project; Have a clean contract with the underlying operating system, offering maximum portability between execution environments; Are suitable for deployment on modern cloud platforms, obviating the need for servers and systems administration; Minimize divergence between development and production, enabling continuous deployment for maximum agility; And can scale up without significant changes to tooling, architecture, or development practices.
  4. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. The 12 factor application I. Codebase One codebase w/ revision control, many deploys II. Dependencies Explicitly declare and isolate dependencies III. Config Store config in the environment IV. Backing services Treat backing services as attached resources V. Build, release, run Strictly separate build and run stages VI. Processes Execute the app as one or more stateless processes VII. Port binding Export services via port binding VIII. Concurrency Scale out via the process model IX. Disposability Fast startup and graceful shutdown X. Dev/prod parity Keep environments as similar as possible XI. Logs Treat logs as event streams XII. Admin processes Run admin/management tasks as one-off processes
  5. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. You know what’s great for a 12 factor app?
  6. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. RUNNING A SINGLE CONTAINER
  7. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. EC2 Instance Task Task Task Task EC2 Instance Task Task Task Task EC2 Instance Task Task Task Task EC2 Instance Task Task Task Task EC2 Instance Task Task Task Task RUNNING CONTAINERS
  8. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. RUNNING CONTAINERS AT SCALE WITH ECS Availability Zone #1 Availability Zone #2 Availability Zone #3 Scheduling and Orchestration Cluster Manager Placement Engine
  9. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ECS AMI Docker agent ECS agent ECSTask ECSTask ECSTask ECSTask EC2 Instance
  10. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ECS AMI Docker agent ECS agent EC2 Instance ECS AMI Docker agent ECS agent EC2 Instance ECS AMI Docker agent ECS agent EC2 Instance Scheduling and Orchestration Cluster Manager Placement Engine
  11. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. “Just launch 10 copies of my container distributed across three availability zones and connect them to this load balancer” X 10
  12. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. One codebase tracked in revision control, many deploys
  13. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Staging / QA Production Dev #1 Dev #2
  14. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Explicitly declare and isolate dependencies
  15. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Dependencies Dependencies Binaries Code
  16. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Store config in the environment
  17. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Treat backing services as attached resources
  18. PostgreSQL app1 app2 Load balancer Use CNAMES for maximum flexibility

    and easy reconfiguration postgres.mycompany.com app2.mycompany.com
  19. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Strictly separate build and run stages
  20. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Execute the app as one or more stateless processes
  21. Stateful container stores state in local disk or local memory.

    Workload ends up tied to a specific host that has state data. eu-west-1b Container 1 Disk eu-west-1c eu-west-1a
  22. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Stateful data Use services: • Amazon RDS • Amazon DynamoDB • Amazon ElasticCache • Amazon ElasticSearch • Amazon S3 • ……
  23. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Export services via port binding
  24. Port 32768 Port 33487 Port 32192 Port 32794 Port 32781

    Match: /api/users* Match: /api/auth*
  25. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Scale out via the process model
  26. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. RUNNING CONTAINERS AT SCALE WITH ECS Availability Zone #1 Availability Zone #2 Availability Zone #3 Scheduling and Orchestration Cluster Manager Placement Engine
  27. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Scaling Instance Container 1 Instance Instance Instance Instance Instance + Container 1 Container 1 Container 1 Container 1 Container 1
  28. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Maximize robustness with fast startup and graceful shutdown
  29. Fast Launch Minimize the startup time of processes: • Scale

    up faster in response to spikes • Ability to move processes to another host as needed • Replace crashed processes faster
  30. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Keep development, staging, and production as similar as possible
  31. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Dev #1 Dev #2 Staging / QA Production
  32. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Staging / QA Production Dev #1 Dev #2 Local Application Remote
  33. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Treat logs as event streams
  34. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. CLOUDWATCH LOGS CONFIGURATION Use the awslogs driver to send stdout from your application to Cloudwatch logs Create a log group in Cloudwatch Configure the log driver in your task definition Remember to add permissions via the Task Execution Role { "family": "scorekeep", ... "containerDefinitions": [ { "name":“scorekeep-frontend", ... "logConfiguration": { "logDriver": "awslogs", "options": { "awslogs-group": "scorekeep", "awslogs-region": “us-east-1", "awslogs-stream-prefix": "scorekeep/frontend“}} }, { "name":“scorekeep-api", ... "logConfiguration": { "logDriver": "awslogs", "options": { "awslogs-group": "scorekeep", "awslogs-region": “us-east-1", "awslogs-stream-prefix": "scorekeep/api"}} } ]} Task Definition
  35. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. CLOUDWATCH LOGS Logs Tab in the Task Detail Page View logs in the ECS or Cloudwatch Console
  36. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Run admin/management tasks as one-off processes
  37. Admin / management processes are inevitable: • Migrate database •

    Repair some broken data • Once a week move database records older than X to cold storage • Every day email a report to this person
  38. Building Blocks for Containerized 12 Factor apps Compute Developer Tools

    Logging & Monitoring Storage & Database Networking & API Proxy AWS Elastic Beanstalk AWS Fargate Amazon ECS Amazon DynamoDB Amazon S3 Amazon ElastiCache Amazon RDS Amazon ECR Amazon EKS AWS X-Ray AWS CodeBuild AWS CodePipeline AWS Cloud9 Amazon CloudWatch AWS CloudTrail Amazon SQS Amazon SNS Amazon MQ Amazon API Gateway Elastic Load Balancing Amazon Route 53 AWS Step Functions
  39. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Sébastien Stormacq Technical Evangelist, AWS @sebsto