to microservices and beyond

82
© Copyright 2015 Pivotal. All rights reserved. © Copyright 2015 Pivotal. All rights reserved. To Microservices and Beyond! SV Microservices/Cloud Native Meetup May 13, 2015 1 Matt Stine (@mstine) Principal Engineer and Senior Product Manager

Upload: matt-stine

Post on 23-Jul-2015

416 views

Category:

Software


1 download

TRANSCRIPT

Page 1: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.© Copyright 2015 Pivotal. All rights reserved.

To Microservices and Beyond!SV Microservices/Cloud Native Meetup May 13, 2015

1

Matt Stine (@mstine) Principal Engineer and Senior Product Manager

Page 2: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 2

IT SEEMS THERE’S SOME HYPE…

M!CR0S3RV!C3$!!!!!

Page 3: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 3

https://twitter.com/mstine/status/557763539101032448

Page 4: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

DEFINE: Microservice

4

Loosely coupled service oriented architecture with bounded contexts

Adrian Cockcroft Technology Fellow, Battery Ventures Former Netflix Chief Cloud Architect

Page 5: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

DEFINE: Microservice

5

Loosely coupled service oriented architecture with bounded contexts

If every service has to be updated in concert, it’s not loosely coupled!

If you have to know about surrounding services you don’t have a bounded context.

Page 6: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

Not Monoliths

6

Relational Database

Data Access

Service

HTML JavaScript MVC

Service

Monolithic ApplicationBrowser

Page 7: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 7

Not Traditional (ESB-centric) SOA

Enterprise Service Bus

Service Service Service Service

Service Service Service Service

UI UI

Page 8: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 8

But Microservices!

From: http://www.slideshare.net/adriancockcroft/goto-berlin

Page 9: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 9

But why?

Page 10: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 10

Issues We’ll Confront•Microservices are not an inherently superior architecture.

•We’re still building big systems from smaller things.

• Just like Docker won’t save the world, neither will microservices. They’re not free.

• You absolutely cannot forget about data.

• Let’s begin!

Page 11: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 11

Not an end in themselves…It’s about Continuous Delivery!

Page 12: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

What is Continuous Delivery?

12

$Busin

ess

Devel

opm

ent

QA

Ope

ratio

nsCu

stom

er

Page 13: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

What is Continuous Delivery?

13

$

Page 14: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 14

Keep the Wheel Spinning!

Design Develop

Test

Customer Feedback Customer

Delivery

Analytics

Page 15: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 15

Prod Release #1

Prod Release #2

Prod Release #3

Agile Development

Waterfall Organization!

Page 16: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

Silo Delivery

16

Project Mgmt UX Dev QA DBA Sys

AdminNet

AdminStorage Admin

Adapted from: http://www.slideshare.net/adriancockcroft/goto-berlin

MONOLITHIC DELIVERY

Page 17: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

Continuous Delivery

17

Product Mgr UX Dev QA DBA Sys

AdminNet

AdminStorage Admin

BUSINESS CAPABILITY TEAMS USING MICROSERVICES

PLATFORM OPERATIONS TEAM

Adapted from: http://www.slideshare.net/adriancockcroft/goto-berlin

Page 18: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

Continuous Delivery

18

Product Mgr UX Dev QA DBA Sys

AdminNet

AdminStorage Admin

BUSINESS CAPABILITY TEAMS USING MICROSERVICES

PLATFORM OPERATIONS TEAM

Adapted from: http://www.slideshare.net/adriancockcroft/goto-berlin

Self Service

API

Page 19: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 19

INVENTORY

Prod Release

Prod Release

Prod Release

CATALOG

Prod Release

Prod Release

Prod Release

REVIEWS

Prod Release

Prod Release

Prod Release

SHIPPING

Prod Release

Prod Release

Prod Release

Page 20: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 20

Microservices Enabling Continuous Delivery•Decoupling Capabilities -> Decoupling Change Cycles

• Product Ownership: Tip to Tail

