#jaxlondon keynote: developing applications with a microservice architecture

63
@crichardson Developing applications with a microservice architecture Chris Richardson Author of POJOs in Action Founder of the original CloudFoundry.com @crichardson [email protected] http://plainoldobjects.com

Upload: chris-richardson

Post on 28-Nov-2014

159 views

Category:

Software


1 download

DESCRIPTION

The micro-service architecture, which structures an application as a set of small, narrowly focused, independently deployable services, is becoming an increasingly popular way to build applications. This approach avoids many of the problems of a monolithic architecture. It simplifies deployment and let’s you create highly scalable and available applications. In this keynote we describe the micro-service architecture and how to use it to build complex applications. You will learn how techniques such as Command Query Responsibility Segregation (CQRS) and Event Sourcing address the key challenges of developing applications with this architecture. We will also cover some of the various frameworks such as Spring Boot that you can use to implement micro-services.

TRANSCRIPT

Page 1: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Developing applications with a microservice

architecture

Chris Richardson

Author of POJOs in ActionFounder of the original CloudFoundry.com

@[email protected] http://plainoldobjects.com

Page 2: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Presentation goal

How decomposing applications into microservices

improves deployability and scalability and

simplifies the adoption of new technologies

Page 3: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

About Chris

Page 4: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

About Chris

Page 5: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

About Chris

Founder of a buzzword compliant (stealthy, social, mobile, big data, machine learning, ...) startup

Consultant helping organizations improve how they architect and deploy applications using cloud computing, micro services, polyglot applications, NoSQL, ...

Page 6: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Agenda

The (sometimes evil) monolith

Decomposing applications into services

Using an API gateway

Inter-service communication mechanisms

Page 7: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Let’s imagine you are building an online store

Page 8: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Tomcat

Traditional application architecture

Browser/Client

WAR/EAR

MySQL Database

Review Service

Product InfoService

Recommendation Service

StoreFrontUI

developtest

deploy

Simple to

Load balancer

scale

Spring MVC

SpringHibernate

Order Service

HTMLREST/JSON

Page 9: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

But big, complex, monolithic applications

⇒ big problems

Page 10: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Intimidates developers

Page 11: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Obstacle to frequent deployments

Need to redeploy everything to change one component

Interrupts long running background (e.g. Quartz) jobs

Increases risk of failure

Fear of change

Updates will happen less often - really long QA cycles

e.g. Makes A/B testing UI really difficult

Eggs in one basket

Page 12: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Overloads your IDE and container

Slows down development

Page 13: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Lots of coordination and communication required

Obstacle to scaling development

I want to update the UI

But the backend is not working

yet!

Page 14: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Requires long-term commitment to a technology stack

Page 15: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Agenda

The (sometimes evil) monolith

Decomposing applications into services

Using an API gateway

Inter-service communication mechanisms

Page 16: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Page 17: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

The scale cube

X axis - horizontal duplication

Z axis

- data

partit

ioning

Y axis - functional

decomposition

Scale b

y split

ting s

imilar

thing

s

Scale by splitting

different things

Page 18: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Y-axis scaling - application level

WAR

Storefront UI

Product InfoService

RecommendationService

ReviewService

OrderService

Page 19: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Y-axis scaling - application level

Storefront UI

Product InfoService

RecommendationService

ReviewService

OrderService

Page 20: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Product Info

Y-axis scaling - application level

Product InfoService

RecommendationService

ReviewService

OrderService

Browse Products UI

Checkout UI

Order management UI

Account management UI

Apply X-axis and Z-axis scaling to each service independently

Page 21: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Service deployment options

VM or Physical Machine

Docker/Linux container

JVM

JAR/WAR/OSGI bundle/...

Isolation, manageability

Density/efficiency

Page 22: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Partitioning strategies...

Partition by noun, e.g. product info service

Partition by verb, e.g. Checkout UI

Single Responsibility Principle

Unix utilities - do one focussed thing well

Page 23: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Partitioning strategies

Too few

Drawbacks of the monolithic architecture

Too many - a.k.a. Nano-service anti-pattern

Runtime overhead

Potential risk of excessive network hops

Potentially difficult to understand system

Something of an art

Page 24: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Example micro-servicerequire 'sinatra'

post '/' do phone_number = params[:From] registration_url = "#{ENV['REGISTRATION_URL']}?phoneNumber=#{URI.encode(phone_number, "+")}" <<-eof <Response> <Sms>To complete registration please go to #{registration_url}</Sms> </Response> eofend

Responds to incoming SMS messages via Twilio

Page 25: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

More service, less micro

But more realistically...

Focus on building services that make development and deployment easier

- not just tiny services

Page 26: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Real world examples

http://highscalability.com/amazon-architecture

http://techblog.netflix.com/

http://www.addsimplicity.com/downloads/eBaySDForum2006-11-29.pdf

http://queue.acm.org/detail.cfm?id=1394128

~600 services

100-150 services to build a page

Page 27: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

There are many benefits

Page 28: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Smaller, simpler apps

Easier to understand and develop

Less jar/classpath hell - who needs OSGI?

Faster to build and deploy

Reduced startup time - important for GAE

Page 29: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Scales development: develop, deploy and scale each service independently

Page 30: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Improves fault isolation

Page 31: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Eliminates long-term commitment to a single technology stack

Modular, polyglot, multi-framework applications

Page 32: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Two levels of architectureSystem-level

