cloud native microservices using spring boot

51
‹#› © 2014 Pivotal Software, Inc. All rights reserved. ‹#› © 2014 Pivotal Software, Inc. All rights reserved. Cloud Native Applications Hands on Workshop David Ferreira Pinto <[email protected]> Field Engineering - Pivotal

Upload: sufyaan-kazi

Post on 15-Apr-2017

335 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved. ‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Cloud Native Applications Hands on Workshop

David Ferreira Pinto <[email protected]> Field Engineering - Pivotal

Page 2: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

> whoami David Ferreira Pinto

Page 3: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Agenda

•What’s changing? • Implications on applications • help is here! •Workshop •Competition •Deploying and running Cloud Native applications •Wrap up •Pizza & Beers

Page 4: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

How it used to be

User Registration Catalog

Orders Profile Search

Recommendation Lists Account

Middleware

OS

User Registration Catalog

Orders Profile Search

Recommendation Lists Account

Middleware

OS

Page 5: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

•Downtime for upgrades •One small change/fix - whole new release

•Scalability - vertical/horizontal? •Size for peaks - Crystal ball analysisTM

•Snowflakes

Page 6: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

The world has changed

Page 7: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

•Distributed computing •Decoupling of components • Latency of communication •Dependencies •Scale as you grow - Size for “now” •Cost efficiencies

Page 8: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

The rules for the cloud

1. S#!t happens! • assume the worst!

2. See (1)

A central truth in cloud computing is that failure is inevitable.  As systems scale, we expect nodes to fail ungracefully in random and unexpected ways, networks to experience sudden partitions, and messages to be dropped at any time.

Rather than fight this truth, we embrace it. HEATHER NAKAMA

Software Engineer, Azure Search

Page 9: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

What does this mean for applications?•Scalability • Inter-dependency •Platform dependency • Location dependency •Resiliency/Availability • Traceability

Page 10: Cloud native Microservices using Spring Boot

© Copyright 2014 Pivotal. All rights reserved. 10

Scalability•  Traditional applications have been

modeled as monolithic due an easy deployment model

•  Several services are combined into one massive single application

•  This model leads to a poor use of resources when it comes to scaling out your application

•  Greedy components steal resources from others that are collocated with them

User Registration Catalog

Orders Profile Search

Recommendation Lists Account

Page 11: Cloud native Microservices using Spring Boot

© Copyright 2014 Pivotal. All rights reserved. 11

.

User Registration Catalog

Orders Profile Search

Recommendation Lists Account

User Registration Catalog

Orders Profile Search

Recommendation Lists Account

User Registration Catalog

Orders Profile Search

Recommendation Lists Account

User Registration Catalog

Orders Profile Search

Recommendation Lists Account

User Registration Catalog

Orders Profile Search

Recommendation Lists Account

Page 12: Cloud native Microservices using Spring Boot

© Copyright 2014 Pivotal. All rights reserved. 12

How you should scale

0 1000000 2000000 3000000 4000000 5000000 6000000

Catalog

Search

Recommendation

Lists

Orders

Profile

User

Account

Registration

Requests

Requests

Page 13: Cloud native Microservices using Spring Boot

© Copyright 2014 Pivotal. All rights reserved. 13

Inter dependency

•Monolithic applications represent component dependency as strong bindings at the code level

• It makes harder to get an independent scalable model promoted by service oriented architectures

Page 14: Cloud native Microservices using Spring Boot

© Copyright 2014 Pivotal. All rights reserved. 14

Platform specificity

import javax.servlet.http.HttpServlet;

import com.ibm.servlet.engine.webapp.*;

•Hard dependencies on the runtime environment make applications not portable •At code level with runtime

dependencies •At OS level (relying on cron as a

scheduler)

Page 15: Cloud native Microservices using Spring Boot

© Copyright 2014 Pivotal. All rights reserved. 15

Location Specificity : Writing to disk

• Applications often need to write to disk, this includes form uploads with binary data, or content in most CMS systems

• Containers are short lived and not guaranteed to be executed on the same hardware every time they are needed to restart. Depending on a local file system is a big lock dependency some applications impose on the runtime

• Some CMS vendors support usage of a service such as S3 to be the persistent mechanism of choice

