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

Building Microservices with the 12 Factor App Pattern on AWS

Ec0eef36125ca5f0ac028d36cec9bd4e?s=47 Nathan Peck
December 13, 2017

Building Microservices with the 12 Factor App Pattern on AWS

The 12 factor app pattern is a set of principles for building a modern, scalable application that operates reliably and integrates well with other applications.

Microservices are an architectural approach that allows an organization to build complex infrastructure out of smaller, more simple distributed application components that enable parallelization of development effort.

Combining 12 factor principles with microservices allows an organization to create a massively scaleable software solution that will operate well.

Ec0eef36125ca5f0ac028d36cec9bd4e?s=128

Nathan Peck

December 13, 2017
Tweet

More Decks by Nathan Peck

Other Decks in Technology

Transcript

  1. Compute Evolved Week Building Microservices with the 12 Factor App

    Pattern on AWS Nathan Peck Developer Advocate, Container Services
  2. 12 Factor App Principles Microservice Principles Great, Scalable Architecture +

    =
  3. 12 Factor Application: Codebase

  4. Code

  5. Code Version Control

  6. Code Deployed Version Version Control

  7. Staging / QA Production Dev #1 Dev #2

  8. 12 Factor Application: Dependencies

  9. Dependencies Binaries Code Application Bundle

  10. Dependency Declaration: Node.js package.json npm install

  11. Dependency Declaration: Python requirements.txt pip install

  12. Dependency Declaration: Ruby Gemfile bundle install

  13. Dependency Isolation Never depend on the host to have your

    dependency. Application deployments should carry all their dependencies with them.
  14. Dependencies Binaries Code

  15. Dependency Declaration & Isolation: Docker docker build Dockerfile

  16. Development Production docker run

  17. 12 Factor Application: Config

  18. Development Configuration Production Configuration Development Production

  19. Development Configuration Production Configuration Development Production ANTIPATTERN

  20. Development Production Same container deployed to both environments. Configuration is

    part of the environment on the host.
  21. At runtime the container gets config from the environment.

  22. Application code pulls from the environment Environment is customized when

    docker runs a container
  23. 12 Factor Application: Backing Services

  24. AWS S3 PostgreSQL app1 Host app2 3rd party service Treat

    local services just like remote third party ones
  25. PostgreSQL app1 app2 postgres.mycompany.com app2.mycompany.com Load balancer Use CNAMES for

    maximum flexibility and reconfigurability
  26. 12 Factor Application: Build, Release, Run

  27. Dependencies Binaries Code Build

  28. Release Config + = Release Build Artifact

  29. Amazon Elastic Container Service Config

  30. Task Definition Release v1.0.0 Run Task Definition Release v1.0.1

  31. 12 Factor Application: Stateless Processes

  32. Stateful container stores state in local disk or local memory.

    Workload ends up tied to a specific host that has state data.
  33. Stateful container stores state in local disk or local memory.

    Workload ends up tied to a specific host that has state data. ANTIPATTERN
  34. Database Durable store of truth. MySQL, PostgreSQL, MongoDB, DynamoDB Cache

    Fast, temporary state store. redis, memcached
  35. None
  36. 12 Factor Application: Port Binding

  37. Port 32456 Port 32457 Port 32458

  38. None
  39. 12 Factor Application: Concurrency

  40. Web API Worker

  41. Worker Web API

  42. Hosts Processes

  43. Hosts Processes

  44. Large Host = More Concurrent Processes Small Host = Fewer

    Concurrent Processes
  45. 12 Factor Application: Disposability

  46. Responsive Graceful Shutdown Fast Launch

  47. 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
  48. Responsive, Graceful Shutdown Should respond to SIGTERM by shutting down

    gracefully
  49. 12 Factor Application: Dev/Prod Parity

  50. Staging / QA Production Dev #1 Dev #2

  51. Staging / QA Production Dev #1 Dev #2 Local Application

    Remote
  52. 12 Factor Application: Logs

  53. Treat logs as an event stream, and keep the logic

    for routing and processing logs separate from the application itself.
  54. Logging Library Application Code Process

  55. Logging Library Application Code Process Some logs get lost if

    they haven’t fully flushed
  56. Logging Library Application Code Process Some logs get lost if

    they haven’t fully flushed ANTIPATTERN
  57. Processes Logging Agent Application Code Logs go to an agent

    which handles exporting them off the host
  58. Processes Logging Agent Application Code Logs still reach agent, and

    still make it into ELK stack
  59. Containerized code writes to stdout Docker connects container’s stdout to

    a log driver
  60. 12 Factor Application: Admin Processes

  61. 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
  62. Run admin processes just like other processes.

  63. Microservices: Componentization

  64. None
  65. Each component is a 12 factor application. Fast Launch Dependencies

    Configuration Port Binding Codebase Concurrent Graceful stop Log stream Stateless
  66. Microservices: Organized around capabilities

  67. Identify the capabilities of the platform

  68. Each major capability of the platform becomes a component that

    is its own 12 factor app
  69. Microservices: Decentralized Governance

  70. None
  71. None
  72. None
  73. Microservices: Products Not Projects

  74. Products grow over time

  75. Microservices are an ecosystem of connected products that can be

    at different stages of growth
  76. Don’t create throwaway microservices that become unmaintained and break the

    ecosystem.
  77. Microservices: Smart endpoints, Dumb pipes

  78. Central bus for communication Bottlenecks performance and feature development

  79. Central bus for communication Bottlenecks performance and feature development

  80. Decentralization

  81. Example: User Signup Signup API HTTP User Metadata Service Password

    Service Email Verification Service Friend Discovery Service Asynchronous Broadcast
  82. Event Producers Subscriptions Event Topics Queues Event Consumers

  83. Amazon Managed Service for Microservice Communication

  84. Microservices: Infrastructure Automation

  85. Automate the container build process: Jenkins AWS CodeBuild

  86. Automate the provisioning of the servers that host microservice containers:

    Terraform, Ansible, Amazon CloudFormation Automate the placement of containerized service processes onto hosts: Amazon Elastic Container Service, Kubernetes, Docker Swarm
  87. Developers Version Control Repository Test & Deployment Manager Image Build

    Service Infrastructure Provisioning Container Scheduling & Orchestration Container Image Repository
  88. Developers AWS CodeCommit AWS CodePipeline AWS CodeBuild AWS CloudFormation Amazon

    ECS Amazon ECR
  89. Developers Github Jenkins Terraform Container Scheduling & Orchestration with Kubernetes

    Container Image Repository
  90. Summary

  91. 12 factor application principles Fast Launch Dependencies Configuration Port Binding

    Codebase Concurrent Graceful stop Log stream Stateless
  92. Microservice principles Automation Componentization Product Focused Decentralization

  93. Thank you! peckn@amazon.com nathankpeck nathanpeck