(arc309) getting to microservices: cloud architecture patterns

72
© 2015, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Adrian Trenaman SVP Engineering, gilt.com @adrian_trenaman October 2015 From Monolithic to Microservices Evolving Architecture Patterns in the Cloud Derek Chiles Sr. Mgr, Solutions Architecture, AWS @derekchiles ARC309

Upload: amazon-web-services

Post on 08-Jan-2017

6.734 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: (ARC309) Getting to Microservices: Cloud Architecture Patterns

© 2015, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Adrian Trenaman

SVP Engineering, gilt.com

@adrian_trenaman

October 2015

From Monolithic to MicroservicesEvolving Architecture Patterns in the Cloud

Derek Chiles

Sr. Mgr, Solutions Architecture, AWS

@derekchiles

ARC309

Page 2: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Gilt’s Journey

Page 3: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Gilt: Luxury designer brands at members-only prices

Page 4: (ARC309) Getting to Microservices: Cloud Architecture Patterns

... we shoot the product in our studios

Page 5: (ARC309) Getting to Microservices: Cloud Architecture Patterns

... we receive, store, pack, and ship ...

Page 6: (ARC309) Getting to Microservices: Cloud Architecture Patterns

... we sell every day at noon EST

Page 7: (ARC309) Getting to Microservices: Cloud Architecture Patterns

… stampede!

Page 8: (ARC309) Getting to Microservices: Cloud Architecture Patterns

... this is what noon really looks like.

Page 9: (ARC309) Getting to Microservices: Cloud Architecture Patterns

How It All Started…

Page 10: (ARC309) Getting to Microservices: Cloud Architecture Patterns

From Rails to Riches ― 2007: A Ruby on Rails monolith

Jobs

Ruby on Rails memcache

Postgres

Page 11: (ARC309) Getting to Microservices: Cloud Architecture Patterns

2011: Java, loosely-typed, monolithic services

(1) Large,

loosely typed

services

(2) Teams

focused on

business lines

(3) Monolithic Java

application; huge

bottleneck for innovation

(4) Hidden linkages;

buried business logic

Page 12: (ARC309) Getting to Microservices: Cloud Architecture Patterns

“How can we arrange our teams around

strategic initiatives? How can we make it fast

and easy to get to change to production?”

Enter: µ-services

Page 13: (ARC309) Getting to Microservices: Cloud Architecture Patterns

2015: LOSA (Lots of Small Apps) & Microservices

Page 14: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Driving Forces Behind Gilt’s Emergent

Architecture

• Team autonomy

• Voluntary adoption (tools, techniques, processes)

• KPI / goal-driven initiatives

• Failing fast and openly

• Being open and honest, even when it’s difficult

Page 15: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Service growth over time: point of inflexion === Scala.

Page 16: (ARC309) Getting to Microservices: Cloud Architecture Patterns

What are all these services doing?

Page 17: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Anatomy of a service

Page 18: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Anatomy of a gilt service – typical choices

gilt-service-

framework,

, Java, Javascript

Log4j, Cloudwatch

Cave

or

Page 19: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Lines of code per service (logarithmic scale)

Page 20: (ARC309) Getting to Microservices: Cloud Architecture Patterns

# source files per service (includes build, config, xml, Java, Scala, Ruby...)

Page 21: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Service discovery: straightforward

ZooKeeper

Brocade Traffic Manager (aka Zeus,

Stringray, SteelApp,...)

Page 22: (ARC309) Getting to Microservices: Cloud Architecture Patterns

From bare metal…

PHX

IAD

Page 23: (ARC309) Getting to Microservices: Cloud Architecture Patterns

… to vapour.

Page 24: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Lift-and-shift + elastic teams

Existing Data Centre

Dual 10-Gb direct connect line, 2-ms latency.

“Legacy VPC”

MobileCommonPerson-

alisationAdmin Data

(1) Deploy to VPC

(2) “Department” accounts for elasticity & DevOps

Page 25: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Single-tenant deployment: one service per EC2 instance

Page 26: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Reproducible, immutable deployments: Docker

Page 27: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Service discovery: new services use ELB

ZooKeeper

Elastic Load

Balancing (ELB)

Page 28: (ARC309) Getting to Microservices: Cloud Architecture Patterns

# running instances per service: “rule of three” (previously “rule of four”)