•We Build and Operate What We Understand BEST

•We Collaborate via API Contracts

•Microservice to Microservice

•Microservice to Platform

https://github.com/realestate-com-au/pact

Page 21: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 21

Systems over ServicesComposition over Components

Page 22: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

Microframeworks for Microservices

22

Spring Boot http://projects.spring.io/spring-boot

Dropwizard http://dropwizard.io

http://12factor.net

Page 23: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

It can get pretty small…

23

@RestController class ThisWillActuallyRun { @RequestMapping("/") String home() { "Hello World!" } }

Page 24: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

With Spring Data REST!

24

http://projects.spring.io/spring-data-rest

@Entity @Table(name = "city") public class City implements Serializable { ! @Id @GeneratedValue private Long id; ! @Column(nullable = false) private String name; ! @Column(nullable = false) private String county; !//... !}

Page 25: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

With Spring Data REST!

25

http://projects.spring.io/spring-data-rest

@RepositoryRestResource(collectionResourceRel = "cities", path = "cities") public interface CityRepository extends PagingAndSortingRepository<City, Long> {}

@SpringBootApplication @EnableJpaRepositories @Import(RepositoryRestMvcConfiguration.class) public class Application { ! public static void main(String[] args) { SpringApplication.run(Application.class, args); } }

Page 26: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

With Spring Data REST!

26

http://projects.spring.io/spring-data-rest

{ "_links" : { "next" : { "href" : "http://localhost:8080/cities?page=1&size=20" }, "self" : { "href" : "http://localhost:8080/cities{?page,size,sort}", "templated" : true } }, "_embedded" : { "cities" : [ { "name" : "HOLTSVILLE", "county" : "SUFFOLK", "stateCode" : "NY", "postalCode" : "00501", "latitude" : "+40.922326", "longitude" : "-072.637078",

Page 27: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

But No Microservice is an Island…

27

Page 28: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

Example Distributed System: Minified

28

Page 29: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 29

Some emergent challenges of microservices systems…

•Distributed/Versioned Configuration

• Service Registration/Discovery

• Routing/Load Balancing

• Fault Tolerance (Circuit Breakers!)

Page 30: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

Example: Coordination Boiler Plate

30

Page 31: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 31

• Eureka

•Hystrix + Turbine

• Ribbon

• Feign

• Zuul

http://netflix.github.io

Page 32: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 32

http://projects.spring.io/spring-cloud

@SpringCloudOSS

Page 33: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

Example: Spring Cloud + Netflix OSS

33

Page 34: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 34

Config Server

Page 35: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 35

Config Server + Cloud Bus

Page 36: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

Running a Config Server

36

@SpringBootApplication @EnableConfigServer public class ConfigServerApplication { ! public static void main(String[] args) { SpringApplication.run(ConfigServerApplication.class, args); } !}

Page 37: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 37

Service Registration/Discovery

Page 38: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

Running a Eureka Server

38

@SpringBootApplication @EnableEurekaServer public class EurekaApplication { ! public static void main(String[] args) { SpringApplication.run(EurekaApplication.class, args); } !}

Page 39: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

Service Registration/Discovery

39

@SpringBootApplication @EnableCircuitBreaker @EnableDiscoveryClient public class CustomerApp extends RepositoryRestMvcConfiguration { @Override protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { config.exposeIdsFor(Customer.class); } ! public static void main(String[] args) { SpringApplication.run(CustomerApp.class, args); } !}

Page 40: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

Service Registration/Discovery

40

Page 41: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

Fault Tolerance - Circuit Breakers

41

Page 42: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

Fault Tolerance - Circuit Breakers

42

@SpringBootApplication @EnableCircuitBreaker @EnableDiscoveryClient public class CustomerApp extends RepositoryRestMvcConfiguration { @Override protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { config.exposeIdsFor(Customer.class); } ! public static void main(String[] args) { SpringApplication.run(CustomerApp.class, args); } !}

Page 43: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

Enabling a Circuit Breaker

43

@HystrixCommand(fallbackMethod = "defaultLink") public Link getStoresByLocationLink(Map<String, Object> parameters) { URI storesUri = URI.create(uri); try { ServiceInstance instance = loadBalancer.choose("stores"); storesUri = URI.create(String.format("http://%s:%s", instance.getHost(), instance.getPort())); } catch (RuntimeException e) { // Eureka not available } ! Traverson traverson = new Traverson(storesUri, MediaTypes.HAL_JSON); Link link = traverson.follow("stores", "search", "by-location") .withTemplateParameters(parameters).asLink(); ! return link; }

Client-Side Load Balancing

Page 44: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 44

{ "id" : 3, "firstname" : "Matt", "lastname" : "Stine", "address" : { "street" : "9195 East Mineral Circle", "zipCode" : "80112", "city" : "Centennial", "location" : { "latitude" : 39.5738106, "longitude" : -104.8816934 } }, "_links" : { "self" : { "href" : "http://pivotalcustomers.cfapps.io/customers/3" }, "stores-nearby" : { "href" : "http://pivotalstores.cfapps.io/stores/search/findByAddressLocationNear?location=39.5738106,-104.8816934&distance=50" } } }

Page 45: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 45

Page 46: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

Circuit Breaker Fallback

46

public Link defaultLink(Map<String, Object> parameters) { return null; }

@HystrixCommand(fallbackMethod = "defaultLink") public Link getStoresByLocationLink(Map<String, Object> parameters) { //... }

Page 47: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 47

{ "id" : 3, "firstname" : "Matt", "lastname" : "Stine", "address" : { "street" : "9195 East Mineral Circle", "zipCode" : "80112", "city" : "Centennial", "location" : { "latitude" : 39.5738106, "longitude" : -104.8816934 } }, "_links" : { "self" : { "href" : "http://pivotalcustomers.cfapps.io/customers/3" } } } // stores-nearby is gone!!!

Page 48: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 48

Page 49: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 49

Operationalized ArchitectureYou have to pay for your lunch!

Page 50: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.© Copyright 2015 Pivotal. All rights reserved. 50

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

Page 51: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 51

Paying for your lunch…• Significant Operations Overhead

• Substantial DevOps Skills Required

• Implicit Interfaces

•Duplication of Effort

•Distributed System Complexity

•Asynchronicity is Difficult!

• Testability Challenges

Page 52: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

You must be this tall to use Microservices…

52

http://martinfowler.com/bliki/MicroservicePrerequisites.html

https://www.flickr.com/photos/gusset/3723961589

• RAPID PROVISIONING

•BASIC MONITORING

• RAPID APPLICATION DEPLOYMENT

•DEVOPS CULTURE

Page 53: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

It takes a platform…

53

http://techblog.netflix.com/2013/01/optimizing-netflix-api.htmlhttp://techblog.netflix.com/2014/03/the-netflix-dynamic-scripting-platform.html

Page 54: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

It takes a platform…

54

Cloud Foundry Spring Cloud

Page 55: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 55

Platform Features• Environment Provisioning

•On-Demand/Automatic Scaling

• Failover/Resilience

• Routing/Load Balancing

•Data Service Operations

•Monitoring

Page 56: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

Environment Provisioning/App Deployment

56

Rou

ter

Cloud Controller Service Broker Node(s)

DEA DEA

DEA DEA

Blobstore DB

Runtime

1. Upload bits/metadata

2. Create/bind services

3. Stage via Buildpack

4. Deploy via Container

push app+ app MD

SC

+ =

http://docs.cloudfoundry.org/devguide/deploy-apps/

Page 57: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

Environment Provisioning/App Deployment

57

Rou

ter

Cloud Controller

DEA

Blobstore DB

Runtime

Detect Compile UploadNo

System Buildpacks

+ =

Yes

http://docs.cloudfoundry.org/buildpacks/

Page 58: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

Deployment/Load Balancing/Scaling

58

Blobstore

R

oute

r Cloud Controller

DEA

Messaging (NATS)

DEA DEA

Runtime

Access App

http://docs.cloudfoundry.org/concepts/architecture/warden.html

Container Container

Page 59: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

Failover/Resilience

59

Blobstore

R

oute

r Cloud Controller

DEA

Messaging (NATS)

DEA DEA

Runtime

Health ManagerActual StateDesired State

http://docs.cloudfoundry.org/concepts/architecture/#hm9k

Container Container Container

Page 60: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 60

Diego

https://github.com/cloudfoundry-incubator/diego-design-notes

Page 61: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 61

http://lattice.cf/

Page 62: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

Data Service Operations: Cluster Provisioning

62

Blobstore

BOSH

Health Monitor

DBDeploy my Services

IaaS

Worker VMs BOSH Director

NATS Cassandra Node

Target VMCassandra Node

Target VMCassandra Node

Target VM

http://bosh.cloudfoundry.org/

Page 63: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

DB

Rou

ter

Data Service Operations: Application Binding

63

Service credentials

reserve resources

obtain connection data

CLI Cloud Controller

Service Broker

Data Service

Runtime

create service (HTTP)

bind service (HTTP)

create service (HTTP)

bind service (HTTP)

http://docs.cloudfoundry.org/services/api.html

Page 64: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

Monitoring

64

Page 65: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 65

It’s All About the DataWhat about the BIG QUESTIONS?

Page 66: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

This won’t work…

66

Page 67: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 67

Instead!

Page 68: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

Bounded Contexts

68

Movie Movie

Actor

Genre

Media Type

Media Type

Kiosk

Location

Media

Product Catalog

Inventory

Page 69: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

Polyglot Persistence

69

REST XYou shall not pass…

Page 70: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

But I have a question!

70

REST XYou shall not pass…

?

?

? ?

?

?

Page 71: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

Lambda Architecture

71

Page 72: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

Join via Events!

72

Page 73: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 73

http://projects.spring.io/spring-xd/

Page 74: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 74

Page 75: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

Redbox Conceptual Workflow

75

Page 76: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

SpringBox Microservices

76

Catalog Service

Inventory Service

Kiosk

Kiosk

Kiosk

Reservation Service

https://github.com/cf-platform-eng/springbox-datacloud

Page 77: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

…and if you have a question:

77

Kiosk

Kiosk

Kiosk

Speed Layer

Batch Layer Serving Layer

Event Ingest

https://github.com/cf-platform-eng/springbox-datacloud

“What movie genres are most popular in what geographic locations?”

Page 78: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

“What movie genres are most popular in what geographic locations?”

78

// Aggregate preferences across all kiosks: stream create --name kiosk_agg_prefs --definition "rabbit --queues=lambda.kiosk.events | field-value-counter --fieldName=genreIds" !// Tap aggregate preferences, filter for kiosk #1: stream create --name kiosk_1_prefs --definition "tap:stream:kiosk_agg_prefs > filter --expression=#jsonPath(payload,'$.locationId').equals(1) | field-value-counter --fieldName=genreIds"

Page 79: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved.

“What movie genres are most popular in what geographic locations?”

79

field-value-counter display --name kiosk_agg_prefs field-value-counter display=kiosk_agg_prefs ------------------------------------------- - ----- VALUE - COUNT Action | 14 Adventure | 6 Comedy | 27 Sci-Fi | 18

Page 80: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 80

Where We’ve Been…•Microservices are an enabler to Continuous Delivery.

• Less about services, more about composed distributed systems. Patterns can help.

• You’re going to need a platform.

•Decomposed data governance -> recomposed data discovery.

• Thank You!

Page 81: To Microservices and Beyond

© Copyright 2015 Pivotal. All rights reserved. 81

I wrote a little cloud book…Available to you compliments of Pivotal! !!Get the FREE e-book at http://bit.ly/cloud-native-book!

Page 82: To Microservices and Beyond

A NEW PLATFORM FOR A NEW ERA