ServicesInter-service glue: interfaces and communication mechanisms

Slow changing

Service-level

Internal architecture of each serviceEach service could use a different technology stack

Pick the best tool for the jobRapidly evolving

Page 33: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Easily try other technologies

... and fail safely

Page 34: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

But there are drawbacks

Page 35: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Complexity

Page 36: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Complexity of developing a distributed system

http://highscalability.com/blog/2014/4/8/microservices-not-a-free-lunch.html

Page 37: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Multiple databases &

Transaction management

e.g. Fun with eventual consistencyCome to my 11.30 am talk

Page 38: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Complexity of testing a distributed system

http://highscalability.com/blog/2014/4/8/microservices-not-a-free-lunch.html

Page 39: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Complexity of deploying and operating a distributed

system

You need a lot of automation

http://highscalability.com/blog/2014/4/8/microservices-not-a-free-lunch.html

Page 40: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Developing and deploying features that span multiple services requires careful

coordination

Page 41: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

When to use it?In the beginning: •You don’t need it •It will slow you down

Later on:•You need it•Refactoring is painful

Page 42: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Agenda

The (sometimes evil) monolith

Decomposing applications into services

Using an API gateway

Inter-service communication mechanisms

Page 43: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Let’s imagine that you want to display a product’s details...

Recommendations

ProductInfo Reviews

Page 44: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Directly connecting the front-end to the backend

Model

View ControllerProduct Info

service

RecommendationService

Reviewservice

REST

REST

Thrift

Model

View Controller

Browser/Native App

Traditional server-sideweb application

Chatty API

Web unfriendly protocols

Page 45: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Use an API gateway

Model

View ControllerProduct Info

service

RecommendationService

Reviewservice

REST

REST

Thrift

APIGateway

Model

View Controller

Browser/Native App

Single entry point

Client specific APIs

Protocol translation

Traditional server-sideweb application

Page 46: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Optimized client-specific APIs

Web application

MobileApp

NodeJS

APIGateway

RESTproxy

Event publishing

Product Infoservice

RecommendationService

Reviewservice

REST

REST

Thrift

getProductInfo()getRecomm...()getReviews()

getProductDetails()

Page 47: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Netflix API Gateway

http://techblog.netflix.com/2013/01/optimizing-netflix-api.html

Device specific end points

Page 48: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

API gateway design challenges

Performance and scalability

Non-blocking I/O

Asynchronous, concurrent code

Handling partial failures

....

http://techblog.netflix.com/2012/02/fault-tolerance-in-high-volume.html

Page 49: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Useful frameworks for building an API gateway

JVM:

Netty, Vertex

Netflix Hystrix

...

Other:

NodeJS

Page 50: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Agenda

The (sometimes evil) monolith

Decomposing applications into services

Using an API gateway

Inter-service communication mechanisms

Page 51: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Inter-service communication options

Synchronous HTTP ⇔ asynchronous AMQP

Formats: JSON, XML, Protocol Buffers, Thrift, ...

Asynchronous is preferredJSON is fashionable but binary format

is more efficient

Page 52: #JaxLondon keynote: Developing applications with a microservice architecture

Pros and cons of messagingPros

Decouples client from server

Message broker buffers messages

Supports a variety of communication patterns

Cons

Additional complexity of message broker

Request/reply-style communication is more complex

Page 53: #JaxLondon keynote: Developing applications with a microservice architecture

Pros and cons of HTTPPros

Simple and familiar

Request/reply is easy

Firewall friendly

No intermediate broker

Cons

Only supports request/reply

Server must be available

Client needs to discover URL(s) of server(s)

Page 54: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Discovery option #1: Internal load balancer

LoadBalancer

Product InfoService

Product InfoService

Product InfoService

Product InfoService

Client/API gateway

Services register with load balancer

Client talks to load balancer

Client talks to

Has a well-known location

http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/USVPC_creating_basic_lb.html

Page 55: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Discovery option #2: client-side load balancing

RESTClient

Product InfoService

Product InfoService

Product InfoService

Product InfoService

Client

ServiceRegistry

Services register with registry

Client polls registry

http://techblog.netflix.com/2013/01/announcing-ribbon-tying-netflix-mid.html

http://techblog.netflix.com/2012/09/eureka.html

Page 56: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Lots of moving parts!Product InfoProduct InfoService

RecommendationService

ReviewService

OrderService

Browse Products UI

Checkout UI

Order management UI

Account management UI

APIGateway

Service registry

ContentRouter

HTMLBrowser

RESTClient

Ext.LB

Ext.LB

Page 57: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Summary

Page 58: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Monolithic applications are simple to develop and deploy

BUT have significant drawbacks

Page 59: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Apply the scale cube

Modular, polyglot, and scalable applications

Services developed, deployed and scaled independently

Page 60: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Use a modular, polyglot architecture

Model

View Controller Product Infoservice

RecommendationService

Reviewservice

REST

REST

AMQP

APIGateway

Model

View Controller

Server-side web application

Browser/Native application

Page 61: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Start refactoring your monolith

Monolith ServiceAnti-corruption layer

Glue code

Pristine

Page 62: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Come to my 11.30 am talk to learn more....

Building microservices with Scala, functional domain models and

Spring Boot

Page 63: #JaxLondon keynote: Developing applications with a microservice architecture

@crichardson

Questions?

@crichardson [email protected]

http://plainoldobjects.com http://microservices.io