workshop: microservices as containers on aws

76
Deploying Microservices as Containers on AWS Casey Lee, Senior DevOps Engineer, Stelligent

Upload: casey-lee

Post on 28-Jan-2018

82 views

Category:

Internet


5 download

TRANSCRIPT

Page 1: WORKSHOP: Microservices as Containers on AWS

Deploying Microservices as Containers on AWS

Casey Lee, Senior DevOps Engineer, Stelligent

Page 2: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com 2

Workshop Goals

Microservice

Principles

Monolith

Decomposition

Containers &

Continuous Delivery

mu

Page 3: WORKSHOP: Microservices as Containers on AWS

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

Page 4: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com 4

Workshop Goals

Microservice

Principles

Monolith

Decomposition

Containers &

Continuous Delivery

mu

Page 5: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com

What’s wrong with my monolith?

5

Page 6: WORKSHOP: Microservices as Containers on AWS

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

Page 7: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com

Team coupling affects agility

Monolith Challenges

7

Code

Monolith

Code

Code

Daily

Weekly

Monthly

Page 8: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com

Deployment coupling affects availability

Monolith Challenges

8

Code

Monolith

Code

Code

Code

Monolith

Code

Code

Page 9: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com

How do microservices help?

9

Page 10: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com 10

MICROSERVICES

“Small, autonomous services

that work together.”

-SAM NEWMAN, 2014

Page 11: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com 11

SINGLE RESPONSIBILITY

PRINCIPLE

“A class should have only

one reason to change.”

-ROBERT C. MARTIN, circa 2003

Page 12: WORKSHOP: Microservices as Containers on AWS

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

Page 13: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com 13

MICROSERVICES

“Small, autonomous services

that work together.”

-SAM NEWMAN, 2014

Page 14: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com

Team autonomy

Microservice Principles

14

Code

Microservice

Code

Microservice

Code

Microservice

Page 15: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com

Independent deployments

Microservice Principles

15

Code

Microservice

Code

Microservice

Code

Microservice

Code

Microservice

Page 16: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com

Public APIs

Microservice Principles

16

Code

Microservice

Code

Microservice

Code

Microservice

Page 17: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com

Private implementations

Microservice Principles

17

Code

Microservice

Code

Microservice

Code

Microservice

DB

DB

Page 18: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com 18

Workshop Goals

Microservice

Principles

Monolith

Decomposition

Containers &

Continuous Delivery

mu

Page 19: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com

How do I manage?

19

Page 20: WORKSHOP: Microservices as Containers on AWS

http://www.slideshare.net/AmazonWebServices/devops-at-amazon-a-look-at-our-tools-and-processes-50364582

Page 21: WORKSHOP: Microservices as Containers on AWS

http://www.slideshare.net/AmazonWebServices/devops-at-amazon-a-look-at-our-tools-and-processes-50364582

Page 22: WORKSHOP: Microservices as Containers on AWS

http://www.slideshare.net/AmazonWebServices/devops-at-amazon-a-look-at-our-tools-and-processes-50364582

Page 23: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com

Continuous Delivery Fundamentals

Continuous =

Every change triggers the feedback process

“If it hurts, do it more often!”

-Martin Fowler, ThoughtWorks

Page 24: WORKSHOP: Microservices as Containers on AWS

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

Page 25: WORKSHOP: Microservices as Containers on AWS

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

Page 26: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com

Pipeline

http://xebia.github.io/cd-with-docker/#/2

Page 27: WORKSHOP: Microservices as Containers on AWS

http://www.slideshare.net/AmazonWebServices/devops-at-amazon-a-look-at-our-tools-and-processes-50364582

Page 28: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com

Containers

https://www.docker.com/what-docker

Page 29: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com

Container Benefits - Cost

Page 30: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com

Container Benefits - Speed

EC2 ECS

3 minutes 12 seconds 34 seconds

Page 31: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com 31

Microservices

Continuous

Delivery

Containers Monolith

Page 32: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com 32

Workshop Goals

Microservice

Principles

Monolith

Decomposition

Containers &

Continuous Delivery

mu

Page 33: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com

Page 34: WORKSHOP: Microservices as Containers on AWS

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

Page 35: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com 35

http://getmu.io

Page 36: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com 36

Page 37: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com

Overview

37

Page 38: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com

Pipelines

38

Page 39: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com

Environment

39

Page 40: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com

Service

40

Page 41: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com

Service #2

41

Page 42: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com 42

Lab 1 -Spring Boot Service