Page 29: (ARC309) Getting to Microservices: Cloud Architecture Patterns

EC2 instance sizing: lots of small instances

Page 30: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Evolution of architecture and tech organization

Page 31: (ARC309) Getting to Microservices: Cloud Architecture Patterns

We (heart) μ-services

• Lessen dependencies between

teams: faster code-to-prod

• Lots of initiatives in parallel

• Your favourite

<tech/language/framework>

here

• Graceful degradation of

service

• Disposable code: easy to

innovate, easy to fail and move

on.

Page 32: (ARC309) Getting to Microservices: Cloud Architecture Patterns

We (heart) cloud

• Do DevOps in a meaningful

way.

• Low barrier of entry for new

tech (Amazon DynamoDB,

Amazon Kinesis,...)

• Isolation

• Cost visibility

• Security tools (IAM)

• Well documented

• Resilience is easy

• Hybrid is easy

• Performance is great

Page 33: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Common Challenges and

Patterns

Page 34: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Monolithic Microservices

• Simple deployments

• Binary failure modes

• Inter-module refactoring

• Technology monoculture

• Vertical scaling

• Partial deployments

• Graceful degradation

• Strong module boundaries

• Technology diversity

• Horizontal scaling

Page 35: (ARC309) Getting to Microservices: Cloud Architecture Patterns

• Organization

• Discovery

• Data management

• Deployment

• I/O explosion

• Monitoring

Common Challenges and Patterns

Page 36: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Organization

Page 37: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Monolithic Ownership

Organized on technology capabilities

UI Team

DBA Team

App Logic Team

Web Tier

App Tier

DB

Organizational Structure Application Architecture

Page 38: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Microservices Ownership

Organized on business responsibilities

Login

Registration

Order

Personalization

Accounts team

Mobile

Personalization team Mobile team

Page 39: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Microservices Ownership

• Requirements

• Technology selection

• Development

• Quality

• Deployment

• Support

Page 40: (ARC309) Getting to Microservices: Cloud Architecture Patterns

How to Be a Good Citizen (Service Consumer)

• Design for failure

• Expect to be throttled

• Retry w/ exponential backoff

• Degrade gracefully

• Cache when appropriate

Page 41: (ARC309) Getting to Microservices: Cloud Architecture Patterns

How to Be a Good Citizen (Service Provider)

• Publish your metrics

• Protect yourself

• Keep your implementation details private

• Maintain backwards compatibility

Page 42: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Amazon API Gateway

• Throttling (global and per-method)

• Caching (with TTLs and invalidation)

• Monitoring (RPS, latency, error rate)

• Versioning

• Authentication

Page 43: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Discovery

Page 44: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Use DNS

Convention-based naming

<service-name>-<environment>.domain.com

shoppingcart-gamma.example.com

<service-name>.<environment>.domain.com

shoppingcart.gamma.example.com

Page 45: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Use a Dynamic Service Registry

• Avoids the DNS TTL issue

• More than service registry & discovery

• Configuration management

• Health checks

• Plenty of options

• ZooKeeper (Apache)

• Eureka (Netflix)

• Consul (HashiCorp)

• SmartStack (Airbnb)

Page 46: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Data management

Page 47: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Challenge: Centralized Database

Monolithic applications typically

have a monolithic data store:

• Difficult to make schema

changes

• Technology lock-in

• Vertical scaling

• Single point of failure

user-svc account-svccart-svc

DB

Page 48: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Centralized Database – Anti-pattern

Monolithic applications typically

have a monolithic data store:

• Difficult to make schema

changes

• Technology lock-in

• Vertical scaling

• Single point of failure

user-svc account-svccart-svc

DB

Page 49: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Decentralized Data Stores

• Each service chooses its data

store technologies

• Low impact schema changes

• Independent scalability

• Data is gated through the

service API

account-

svc

cart-

svc

DynamoDB RDS

user-

svc

ElastiCache RDS

Page 50: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Challenge: Transactional Integrity

• Use a pessimistic model

• Handle it in the client

• Add a transaction manager / distributed locking service

• Rethink your design

• Use an optimistic model

• Accept eventual consistency

• Retry (if idempotent)

• Fix it later

• Write it off

Page 51: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Challenge: Aggregation

• Pull: Make the data available via your service API

• Push: To Amazon S3, Amazon CloudWatch, or another service

you create

