© 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud...

58
© 2017 Pivotal Software, Inc. All rights reserved. 1

Transcript of © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud...

Page 1: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

© 2017 Pivotal Software, Inc. All rights reserved. 1

Page 2: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

© 2017 Pivotal Software, Inc. All rights reserved.@kennybastani

Cloud Native Java

Kenny BastaniSpring Developer Advocate @ Pivotal

2

Page 3: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

Kenny Bastani

@kennybastani

Spring Developer Advocate

Page 4: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

Agenda

Agenda

1 Monolith to Microservices

2 Microservice Reference Architecture

3 Spring Boot & Spring Cloud Examples

Page 5: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

© 2017 Pivotal Software, Inc. All rights reserved.@kennybastani

MicroservicesHow did we get there?

5

Page 6: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

We started with the monolith…

Page 7: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

© 2017 Pivotal Software, Inc. All rights reserved.@kennybastani

Cultural problems with monoliths

7

Slows our velocity getting into production

It takes too long to ramp up new engineers

The code base is just too large for any one person to fully comprehend

Centralized authority and change management slows progress (DBA, Ops)

Page 8: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

© 2017 Pivotal Software, Inc. All rights reserved.@kennybastani

Operational problems with monoliths

8

Deployments batch many changes together from different teams

Operations drives the runtime environment of applications

Operators take on all operational responsibility (including VM upgrades)

Deploy everything at once or nothing at all

Page 9: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

We then moved towards SOA…

Page 10: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

@kennybastani

We have now arrived at microservices…Each team provisions self-service infrastructure, like a database, and builds a single application

Centralized resources are provided as backing services that are shared for data consistency, caching

Page 11: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

© 2017 Pivotal Software, Inc. All rights reserved.@kennybastani

Online Store ExampleCloud native application as microservices

11

Page 12: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

@kennybastani

Page 13: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with
Page 14: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with
Page 15: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with
Page 16: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

Migration strategies

Page 17: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

Monolith to Microservice

Page 18: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

Splitting the Monolith: User Service Migration

Page 19: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

Strangler Pattern

“Gradually create a new system around the edges of the old, letting it grow slowly over several years

until the old system is strangled.” — Martin Fowler

Page 20: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

Strangler vines—seed in the upper branches of a fig tree and gradually work their way down to the soil—strangling and eventually and killing the tree

Page 21: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

Strangling legacy using microservices

How can we take advantage of building microservices that also strangle data from the edge of legacy systems?

Page 22: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

Point-to-point Connections

Page 23: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

Legacy Indirection Layer

Page 24: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with
Page 25: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

© 2017 Pivotal Software, Inc. All rights reserved.@kennybastani

Spring BootA JVM micro-framework for building microservices

25

Page 26: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

What is Spring Boot?

Page 27: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

@kennybastani

spring boot

Spring Initializr for bootstrapping your applications

supports rapid development of production-ready applications and services

Page 28: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

© 2017 Pivotal Software, Inc. All rights reserved.@kennybastani

Cloud PlatformsShipping applications in containers instead of shared application servers

28

Page 29: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

@kennybastani

Microservices: Container Deployment

Each microservice can be containerized with their application dependencies

Containers get scheduled on virtual machines with an allotted resource policy

Page 30: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

@kennybastani

Container scheduling and auto-scalingMinutes to provision and start a VM, but seconds to schedule and start a container

Auto-scaling becomes a feature of the cloud platform by scheduling on pool of VMs

Page 31: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

@kennybastani

Distributed ApplicationsEach microservice will likely need to communicate with other containers

Service discovery automates how distributed apps find service dependencies

Page 32: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

© 2017 Pivotal Software, Inc. All rights reserved.@kennybastani

Spring CloudA toolset designed for building distributed systems

32

Page 33: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

@kennybastani

What is Spring Cloud?Spring Cloud provides a way to turn Spring Boot microservices into distributed applications

Page 34: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

© 2017 Pivotal Software, Inc. All rights reserved.@kennybastani

Spring Cloud DemosApplying the patterns of cloud-native architectures with Spring Boot and Spring Cloud

34

Page 35: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

Service Discovery

Allows applications to find each other in an environment

An essential component when using dynamic container scheduling

Each application handles its own routing

Developers only need the name of a dependency, not the URL

A service registry is distributed to all subscriber applications

Page 36: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

Service Discovery

Page 37: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

Service Registry

Page 38: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

@kennybastani

Client-side Load Balancing

• Create discovery service

• Register user service

• Register user client

• Scale user service

• Reverse proxy from user client to user service

UserService

UserService

UserClient

Page 39: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

@kennybastani

Client-side Load Balancing

• Create discovery service

• Register user service

• Register user client

• Scale user service

• Reverse proxy from user client to user service

UserService

UserService

UserClient

Page 40: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

@kennybastani

Client-side Load Balancing

• Create discovery service

• Register user service

• Register user client

• Scale user service

• Reverse proxy from user client to user service

UserService

UserService

UserClient

Page 41: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

@kennybastani

Client-side Load Balancing

• Create discovery service

• Register user service

• Register user client

• Scale user service

• Reverse proxy from user client to user service

UserService

UserService

UserClient

Page 42: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with
Page 43: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

© 2017 Pivotal Software, Inc. All rights reserved.@kennybastani

Config ServerCentralizing config management for microservices with Spring Cloud Config Server

43

Page 44: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

Config Server

Allows applications to source configuration from central service

Application configuration can be changed without deployment

Cascading configuration files for all apps and individual apps

Uses Git repository as file system, providing audit log of changes

Add Spring Cloud Bus to automate config refresh for many instances

Page 45: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

Configuration Server

Page 46: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with
Page 47: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

© 2017 Pivotal Software, Inc. All rights reserved.@kennybastani

API GatewayBuilding edge services that route requests to backend microservices

47

Page 48: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with
Page 49: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with
Page 50: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

Edge Service

API gateway pattern using Spring Cloud Netflix Zuul starter project

Embeds relative routes from other services registered with Eureka

Automatic method for reverse proxying to other services

Routes are displayed at /routes of the Spring Boot app

Page 51: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with
Page 52: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

© 2017 Pivotal Software, Inc. All rights reserved.@kennybastani

Distributed TracingTracing the Online Store

52

Page 53: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

Spring Cloud Sleuth

Spring Cloud Sleuth is a project that adds distributed tracing capabilities to your distributed Spring Boot applications

https://cloud.spring.io/spring-cloud-sleuth/ http://zipkin.io/

Page 54: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

Zipkin Dashboard

Page 55: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with
Page 56: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

© 2017 Pivotal Software, Inc. All rights reserved.@kennybastani

Spring Cloud ContractConsumer-driven contract testing

56

Page 57: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

Consumer-driven Contracts

Page 58: © 2017 Pivotal Software, Inc. All rights reserved. 1...API gateway pattern using Spring Cloud Netflix Zuul starter project Embeds relative routes from other services registered with

© 2017 Pivotal Software, Inc. All rights reserved. @kennybastani

Thanks!

58