Slide 1

Slide 1 text

Compute Evolved Week Building Microservices with the 12 Factor App Pattern on AWS Nathan Peck Developer Advocate, Container Services

Slide 2

Slide 2 text

12 Factor App Principles Microservice Principles Great, Scalable Architecture + =

Slide 3

Slide 3 text

12 Factor Application: Codebase

Slide 4

Slide 4 text

Code

Slide 5

Slide 5 text

Code Version Control

Slide 6

Slide 6 text

Code Deployed Version Version Control

Slide 7

Slide 7 text

Staging / QA Production Dev #1 Dev #2

Slide 8

Slide 8 text

12 Factor Application: Dependencies

Slide 9

Slide 9 text

Dependencies Binaries Code Application Bundle

Slide 10

Slide 10 text

Dependency Declaration: Node.js package.json npm install

Slide 11

Slide 11 text

Dependency Declaration: Python requirements.txt pip install

Slide 12

Slide 12 text

Dependency Declaration: Ruby Gemfile bundle install

Slide 13

Slide 13 text

Dependency Isolation Never depend on the host to have your dependency. Application deployments should carry all their dependencies with them.

Slide 14

Slide 14 text

Dependencies Binaries Code

Slide 15

Slide 15 text

Dependency Declaration & Isolation: Docker docker build Dockerfile

Slide 16

Slide 16 text

Development Production docker run

Slide 17

Slide 17 text

12 Factor Application: Config

Slide 18

Slide 18 text

Development Configuration Production Configuration Development Production

Slide 19

Slide 19 text

Development Configuration Production Configuration Development Production ANTIPATTERN

Slide 20

Slide 20 text

Development Production Same container deployed to both environments. Configuration is part of the environment on the host.

Slide 21

Slide 21 text

At runtime the container gets config from the environment.

Slide 22

Slide 22 text

Application code pulls from the environment Environment is customized when docker runs a container

Slide 23

Slide 23 text

12 Factor Application: Backing Services

Slide 24

Slide 24 text

AWS S3 PostgreSQL app1 Host app2 3rd party service Treat local services just like remote third party ones

Slide 25

Slide 25 text

PostgreSQL app1 app2 postgres.mycompany.com app2.mycompany.com Load balancer Use CNAMES for maximum flexibility and reconfigurability

Slide 26

Slide 26 text

12 Factor Application: Build, Release, Run

Slide 27

Slide 27 text

Dependencies Binaries Code Build

Slide 28

Slide 28 text

Release Config + = Release Build Artifact

Slide 29

Slide 29 text

Amazon Elastic Container Service Config

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

12 Factor Application: Stateless Processes

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

Database Durable store of truth. MySQL, PostgreSQL, MongoDB, DynamoDB Cache Fast, temporary state store. redis, memcached

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

12 Factor Application: Port Binding

Slide 37

Slide 37 text

Port 32456 Port 32457 Port 32458

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

12 Factor Application: Concurrency

Slide 40

Slide 40 text

Web API Worker

Slide 41

Slide 41 text

Worker Web API

Slide 42

Slide 42 text

Hosts Processes

Slide 43

Slide 43 text

Hosts Processes

Slide 44

Slide 44 text

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

Slide 45

Slide 45 text

12 Factor Application: Disposability

Slide 46

Slide 46 text

Responsive Graceful Shutdown Fast Launch

Slide 47

Slide 47 text

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

Slide 48

Slide 48 text

Responsive, Graceful Shutdown Should respond to SIGTERM by shutting down gracefully

Slide 49

Slide 49 text

12 Factor Application: Dev/Prod Parity

Slide 50

Slide 50 text

Staging / QA Production Dev #1 Dev #2

Slide 51

Slide 51 text

Staging / QA Production Dev #1 Dev #2 Local Application Remote

Slide 52

Slide 52 text

12 Factor Application: Logs

Slide 53

Slide 53 text

Treat logs as an event stream, and keep the logic for routing and processing logs separate from the application itself.

Slide 54

Slide 54 text

Logging Library Application Code Process

Slide 55

Slide 55 text

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

Slide 56

Slide 56 text

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

Slide 57

Slide 57 text

Processes Logging Agent Application Code Logs go to an agent which handles exporting them off the host

Slide 58

Slide 58 text

Processes Logging Agent Application Code Logs still reach agent, and still make it into ELK stack

Slide 59

Slide 59 text

Containerized code writes to stdout Docker connects container’s stdout to a log driver

Slide 60

Slide 60 text

12 Factor Application: Admin Processes

Slide 61

Slide 61 text

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

Slide 62

Slide 62 text

Run admin processes just like other processes.

Slide 63

Slide 63 text

Microservices: Componentization

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

Each component is a 12 factor application. Fast Launch Dependencies Configuration Port Binding Codebase Concurrent Graceful stop Log stream Stateless

Slide 66

Slide 66 text

Microservices: Organized around capabilities

Slide 67

Slide 67 text

Identify the capabilities of the platform

Slide 68

Slide 68 text

Each major capability of the platform becomes a component that is its own 12 factor app

Slide 69

Slide 69 text

Microservices: Decentralized Governance

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

Microservices: Products Not Projects

Slide 74

Slide 74 text

Products grow over time

Slide 75

Slide 75 text

Microservices are an ecosystem of connected products that can be at different stages of growth

Slide 76

Slide 76 text

Don’t create throwaway microservices that become unmaintained and break the ecosystem.

Slide 77

Slide 77 text

Microservices: Smart endpoints, Dumb pipes

Slide 78

Slide 78 text

Central bus for communication Bottlenecks performance and feature development

Slide 79

Slide 79 text

Central bus for communication Bottlenecks performance and feature development

Slide 80

Slide 80 text

Decentralization

Slide 81

Slide 81 text

Example: User Signup Signup API HTTP User Metadata Service Password Service Email Verification Service Friend Discovery Service Asynchronous Broadcast

Slide 82

Slide 82 text

Event Producers Subscriptions Event Topics Queues Event Consumers

Slide 83

Slide 83 text

Amazon Managed Service for Microservice Communication

Slide 84

Slide 84 text

Microservices: Infrastructure Automation

Slide 85

Slide 85 text

Automate the container build process: Jenkins AWS CodeBuild

Slide 86

Slide 86 text

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

Slide 87

Slide 87 text

Developers Version Control Repository Test & Deployment Manager Image Build Service Infrastructure Provisioning Container Scheduling & Orchestration Container Image Repository

Slide 88

Slide 88 text

Developers AWS CodeCommit AWS CodePipeline AWS CodeBuild AWS CloudFormation Amazon ECS Amazon ECR

Slide 89

Slide 89 text

Developers Github Jenkins Terraform Container Scheduling & Orchestration with Kubernetes Container Image Repository

Slide 90

Slide 90 text

Summary

Slide 91

Slide 91 text

12 factor application principles Fast Launch Dependencies Configuration Port Binding Codebase Concurrent Graceful stop Log stream Stateless

Slide 92

Slide 92 text

Microservice principles Automation Componentization Product Focused Decentralization

Slide 93

Slide 93 text

Thank you! [email protected] nathankpeck nathanpeck