• Pub/sub: Via Amazon Kinesis or Amazon SQS

Page 52: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Deployment

Page 53: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Continuous Delivery & Continuous Deployment

Create the right build pipeline for each service

• AWS CodeDeploy

• AWS Elastic Beanstalk

• Jenkins, CircleCI, Travis,…

Integration

& perf tests

Build &

unit testsbeta Produser-svc

Integration &

perf tests

Build &

unit testsbeta gamma Prodcart-svc

Page 54: (ARC309) Getting to Microservices: Cloud Architecture Patterns

AWS CodePipeline

Page 55: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Multiple Services per Container/Instance

• Independent monitoring

• Independent scaling

• Clear ownership

• Immutable deployments

user-svc

cart-svc

account-svc

Container or instance

Page 56: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Multiple Services per Container/Instance – Anti-pattern

• Independent monitoring

• Independent scaling

• Clear ownership

• Immutable deployments

user-svc

cart-svc

account-svc

Container or instance

Page 57: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Single Service per Container/Instance

• Independent monitoring

• Independent scaling

• Clear ownership

• Immutable deployments

user-svc

container or instance

account-svc

cart-svc

container or instance

container or instance

Page 58: (ARC309) Getting to Microservices: Cloud Architecture Patterns

…Or Just Use AWS Lambda

LambdaAPI Gateway

RDS

DynamoDB

Page 59: (ARC309) Getting to Microservices: Cloud Architecture Patterns

I/O explosion

Photo credit: maf04 (CC by-sa-2.0)

Page 60: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Challenge: Request Multiplication

checkout-

svc

cart-svc

account-svc

user-svc

Single request

Page 61: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Add Client Caching

checkout-

svc

cart-svc

account-svc

user-svc

Single request

cache

user & account cache

Page 62: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Challenge: Hotspots

cart-svc order-svcshipping-

svc

user-svc

single request

get (user x, col y) get (user x, col y) get (user x, col y)

Page 63: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Use Dependency Injection

cart-svc order-svcshipping-

svc

user-svc

single request

get (user x, col y)

(user x, col y) (user x, col y)

Page 64: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Monitoring

Page 65: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Challenge: monitoring

• Publish externally relevant metrics

• Latency

• RPS

• Error rate

• Understand internally relevant metrics

• Basic – CloudWatch

• OS

• Application

Page 66: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Challenge: Logging

• Pick a common log aggregation solution

• Agree on log entry formats

• Use naming conventions

• Agree on correlation strategy

Page 67: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Challenge: Correlating Requests

ui-svc catalog-

svc

checkout-

svc

shipping-

svc

payment-

svc

request

Page 68: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Use Correlation IDs

09-02-2015 15:03:24 ui-svc INFO [uuid-123] ……

09-02-2015 15:03:25 catalog-svc INFO [uuid-123] ……

09-02-2015 15:03:26 checkout-svc ERROR [uuid-123] ……

09-02-2015 15:03:27 payment-svc INFO [uuid-123] ……

09-02-2015 15:03:27 shipping-svc INFO [uuid-123] ……

ui-svc catalog-

svc

checkout-

svc

shipping-

svc

payment-

svc

request correlation id:

“uuid-123”correlation id:

“uuid-123”

Page 69: (ARC309) Getting to Microservices: Cloud Architecture Patterns

What did we cover?

• Ownership

• Discovery

• Data management

• Deployment

• I/O explosion

• Monitoring

Page 70: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Related Sessions

• ARC201 - Microservices Architecture for Digital Platforms with AWS

Lambda, Amazon CloudFront and Amazon DynamoDB

• CMP302 - Amazon EC2 Container Service: Distributed Applications

at Scale

• DEV203 - Using Amazon API Gateway with AWS Lambda to Build

Secure and Scalable APIs

• DVO401 - Deep Dive into Blue/Green Deployments on AWS

• SPOT304 - Faster, Cheaper, Safer Products with AWS: Adrian

Cockcroft Shares Experiences Helping Customers Move to the

Cloud

Page 71: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Remember to complete

your evaluations!

Page 72: (ARC309) Getting to Microservices: Cloud Architecture Patterns

Thank you!

Adrian Trenaman

SVP Engineering, gilt.com

@adrian_trenaman

Derek Chiles

Sr. Mgr, Solutions Architecture, AWS

@derekchiles