https://github.com/stelligent/mu-workshop-lab1

Page 43: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com 43

Lab 2 -Test Automation

https://github.com/stelligent/mu-workshop-lab2

Page 44: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com

Break

Page 45: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com 45

Workshop Goals

Microservice

Principles

Monolith

Decomposition

Containers &

Continuous Delivery

mu

Page 46: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com

How do I decompose my monolith?

46

Page 47: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com 47

The Challenge

User Experience

Business Services

Data Access Layer

From thick, layered architecture To small, autonomous services

Page 48: WORKSHOP: Microservices as Containers on AWS

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

Page 49: WORKSHOP: Microservices as Containers on AWS

Step 1 - Capability Cohesion

Code Order Code

Monolith ServiceMonolith Service

Customer Code

Monolith DB

Monolith DB

49

Page 50: WORKSHOP: Microservices as Containers on AWS

Bounded Context

Factor out Bounded Contextinto separate packages

Page 51: WORKSHOP: Microservices as Containers on AWS

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

Page 52: WORKSHOP: Microservices as Containers on AWS

Finding Seams

Page 53: WORKSHOP: Microservices as Containers on AWS

Finding Seams

Page 54: WORKSHOP: Microservices as Containers on AWS

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

Page 55: WORKSHOP: Microservices as Containers on AWS

Step 2 - Data Cohesion

Order Code

Monolith Service

Customer Code

Order Code

Monolith Service

Customer Code

Monolith DB

OrderDB

CustomerDB

55

Page 56: WORKSHOP: Microservices as Containers on AWS

Encapsulate Data

Foreign Key? Use the service to access data

Order

OrderDB

CustomerDB

Order Customer

OrderDB

CustomerDB

Page 57: WORKSHOP: Microservices as Containers on AWS

Encapsulate Data

Shared Data? Create a 3rd service

Address

OrderCustomer

Page 58: WORKSHOP: Microservices as Containers on AWS

Encapsulate Data

Single Table? Split table into two

Order Customer

Page 59: WORKSHOP: Microservices as Containers on AWS

Event Based and Eventual Consistency

Order Customer

CustomerDB

Topic

OrderDB

POST /Orders

(including address change)

Page 60: WORKSHOP: Microservices as Containers on AWS

Step 3 - Deployment Cohesion

Order Code

Microservice

Customer Code

OrderDB

CustomerDB

Order Code

Monolith Service

Customer Code

OrderDB

CustomerDB

Microservice

60

Page 61: WORKSHOP: Microservices as Containers on AWS

Separate Deployments

Order Code

Microservice

Customer Code

Microservice

Expose API

Page 62: WORKSHOP: Microservices as Containers on AWS

Separate Deployments

Independent CD Pipelines

CompileUnitTest

Package DeployE2ETest

ProdOrder

CompileUnitTest

Package DeployE2ETest

ProdCustomer

Contract Tests

Page 63: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com

How do I integrate these services?

63

Page 64: WORKSHOP: Microservices as Containers on AWS

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.

Page 65: WORKSHOP: Microservices as Containers on AWS

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.

Page 66: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com

Synchronous Integration

Order Customer

CustomerDB

2

Versioned API

• Decouple Change• Single Deployable

1

Page 67: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com

Synchronous Integration

Order Customer

CustomerDB

Circuit Breaker

• Degrade Gracefully• Shed Load• Recover Quickly

Page 68: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com

Asynchronous Integration

Order Customer

CustomerDB

Queue

Dead Letter Queue

• Handle Downstream Failures• Restore Consistency

Dead LetterQueue

Cleanup Job

Page 69: WORKSHOP: Microservices as Containers on AWS

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

Page 70: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com

Orchestration vs. Choreography

Order Submission

Payment

Fulfillment

Notification

Order Submission

Payment

Fulfillment

Notification

Page 71: WORKSHOP: Microservices as Containers on AWS

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

Page 72: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com

Lab 3 -Service Discovery

72

https://github.com/stelligent/mu-workshop-lab3

Page 73: WORKSHOP: Microservices as Containers on AWS

www.stelligent.com 73

Summary

Microservice

Principles

Monolith

Decomposition

Containers &

Continuous Delivery

mu

Page 74: WORKSHOP: Microservices as Containers on AWS

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

Page 75: WORKSHOP: Microservices as Containers on AWS

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

Page 76: WORKSHOP: Microservices as Containers on AWS

For more information on how Stelligent can help you with AWS Automation, go to www.stelligent.com

Q&A