Upload
casey-lee
View
82
Download
5
Embed Size (px)
Citation preview
Deploying Microservices as Containers on AWS
Casey Lee, Senior DevOps Engineer, Stelligent
www.stelligent.com 2
Workshop Goals
Microservice
Principles
Monolith
Decomposition
Containers &
Continuous Delivery
mu
www.stelligent.com 3
Agenda
8:30 - 9:00 - Breakfast and registration
9:00 - 9:30 - Microservice principles and introduction to mu on AWS
9:30 - 10:00 - Lab 1: microservice deployment
10:00 - 10:15 - Lab 2: microservice testing
10:15 - 10:30 - Break
10:30 - 11:00 - Decomposing the monolith into microservices
11:00 - 11:45 - Lab 3: service discovery for microservices
11:45 - 12:00 - Wrap-up
www.stelligent.com 4
Workshop Goals
Microservice
Principles
Monolith
Decomposition
Containers &
Continuous Delivery
mu
www.stelligent.com
What’s wrong with my monolith?
5
www.stelligent.com
DEPLOYMENT PIPELINE
FEEDBACK LOOP
plan monitor
build test release
Developers Customers
Based on http://www.slideshare.net/AmazonWebServices/dvo202-devops-at-amazon-a-look-at-our-tools-processes
www.stelligent.com
Team coupling affects agility
Monolith Challenges
7
Code
Monolith
Code
Code
Daily
Weekly
Monthly
www.stelligent.com
Deployment coupling affects availability
Monolith Challenges
8
Code
Monolith
Code
Code
Code
Monolith
Code
Code
www.stelligent.com
How do microservices help?
9
www.stelligent.com 10
MICROSERVICES
“Small, autonomous services
that work together.”
-SAM NEWMAN, 2014
www.stelligent.com 11
SINGLE RESPONSIBILITY
PRINCIPLE
“A class should have only
one reason to change.”
-ROBERT C. MARTIN, circa 2003
www.stelligent.com
THE UNIX PHILOSOPHY
“Write programs that do one
thing and do it well. Write
programs to work together.”
-DOUG MCILROY, circa 1978
12
www.stelligent.com 13
MICROSERVICES
“Small, autonomous services
that work together.”
-SAM NEWMAN, 2014
www.stelligent.com
Team autonomy
Microservice Principles
14
Code
Microservice
Code
Microservice
Code
Microservice
www.stelligent.com
Independent deployments
Microservice Principles
15
Code
Microservice
Code
Microservice
Code
Microservice
Code
Microservice
www.stelligent.com
Public APIs
Microservice Principles
16
Code
Microservice
Code
Microservice
Code
Microservice
www.stelligent.com
Private implementations
Microservice Principles
17
Code
Microservice
Code
Microservice
Code
Microservice
DB
DB
www.stelligent.com 18
Workshop Goals
Microservice
Principles
Monolith
Decomposition
Containers &
Continuous Delivery
mu
www.stelligent.com
How do I manage?
19
http://www.slideshare.net/AmazonWebServices/devops-at-amazon-a-look-at-our-tools-and-processes-50364582
http://www.slideshare.net/AmazonWebServices/devops-at-amazon-a-look-at-our-tools-and-processes-50364582
http://www.slideshare.net/AmazonWebServices/devops-at-amazon-a-look-at-our-tools-and-processes-50364582
www.stelligent.com
Continuous Delivery Fundamentals
Continuous =
Every change triggers the feedback process
“If it hurts, do it more often!”
-Martin Fowler, ThoughtWorks
www.stelligent.com
Continuous Delivery Fundamentals
Quality = Build it into the product
“Cease dependence on mass inspection to
achieve quality. Improve the process and build
quality into the product in the first place”
-W. Edwards Deming
www.stelligent.com
Continuous Delivery Fundamentals
Automated = Releasing software should be repeatable and reliable
“Deployments ought to be a boring, push-
button experience”
-Jez Humble
www.stelligent.com
Pipeline
http://xebia.github.io/cd-with-docker/#/2
http://www.slideshare.net/AmazonWebServices/devops-at-amazon-a-look-at-our-tools-and-processes-50364582
www.stelligent.com
Containers
https://www.docker.com/what-docker
www.stelligent.com
Container Benefits - Cost
www.stelligent.com
Container Benefits - Speed
EC2 ECS
3 minutes 12 seconds 34 seconds
www.stelligent.com 31
Microservices
Continuous
Delivery
Containers Monolith
www.stelligent.com 32
Workshop Goals
Microservice
Principles
Monolith
Decomposition
Containers &
Continuous Delivery
mu
www.stelligent.com
www.stelligent.com 34
Amazon ECRAmazon ECS
Amazon
EC2
Amazon
VPC
router
VPC NAT
gateway
Auto ScalingApplication
Load Balancer
Elastic Load
Balancing
MySQL DB
instance
Amazon
RDSAWS
CodeCommit
AWS
CodePipeline
AWS
CodeBuild
Amazon
CloudWatchAWS
CloudFormation
alarm
IAM
rolestack
virtual private cloud
ECR registryEC2 compute
container
template
www.stelligent.com 35
http://getmu.io
www.stelligent.com 36
www.stelligent.com
Overview
37
www.stelligent.com
Pipelines
38
www.stelligent.com
Environment
39
www.stelligent.com
Service
40
www.stelligent.com
Service #2
41
www.stelligent.com 42
Lab 1 -Spring Boot Service
https://github.com/stelligent/mu-workshop-lab1
www.stelligent.com 43
Lab 2 -Test Automation
https://github.com/stelligent/mu-workshop-lab2
www.stelligent.com
Break
www.stelligent.com 45
Workshop Goals
Microservice
Principles
Monolith
Decomposition
Containers &
Continuous Delivery
mu
www.stelligent.com
How do I decompose my monolith?
46
www.stelligent.com 47
The Challenge
User Experience
Business Services
Data Access Layer
From thick, layered architecture To small, autonomous services
Decomposition Process
• Start with functionality and
capabilities, NOT the data.
• Look at capabilities outside
in. Model services from
customer perspective.
• Avoid anemic CRUD
services.
1. Capabilities Decomposition 2. Data Decomposition 3. Deployment Decomposition
• The capabilities drive the
data decomposition.
• Additional services based
on data access
decomposition
• Data needs to be owned
exclusively by SINGLE
service
• Separating services into
distinct deployables
• Expose APIs
• Decide on integration
methods
Step 1 - Capability Cohesion
Code Order Code
Monolith ServiceMonolith Service
Customer Code
Monolith DB
Monolith DB
49
Bounded Context
Factor out Bounded Contextinto separate packages
Finding Seams
“A seam is a place where you can alter behavior in your program without editing in that place.”
-Eric Evans, Domain-Driven Design
Finding Seams
Finding Seams
The Anti-Corruption Layer Pattern
Order
Microservice
Account
Microservice
Shipping
Microservice
Monolith
Database
Monolith Application
Order
ACL
Account
ACL
Shipping
ACL
Application Layer
Data Access Layer
DAO Layer, etc.
json
xml
json
java
xml
csv
• Each Anti-Corruption Layer (ACL) – Translates from New Domain Model to Monolith Domain Model– Prevents corruption of either domain model– Often implemented using the Façade and/or Adapter pattern– Can be built inside or outside the monolith
Step 2 - Data Cohesion
Order Code
Monolith Service
Customer Code
Order Code
Monolith Service
Customer Code
Monolith DB
OrderDB
CustomerDB
55
Encapsulate Data
Foreign Key? Use the service to access data
Order
OrderDB
CustomerDB
Order Customer
OrderDB
CustomerDB
Encapsulate Data
Shared Data? Create a 3rd service
Address
OrderCustomer
Encapsulate Data
Single Table? Split table into two
Order Customer
Event Based and Eventual Consistency
Order Customer
CustomerDB
Topic
OrderDB
POST /Orders
(including address change)
Step 3 - Deployment Cohesion
Order Code
Microservice
Customer Code
OrderDB
CustomerDB
Order Code
Monolith Service
Customer Code
OrderDB
CustomerDB
Microservice
60
Separate Deployments
Order Code
Microservice
Customer Code
Microservice
Expose API
Separate Deployments
Independent CD Pipelines
CompileUnitTest
Package DeployE2ETest
ProdOrder
CompileUnitTest
Package DeployE2ETest
ProdCustomer
Contract Tests
www.stelligent.com
How do I integrate these services?
63
www.stelligent.com
Database Integration Anti-pattern
Order Customer
CustomerDB
• Tight coupling – DB changes require changes in both services.
• Weak Cohesion – Customer DB code exists in multiple places.
• Availability – High DB load from one service will impact the other service.
The benefits…
The challenges…
• Simple – Seems easier and quicker to start.
www.stelligent.com
Synchronous Integration
Order Customer
CustomerDB
• Loose Coupling – Customer service can change independent from Order service.
• Strong Cohesion – Customer DB code exists in one place.
• Strong Consistency – Order service can react to downstream failures.
The benefits…
The challenges…
• Availability – Care must be taken to avoid cascading failures (circuit breakers)
• Contracts – API contract changes must be versioned to maintain loose coupling.
www.stelligent.com
Synchronous Integration
Order Customer
CustomerDB
2
Versioned API
• Decouple Change• Single Deployable
1
www.stelligent.com
Synchronous Integration
Order Customer
CustomerDB
Circuit Breaker
• Degrade Gracefully• Shed Load• Recover Quickly
www.stelligent.com
Asynchronous Integration
Order Customer
CustomerDB
Queue
Dead Letter Queue
• Handle Downstream Failures• Restore Consistency
Dead LetterQueue
Cleanup Job
www.stelligent.com
Event-driven Architecture
Order Customer
CustomerDB
• Loose Coupling – Customer service can change independent from Order service.
• Strong Cohesion – Customer DB code exists in one place.
• Availability – Order service is not impacted by Customer service degradation.
The benefits…
The challenges…
• Eventual Consistency – Care must be taken to achieve consistency in failure conditions
• Contracts – API contract changes must be versioned to maintain loose coupling.
Topic
www.stelligent.com
Orchestration vs. Choreography
Order Submission
Payment
Fulfillment
Notification
Order Submission
Payment
Fulfillment
Notification
www.stelligent.com
HATEOAS
Order Customer
• Loose coupling – Customer service URLs can change without changing client App.
The benefits…
The challenges…
• Complexity – Requires discipline to enforce link traversal in clients.
Client App
1) GET /orders/123
2) Order (with Customer link)
3) GET /customers/456
www.stelligent.com
Lab 3 -Service Discovery
72
https://github.com/stelligent/mu-workshop-lab3
www.stelligent.com 73
Summary
Microservice
Principles
Monolith
Decomposition
Containers &
Continuous Delivery
mu
www.stelligent.com 74
Next Steps
• Try mu - https://getmu.io/
• Get support - https://gitter.im/stelligent/mu
• Contribute - https://github.com/stelligent/mu/blob/develop/CONTRIBUTING.md
www.stelligent.com
Resources
• Building Microservices, Sam Newman - http://shop.oreilly.com/product/0636920033158.do
• The DevOps Handbook, Gene Kim/Jez Humble/Patrick Debois/John Willis -http://itrevolution.com/devops-handbook
• mu - https://getmu.io/
75
For more information on how Stelligent can help you with AWS Automation, go to www.stelligent.com
Q&A