Page 16: Cloud native Microservices using Spring Boot

© Copyright 2014 Pivotal. All rights reserved. 16

Location Specificity : service locations

Cache.hosts=10.68.27.41,10.68.27.42

#naming does not help either Cache.hosts=cacheserver1, cacheserver2

Properties file deployed With application

Page 17: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

12 factor Apps - 12factor.net1. Codebase

One codebase tracked in revision control, many deploys

2. DependenciesExplicitly declare and isolate dependencies

3. ConfigStore config in the environment

4. Backing ServicesTreat backing services as attached resources

5. Build, release, runStrictly separate build and run stages

6. ProcessesExecute the app as one or more stateless processes

7. Port binding Export services via port binding

8. ConcurrencyScale out via the process model

9. Disposability Maximize robustness with fast startup and graceful shutdown

10.Dev/prod parity Keep development, staging, and production as similar as possible

11.Logs Treat logs as event streams

12.Admin processesRun admin/management tasks as one-off processes

Page 18: Cloud native Microservices using Spring Boot

© Copyright 2014 Pivotal. All rights reserved.

Monolithic Architecture

18

Relational Database

Data Access

Service

HTML JavaScript MVC

Service

Monolithic ApplicationBrowser

Page 19: Cloud native Microservices using Spring Boot

© Copyright 2014 Pivotal. All rights reserved.

Microservice Architecture

19

HTTP

HTTP

HTTP

HTTP

HTTP

HTTP

AMQPAMQP

Relational DB

Key/Value Store

Graph DB

Page 20: Cloud native Microservices using Spring Boot

© Copyright 2014 Pivotal. All rights reserved. 20

Microservice Architectures•Modularity Based on Component Services •Change Cycles Decoupled / Enable Frequent Deploys • Efficient Scaling • Individual Components Less Intimidating to New

Developers • Enables Scaling of Development • Eliminates Long-Term Commitment to Technical Stack

Page 21: Cloud native Microservices using Spring Boot

© Copyright 2014 Pivotal. All rights reserved.

Organize Around Business Capabilities

21

Data Access

Service

HTML JavaScript MVC

Service

UI S

pecialists

Middlew

are S

pecialists

DB

As

Business C

apability

Business C

apability

Business C

apabilitySiloed Functional Teams

http://martinfowler.com/articles/microservices.html#OrganizedAroundBusinessCapabilities

Siloed Application Architectures

Cross- functional Teams

Microservice Architectures

Page 22: Cloud native Microservices using Spring Boot

‹#›© 2015 Pivotal Software, Inc. All rights reserved.

•Manage Configuration Data provided to µServices via the environment reliably?(Factor-3) •Update Configuration Data to all µServices instances simultaneously? •Ensure µServices can discover each other, despite being Disposable?

(Factor-9) •Handle load-balancing between µServices of the same type? (Factor-8) •Guard against cascading failures when all instances of the same µService

fail? •Ensure resiliency by restoring failed µServices?

12 factors is not enough, Distributed Systems are hard!!!

HOW DO WE:

Page 23: Cloud native Microservices using Spring Boot

‹#›© 2015 Pivotal Software, Inc. All rights reserved.

Help is Here!

Spring Cloud Quickly add Distributed

Systems Patterns to your µServices

withPivotal Cloud Foundry

Keeps your µServices running!

Page 24: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Service registry & discovery - Eureka

Page 25: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Service registry & discovery - Eureka

@SpringBootApplication@EnableEurekaServer //@EnableDiscoveryClientpublic class RegistryApplication {public static void main(String[] args) {SpringApplication.run(RegistryApplication.class, args);

}}

Page 26: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Client-side load balancing - Ribbon

Page 27: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Client-side load balancing - Ribbon

@Autowired@LoadBalancedprivate RestTemplate restTemplate;

Quote quote = restTemplate.getForObject("http://quotes/quote/{symbol}", Quote.class, symbol);

Page 28: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Circuit Breaker - Hystrix

Page 29: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Circuit Breaker - Hystrix@HystrixCommand(fallbackMethod = "getCompaniesFallback")public List<CompanyInfo> getCompanies(String name) {

CompanyInfo[] infos = restTemplate.getForObject("http://quotes/company/{name}", CompanyInfo[].class, name);

return Arrays.asList(infos);}

private List<CompanyInfo> getCompaniesFallback(String name) {List<CompanyInfo> infos = new ArrayList<>();return infos;

}

Page 30: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Configuration Server

Page 31: Cloud native Microservices using Spring Boot

‹#›© 2015 Pivotal Software, Inc. All rights reserved.

Spring Cloud Services for PCF https://network.pivotal.io/products/p-spring-cloud-services

Page 32: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved. ‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Workshop

Page 33: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Spring Trader Application

Page 34: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

• Services: • Quotes service • Accounts service • Portfolio service • Web service

Spring Trader Application

http://bit.ly/1RLHzXQ or https://github.com/dpinto-pivotal/cf-SpringBootTrader

Quotes

Accounts Portfolio

Web

DB DB

Discovery Service

Circuit Breaker Dashboard

Page 35: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Competition

•Make the most money!!! •Create account with 100,000 •Buy and sell as much as you want. •When I say so, sell everything! •Highest account balance wins!

Page 36: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Setup

•You will need some tools (lab 1). • If you don’t want to install tools on your laptop, we

have a VM you can use.

Page 37: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Exercises• Deploy applications to Cloud Foundry

1. Set up the environment 2. Deploy the registry service 3. Create a user-provided service 4. Deploy quote microservice 5. Deploy all services at one 6. Scaling applications 7. Zero downtime deployments 8. Application Performance Monitoring

Page 38: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Lab 1: Set up the environment•Goal is to ensure you have all the tools and accounts to run

through the rest of the exercises. • Java 8 • git CLI — install git cli (or other git tool that allows you to clone repo) — clone the repository locally. • CF CLI — install CF CLI to allow you to interact with PCF • Build code - ./gradlew build - could take sometime…

Page 39: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Lab 1: Login to Pivotal Cloud Foundry• Login to Pivotal’s test environment • cf login -a api.emea.fe.pivotal.io • user: PodX •Password: PodX

• browser: http://console.emea.fe.pivotal.io

Page 40: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Lab 2 & 3: Create the Services

•Create a service called: discovery-service

• bind it to your space

•Create a service called: circuit-breaker-dashboard • bind it to your space

Page 41: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

And you may as well….

•Create a service called: traderdb

• bind it to your space

•Can be any RDBMS ie. Postgres, ClearDB, etc.

Page 42: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Lab 4 & 5: Pushing micro services

• cf push -f manifest-quotes.yml

•And same for accounts, portfolio and web.

Page 43: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

CompetitionBuy shares!!!!

Page 44: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Lab 6: Scaling the services

• cf scale quotes -i 2 • yes it is that simple!!!

•What happens when you scale the other services? • is there one that behaves differently? •How can we solve this?

Page 45: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Lab 7: Zero downtime deployments

• edit manifest-quote.yml • cf push -f manifest-

quote.yml

•What happens in Discovery Service dashboard?

--- timeout: 180 instances: 1 memory: 330M env: SPRING_PROFILES_DEFAULT: cloud JAVA_OPTS: -Djava.security.egd=file:///dev/urandom applications: - name: quotes-2 random-route: true path: springboottrades-quotes/build/libs/quotes-0.2.jar services: [ discovery-service ]

Page 46: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Lab 8: Application Performance Monitoring

•Go To Marketplace •Create new relic service and bind it to app •Re-Push the apps • In your App Manager UI, accept the license. •wait a few minutes • check newrelic dashboard.

Page 47: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

And the winner is….

Page 48: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved. ‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Wrap up

Page 49: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

Summary

• It’s a different world! • decoupling of application and infrastructure

processes • decoupling of application components •Platform to automate the running of applications • Framework to simplify development of cloud

applications

Page 50: Cloud native Microservices using Spring Boot

‹#›© 2014 Pivotal Software, Inc. All rights reserved.

What’s next?• Topics for future meetups? • What would you like to hear/discuss? • Examples: • Drill down into each cloud service e.g. Circuit Breaker • API management • Continuous Delivery • Logging/Monitoring • APM

• Any presenters? • Format? • Time?

Page 51: Cloud native Microservices using Spring Boot