SlideShare a Scribd company logo
1 of 79
Download to read offline
Building ‘Bootiful’
microservices cloud
Powered by Spring Cloud Netflix libraries
Idan Fridman, Tikal
Agenda
● Microservices - Quick overview
● Implementing microservices - Build your endpoints with Spring-Boot
● Spring Cloud and Netflix
● Service Discovery: Eureka instances
● Circuit Breaker: Hystrix
● Client Side Load Balancer: Ribbon
● Router and Filter: Automatic registration of Zuul
● RxJava: Aggregation of multiple micro-service requests
● Declarative REST Client: Feign
● There is a strong trend in distributed systems with lightweight
architectures
● People have started to call them "microservices"
What are microservices?
(In short, I promise;P)
● Smaller units of a larger system
small enough to be owned by a small agile development team
re-writable within one or two agile sprints ( typically two to four
weeks)
The complexity does not require to refactoring or require further
divide into another microservice.
● Not monolithic
● Runs in its own process
Running independently of the application If fail app
won't fail and deliver workarounds
Life continues as if nothing has happened.
● Lightweight communication protocols
Rely on HTTP(Rest, etc..) or a lightweight
message bus
Establish a boundary between components
Ensures loose coupling.
● Single responsibility principle(SRP)
Should perform a single business function
Must be functionally complete
Also knowns as bounded context from
Domain-Driven Design
● Independent data source
Soa vs Microservices
- SOA and microservices don’t conflict or replace each other -> they
complement
- SOA is about how to reuse existing functionality as services
- Microservices is about how to make functionality to scale better with high
resilience and short release cycles...
Challenges with Microservices
● Distributed/versioned configuration
○ Auto configurations and refresh on runtime
● New services can auto-register at startup
○ Service registration and discovery
● Routing and load balancing
○ Clients can detect new instances as they are started up
● Centralized log management
○ Collects and visualize log events from distributed processes
● Circuit Breaker
○ Prevent problems with chain of failures
● Security
Open source to the rescue
Agenda
● Microservices - Quick overview
● Implementing microservices - Build your endpoints with Spring-Boot
● Spring Cloud and Netflix
● Service Discovery: Eureka instances
● Circuit Breaker: Hystrix
● Client Side Load Balancer: Ribbon
● Router and Filter: automatic registration of Zuul
● RxJava: Aggregation of multiple micro-service requests
● Declarative REST Client: Feign
Build your endpoints with Spring-
Boot
It can get pretty much small:
@RestController
class ThisWillActuallyRun {
@RequestMapping("/")
String home() {
"Hello World!"
}
}
Pretty much micro?
Spring Boot
● A tool for getting started very quickly with Spring
● Common non-functional requirements for a "real" application
● Exposes a lot of useful features by default
● Gets out of the way quickly if you want to change defaults
● Available for web, batch, integration, data, amqp, aop, jdbc, ...
Spring Boot Modules
● Spring Boot - main library supporting the other parts of Spring Boot
● Spring Boot Autoconfigure - single @EnableAutoConfiguration annotation
creates a whole Spring context
● Spring Boot Starters - a set of convenient dependency descriptors that you
can include in your application.
Spring Boot Modules
● Spring Boot Actuator - common non-functional features that make an app
instantly deployable and supportable in production
● Spring Boot Tools - for building and executing self-contained JAR and
WAR archives
● Spring Boot Samples - a wide range of sample apps
Agenda
● Microservices - Quick overview
● Implementing microservices - Build your endpoints with Spring-Boot
● Spring Cloud and Netflix
● Service Discovery: Eureka instances
● Circuit Breaker: Hystrix
● Client Side Load Balancer: Ribbon
● Router and Filter: automatic registration of Zuul
● RxJava: Aggregation of multiple micro-service requests
● Declarative REST Client: Feign
Spring cloud - Netflix
● Spring Cloud Netflix provides Netflix OSS integration
● With simple annotations enable and configure can build large distributed
systems with battle-tested Netflix components.
● The patterns provided include Service Discovery (Eureka), Circuit Breaker
(Hystrix), Intelligent Routing (Zuul) and Client Side Load Balancing
(Ribbon)..
System Setup
System Landscape
Agenda
● Microservices - Quick overview
● Implementing microservices - Build your endpoints with Spring-Boot
● Spring Cloud and Netflix
● Service Discovery: Eureka instances
● Circuit Breaker: Hystrix
● Client Side Load Balancer: Ribbon
● Router and Filter: automatic registration of Zuul
● RxJava: Aggregation of multiple micro-service requests
● Declarative REST Client: Feign
Service discovery Eureka
Discover
Motivation
● When you’re running your software across a large number of replaceable pieces of hardware, it’
s inevitable that one of them will fail at some point.
● In a cloud environment you are guaranteed failure, and it is absolutely
● Critical to have a service discovery system that can survive failures.
Eureka features
● Eureka has a built-in concept of service heartbeats to prevent stale data - if a service doesn’t phone home often enough,
then Eureka will remove the entry from the service registry
● HeartBeat - New services can register, but “dead” ones will be kept, just in case a client might still be able to contact them
● Cache - Eureka caches on the client side. So even if every last Eureka server goes down, or there is a partition where a
client can’t talk to any of the Eureka servers, then the service registry still won’t be lost.
● HA - The server can be configured and deployed to be highly available, with each server replicating state about the
registered services to the others.
Demo - 1
Agenda
● Microservices - Quick overview
● Implementing microservices - Build your endpoints with Spring-Boot
● Spring Cloud and Netflix
● Service Discovery: Eureka instances
● Circuit Breaker: Hystrix
● Netflix Turbine
● Client Side Load Balancer: Ribbon
● Router and Filter: automatic registration of Zuul
● RxJava: Aggregation of multiple micro-service requests
● Declarative REST Client: Feign
Circuit Breaker
What is the circuit breaker pattern?
● Communication with microservices(or any other services)
○ Remote calls
○ Different machines across a network
○ API calls and dependencies
● Unresponsive supplier
● Hang without a response
● Critical resources leading to cascading failures across systems
Failure risks
How it works?
Hystrix uses the bulkhead pattern to isolate dependencies and limit concurrent access.
The idea behind circuit breaker
1. Monitor For failures
2. Failure occur -> Circuit is open -> Protected call wont be made -> Do something else + raise alert
3. Need external intervention to reset it when things are well again
Not all errors should trip the circuit, some should reflect normal failures and be dealt regularly
Remote function
call
Circuit breaker object
wrapper
Circuit breaker monitoring
● Any change in breaker state should be logged
● Breakers should reveal details of their state for deeper monitoring
What’s next after the break?
● You need to consider what to do in case of failure.
○ perhaps business decision?
○ Workarounds?
○ Show partials results?
Examples:
1. A bank action authorization could be put on a queue to deal with later.
2. Show partial content (better than nothing right?)
Circuit Breaker and Hystrix
What’s Hystrix?
● Hystrix evolved out of resilience engineering work that the Netflix API team began in 2011
● Isolating points of access between the services
● Handling fallbacks and protect API calls by stopping them(defining thresholds, etc..)
● Provide temporary fallback exchanges
● Monitoring dashboard to watch our our critical access points
Taken from spring.io:
HystrixCommand
● Wrap calls to dependencies in a HystrixCommand object
● HystrixCommand follows the command pattern and typically executes within a separate thread
● Hystrix maintains a thread-pool (or semaphore) for each dependency and rejects requests
(instead of queuing requests)
● if the thread-pool becomes exhausted -> It provides circuit-breaker functionality that can stop all
requests to a dependency.
Spring cloud for the rescue
● Using spring-cloud-netflix library we can implement circuit breaker logic
easily:
○ Hystrix Synchronous
○ Hystrix Asynchronous
○ Hystrix Observable
Hystrix synchronous
fallbackMethod
@HystrixCommand(fallbackMethod = "fallbackInvocation")
private void generateService(ObjectInput input) {
//invoke your service
}
public void fallbackInvocation(ObjectInput input) {
//keepDefaultvalues
//raise alert
//getNextServer from Eureka and invoke the method
//return data from a local cache
}
Hystrix asynchronous
Using future
@HystrixCommand(fallbackMethod = "stubbedBro")
public Future<String> runFutureBro(final String name) {
return new AsyncResult<String>() {
public String invoke() {
return(executeRemoteService(name));
}
};}
//and somewhere else:
this.runFutureBro(name).get();
Hystrix asynchronous
Using subscriptions
@HystrixCommand(fallbackMethod = "stubbedBro")
public Observable<String> executeObservableBro(String name) {
return new ObservableResult<String>() {
@Override
public String invoke() {
return executeRemoteService(name);
}
};
}
Hystrix asynchronous
Using subscriptions
broConsumerService.executeObservableBro(input).subscribe(new Observer<String>() {
@Override
public void onCompleted() {
System.out.println("completed");
}
@Override
public void onError(Throwable e) {
System.out.printf(e.getMessage());
}
@Override
public void onNext(String s) {
System.out.println("on next.." + s);
}
});
Command properties
@HystrixCommand(commandProperties = {
//execute on local thread or separate thread(Thread,Semaphore)
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "500")
//sets the time in milliseconds after which the caller will observe a timeout and walk away from the command
//execution (default 1000)
},
threadPoolProperties = {
@HystrixProperty(name = "coreSize", value = "30"),
//maximum number of HystrixCommands that can execute concurrently
@HystrixProperty(name="hystrix.command.default.circuitBreaker.requestVolumeThreshold",
value = "30"),
//sets the minimum number of requests in a rolling window that will trip the circuit.
//maximum queue size
@HystrixProperty(name = "metrics.rollingStats.numBuckets", value = "12"),
@HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds", value = "1440")
})
Drawbacks
● Each command execution involves:
○ Queueing
○ Scheduling
○ Context switching involved in running a command on a separate thread.
● Netflix’s experiences proved it minor enough to not have major cost or performance impact.
Demo - 2
Protected with Hystrix
Hystrix Dashboard
● You can Monitor your access points(wrapped points) via ui dashboard and grab metrics
Enabling HystrixDashboards
Add @EnableHystrixDashboard
Demo-3
Agenda
● Microservices - Quick overview
● Implementing microservices - Build your endpoints with Spring-Boot
● Spring Cloud and Netflix
● Service Discovery: Eureka instances
● Circuit Breaker: Hystrix
● Netflix Turbine
● Client Side Load Balancer: Ribbon
● Router and Filter: automatic registration of Zuul
● RxJava for aggregation of micro-service requests
● Declarative REST Client: Feign
Netflix Turbine
● Aggregating metrics streams from all cloud instances into one stream
● Use case: Use Hystrix real-time dashboard that uses Turbine to aggregate
from many machines
Demo
Rabbitmq
● Turbine can aggregate all streams by receiving all clients metrics via amqp
● Hystrix commands push metrics to Turbine and Spring Cloud enables that
with AMQP messaging
● Hysteric use RabbitMQ to communicate between circuit breakers and
dashboards
Annotate your turbine server with:
@EnableTurbineAmqp
Have all your Hystrix clients importing:
compile("org.springframework.cloud:spring-cloud-starter-hystrix:1.0.0.RELEASE")
compile("org.springframework.cloud:spring-cloud-starter-bus-amqp:1.0.0.RELEASE")
compile("org.springframework.cloud:spring-cloud-netflix-hystrix-amqp:1.0.0.RELEASE")
That library has everything you need in order to find running rabbitMQ broker and start pushing
messages.
In your Hystrix dashboard add the turbine’s amqp listening port: http://host:8989 (set via application.
yaml)
Demo4
1. Start rabbitmq sbin/rabbitmq-server
2. Stream Turbine using port 8989
[demo]
Agenda
● Microservices - Quick overview
● Implementing microservices - Build your endpoints with Spring-Boot
● Spring Cloud and Netflix
● Service Discovery: Eureka instances
● Circuit Breaker: Hystrix
● Netflix Turbine
● Client Side Load Balancer: Ribbon
● Router and Filter: automatic registration of Zuul
● RxJava: Aggregation of multiple micro-service requests
● Declarative REST Client: Feign
Netflix Ribbon
Client Side Load Balancing
● Dynamic Routing
● Load Balancer
● Support rules:
○ round robin
○ response time weighted
○ random load balancing
○ Custom rules
● Ribbon does not run as a separate service but instead as an embedded component in each service consumer.
Using Ribbon with Eureka
● Ribbon includes load balancers that are capable of service discovery in a dynamic environment
● Ribbon uses the information available in Eureka to locate appropriate service instances.
● Ribbon will apply load balancing to spread the requests over the available instances.
● Add new instance dynamically -> Registered automatically on discovery services -> Ribbon choose instance to
invoke
Ribbon Example
Ribbon and RestTemplate
● Inject RestTemplate and use your instance-id
● Spring Cloud Ribbon will handle automatically the load-balancing
@EnableEurekaClient
@RestController
public class Application {
@Autowired
RestTemplate restTemplate
@RequestMapping("/")
String consume() {
Response response = restTemplate.getForObject("http://baggage-service", Response.class)
}
}
Does make sense: Eureka’s service name
The ribbon-loadbalancer must be on the classpath (e.g. via "spring-cloud-starter-
ribbon").
Then you can inject one as a LoadBalancerClient or you can inject a RestTemplate
(it will be load-balancer aware if you have a LoadBalancerClient).
Demo
Agenda
● Microservices - Quick overview
● Implementing microservices - Build your endpoints with Spring-Boot
● Spring Cloud and Netflix
● Service Discovery: Eureka instances
● Circuit Breaker: Hystrix
● Netflix Turbine
● Client Side Load Balancer: Ribbon
● Router and Filter: automatic registration of Zuul
● RxJava for aggregation of micro-service requests
● Declarative REST Client: Feign
Netflix Zuul - Edge Server
Zuul the Gatekeeper of Gozer
The Gatekeeper
of our microservices world
● Entry point to the microservices
● Zuul is a JVM based router and server side load balancer by Netflix.
● Intelligent Routing
● Using Ribbon to lookup available services and routes the external request to an
appropriate service instance
● By default Zuul set up a route to every service it can find in Eureka
Using Routings
● Routing in an integral part of a microservice architecture.
For example, / -> mapped to your web application,
/api/bookings -> mapped to the flight-booking service
/api/coupon -> mapped to the coupon service.
Zuul harmonically integrated with Netflix stack
● Zuul using Ribbon to locate an instance to forward to via Eureka
● All requests are executed in a hystrix command -> failures will show up in
Hystrix metrics
● once the circuit is open the proxy will not try to contact the service.
Use cases
● Use case where a UI application wants to proxy calls to one or more back end service
●
Other use cases:
● Authentication
● Stress Testing
● Security
● Service Migration
● Active/Active traffic management
Set your routings
On application.yaml you can set your routings and roles
In this example all services are ignored except coupon-service.
[Demo]
Demo - 5
Agenda
● Microservices - Quick overview
● Implementing microservices - Build your endpoints with Spring-Boot
● Spring Cloud and Netflix
● Service Discovery: Eureka instances
● Circuit Breaker: Hystrix
● Netflix Turbine
● Client Side Load Balancer: Ribbon
● Router and Filter: automatic registration of Zuul
● RxJava: Aggregation of multiple micro-service requests
● Declarative REST Client: Feign
How many services being called?
Scenario Example
1. Client calls to our app’s web service ->
2. our webservice need to request multiple micro-services->
3. uses a callbacks interface to pass the successful result to the
next web service call
4. define another success callback- >
5. and then moves on to the next web service request.
Orchestrator
A B C F
Client Request
Looks like that->
Also known as:
“The Callback Hell”
//The "Nested Callbacks" Way
public void fetchUserDetails() {
//first, request the users...
mService.requestUsers(new Callback<GithubUsersResponse>() {
@Override
public void success(final GithubUsersResponse githubUsersResponse,
final Response response) {
Timber.i(TAG, "Request Users request completed");
final List<GithubUserDetail> githubUserDetails = new ArrayList<GithubUserDetail>();
//next, loop over each item in the response
for (GithubUserDetail githubUserDetail : githubUsersResponse) {
//request a detail object for that user
mService.requestUserDetails(githubUserDetail.mLogin,
new Callback<GithubUserDetail>() {
@Override
public void success(GithubUserDetail githubUserDetail,
Response response) {
Log.i("User Detail request completed for user : " + githubUserDetail.mLogin);
githubUserDetails.add(githubUserDetail);
if (githubUserDetails.size() == githubUsersResponse.mGithubUsers.size()) {
//we've downloaded'em all - notify all who are interested!
Async our microservices call
(Using Reactor)
A library for composing asynchronous and
event-based programs by using observable sequences.
● Allow you to compose sequences together declaratively
● Abstracting away :
○ low-level threading
○ synchronization
○ thread-safety
○ concurrent data structures
○ non-blocking I/O.
RxJava for the rescue
● RxJava is single jar lightweight library.
● Using the Observable abstraction and related higher-order functions.
(Support Java6+)
The following external libraries can work with RxJava:
● Camel RX provides an easy way to reuse any of the Apache Camel components, protocols, transports and data
formats with the RxJava API
● rxjava-http-tail allows you to follow logs over HTTP, like tail -f
● mod-rxvertx - Extension for VertX that provides support for Reactive Extensions (RX) using the RxJava library
And ->> Hystrix latency and fault tolerance bulkheading library. (Which is why we here)
Using Observables
“Go do this thing and when that thing is done then invoke
that other code”
@HystrixCommand(fallbackMethod = "stubbedBro")
public Observable<String> executeObservableBro(String name) {
return new ObservableResult<String>() {
@Override
public String invoke() {
return executeRemoteService(name);
}
};
}
Agenda
● Microservices - Quick overview
● Implementing microservices - Build your endpoints with Spring-Boot
● Spring Cloud and Netflix
● Service Discovery: Eureka instances
● Circuit Breaker: Hystrix
● Netflix Turbine
● Client Side Load Balancer: Ribbon
● Router and Filter: automatic registration of Zuul
● RxJava: Aggregation of multiple micro-service requests
● Declarative REST Client: Feign
Demo
Feign Client
● It makes writing web service clients easier
● Feign connect your code to http API’S with minimal overhead.
● Maps to the REST API methods that are exposed by a service
● Customizable decoders and error handlings
● Feign works by processing annotations into a templatized request
Feign and Spring-Cloud
● Create interface and annotate
● Support Feign annotations and JAX-RS annotations
● Collaborated with Spring-MVC annotations(Using convertors like: HttpMessageConverters )
● Eureka-aware REST clients that uses Ribbon for client-side load-balancing to pick an available
service instance
● You can call methods on an interface instead of manually handling URLs, Spring Cloud takes
care of auto-instantiating the interface implementation and will use Eureka for discovery.
Demo 6
Thank You:)

More Related Content

What's hot

Cloud Foundry for Spring Developers
Cloud Foundry for Spring DevelopersCloud Foundry for Spring Developers
Cloud Foundry for Spring DevelopersGunnar Hillert
 
Developing Resilient Cloud Native Apps with Spring Cloud
Developing Resilient Cloud Native Apps with Spring CloudDeveloping Resilient Cloud Native Apps with Spring Cloud
Developing Resilient Cloud Native Apps with Spring CloudDustin Ruehle
 
Kubernetes your next application server
Kubernetes  your next application serverKubernetes  your next application server
Kubernetes your next application serverRed Hat Developers
 
Open Service Broker APIとKubernetes Service Catalog #k8sjp
Open Service Broker APIとKubernetes Service Catalog #k8sjpOpen Service Broker APIとKubernetes Service Catalog #k8sjp
Open Service Broker APIとKubernetes Service Catalog #k8sjpToshiaki Maki
 
Cloud Native Microservices with Spring Cloud
Cloud Native Microservices with Spring CloudCloud Native Microservices with Spring Cloud
Cloud Native Microservices with Spring CloudConor Svensson
 
Serverless and Servicefull Applications - Where Microservices complements Ser...
Serverless and Servicefull Applications - Where Microservices complements Ser...Serverless and Servicefull Applications - Where Microservices complements Ser...
Serverless and Servicefull Applications - Where Microservices complements Ser...Red Hat Developers
 
CDK Meetup: Rule the World through IaC
CDK Meetup: Rule the World through IaCCDK Meetup: Rule the World through IaC
CDK Meetup: Rule the World through IaCsmalltown
 
Vert.x for Microservices Architecture
Vert.x for Microservices ArchitectureVert.x for Microservices Architecture
Vert.x for Microservices ArchitectureIdan Fridman
 
Winning the Lottery with Spring: A Microservices Case Study for the Dutch Lot...
Winning the Lottery with Spring: A Microservices Case Study for the Dutch Lot...Winning the Lottery with Spring: A Microservices Case Study for the Dutch Lot...
Winning the Lottery with Spring: A Microservices Case Study for the Dutch Lot...VMware Tanzu
 
What’s New in Spring Batch?
What’s New in Spring Batch?What’s New in Spring Batch?
What’s New in Spring Batch?VMware Tanzu
 
MicroServices at Netflix - challenges of scale
MicroServices at Netflix - challenges of scaleMicroServices at Netflix - challenges of scale
MicroServices at Netflix - challenges of scaleSudhir Tonse
 
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entitySpring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entityToni Jara
 
A Series of Fortunate Events: Building an Operator in Java
A Series of Fortunate Events: Building an Operator in JavaA Series of Fortunate Events: Building an Operator in Java
A Series of Fortunate Events: Building an Operator in JavaVMware Tanzu
 
Create Great CNCF User-Base from Lessons Learned from Other Open Source Commu...
Create Great CNCF User-Base from Lessons Learned from Other Open Source Commu...Create Great CNCF User-Base from Lessons Learned from Other Open Source Commu...
Create Great CNCF User-Base from Lessons Learned from Other Open Source Commu...Lee Calcote
 
Game of Streams: How to Tame and Get the Most from Your Messaging Platforms
Game of Streams: How to Tame and Get the Most from Your Messaging PlatformsGame of Streams: How to Tame and Get the Most from Your Messaging Platforms
Game of Streams: How to Tame and Get the Most from Your Messaging PlatformsVMware Tanzu
 
Microservices - java ee vs spring boot and spring cloud
Microservices - java ee vs spring boot and spring cloudMicroservices - java ee vs spring boot and spring cloud
Microservices - java ee vs spring boot and spring cloudBen Wilcock
 
Microservices with Micronaut
Microservices with MicronautMicroservices with Micronaut
Microservices with MicronautQAware GmbH
 
Security model for a remote company
Security model for a remote companySecurity model for a remote company
Security model for a remote companyPierre Mavro
 

What's hot (20)

Cloud Foundry for Spring Developers
Cloud Foundry for Spring DevelopersCloud Foundry for Spring Developers
Cloud Foundry for Spring Developers
 
Developing Resilient Cloud Native Apps with Spring Cloud
Developing Resilient Cloud Native Apps with Spring CloudDeveloping Resilient Cloud Native Apps with Spring Cloud
Developing Resilient Cloud Native Apps with Spring Cloud
 
Kubernetes your next application server
Kubernetes  your next application serverKubernetes  your next application server
Kubernetes your next application server
 
Open Service Broker APIとKubernetes Service Catalog #k8sjp
Open Service Broker APIとKubernetes Service Catalog #k8sjpOpen Service Broker APIとKubernetes Service Catalog #k8sjp
Open Service Broker APIとKubernetes Service Catalog #k8sjp
 
Cloud Native Microservices with Spring Cloud
Cloud Native Microservices with Spring CloudCloud Native Microservices with Spring Cloud
Cloud Native Microservices with Spring Cloud
 
Serverless and Servicefull Applications - Where Microservices complements Ser...
Serverless and Servicefull Applications - Where Microservices complements Ser...Serverless and Servicefull Applications - Where Microservices complements Ser...
Serverless and Servicefull Applications - Where Microservices complements Ser...
 
CDK Meetup: Rule the World through IaC
CDK Meetup: Rule the World through IaCCDK Meetup: Rule the World through IaC
CDK Meetup: Rule the World through IaC
 
Vert.x for Microservices Architecture
Vert.x for Microservices ArchitectureVert.x for Microservices Architecture
Vert.x for Microservices Architecture
 
Winning the Lottery with Spring: A Microservices Case Study for the Dutch Lot...
Winning the Lottery with Spring: A Microservices Case Study for the Dutch Lot...Winning the Lottery with Spring: A Microservices Case Study for the Dutch Lot...
Winning the Lottery with Spring: A Microservices Case Study for the Dutch Lot...
 
What’s New in Spring Batch?
What’s New in Spring Batch?What’s New in Spring Batch?
What’s New in Spring Batch?
 
MicroServices at Netflix - challenges of scale
MicroServices at Netflix - challenges of scaleMicroServices at Netflix - challenges of scale
MicroServices at Netflix - challenges of scale
 
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entitySpring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
 
A Series of Fortunate Events: Building an Operator in Java
A Series of Fortunate Events: Building an Operator in JavaA Series of Fortunate Events: Building an Operator in Java
A Series of Fortunate Events: Building an Operator in Java
 
Create Great CNCF User-Base from Lessons Learned from Other Open Source Commu...
Create Great CNCF User-Base from Lessons Learned from Other Open Source Commu...Create Great CNCF User-Base from Lessons Learned from Other Open Source Commu...
Create Great CNCF User-Base from Lessons Learned from Other Open Source Commu...
 
Game of Streams: How to Tame and Get the Most from Your Messaging Platforms
Game of Streams: How to Tame and Get the Most from Your Messaging PlatformsGame of Streams: How to Tame and Get the Most from Your Messaging Platforms
Game of Streams: How to Tame and Get the Most from Your Messaging Platforms
 
Microservices - java ee vs spring boot and spring cloud
Microservices - java ee vs spring boot and spring cloudMicroservices - java ee vs spring boot and spring cloud
Microservices - java ee vs spring boot and spring cloud
 
Istio presentation jhug
Istio presentation jhugIstio presentation jhug
Istio presentation jhug
 
OPNFV & OpenStack
OPNFV & OpenStackOPNFV & OpenStack
OPNFV & OpenStack
 
Microservices with Micronaut
Microservices with MicronautMicroservices with Micronaut
Microservices with Micronaut
 
Security model for a remote company
Security model for a remote companySecurity model for a remote company
Security model for a remote company
 

Viewers also liked

Hystrix in Action - Ein Weg zu robuster Software
Hystrix in Action - Ein Weg zu robuster SoftwareHystrix in Action - Ein Weg zu robuster Software
Hystrix in Action - Ein Weg zu robuster Softwareinovex GmbH
 
Spring 3.1 and MVC Testing Support - 4Developers
Spring 3.1 and MVC Testing Support - 4DevelopersSpring 3.1 and MVC Testing Support - 4Developers
Spring 3.1 and MVC Testing Support - 4DevelopersSam Brannen
 
Chicago Hadoop Users Group: Enterprise Data Workflows
Chicago Hadoop Users Group: Enterprise Data WorkflowsChicago Hadoop Users Group: Enterprise Data Workflows
Chicago Hadoop Users Group: Enterprise Data WorkflowsPaco Nathan
 
Reactive Programming With Akka - Lessons Learned
Reactive Programming With Akka - Lessons LearnedReactive Programming With Akka - Lessons Learned
Reactive Programming With Akka - Lessons LearnedDaniel Sawano
 
The no-framework Scala Dependency Injection Framework
The no-framework Scala Dependency Injection FrameworkThe no-framework Scala Dependency Injection Framework
The no-framework Scala Dependency Injection FrameworkAdam Warski
 
A Sceptical Guide to Functional Programming
A Sceptical Guide to Functional ProgrammingA Sceptical Guide to Functional Programming
A Sceptical Guide to Functional ProgrammingGarth Gilmour
 
Effective akka scalaio
Effective akka scalaioEffective akka scalaio
Effective akka scalaioshinolajla
 
Actor Based Asyncronous IO in Akka
Actor Based Asyncronous IO in AkkaActor Based Asyncronous IO in Akka
Actor Based Asyncronous IO in Akkadrewhk
 
Efficient HTTP Apis
Efficient HTTP ApisEfficient HTTP Apis
Efficient HTTP ApisAdrian Cole
 
Spring Cloud and Netflix OSS overview v1
Spring Cloud and Netflix OSS overview v1Spring Cloud and Netflix OSS overview v1
Spring Cloud and Netflix OSS overview v1Dmitry Skaredov
 
Beginning Haskell, Dive In, Its Not That Scary!
Beginning Haskell, Dive In, Its Not That Scary!Beginning Haskell, Dive In, Its Not That Scary!
Beginning Haskell, Dive In, Its Not That Scary!priort
 
C*ollege Credit: Creating Your First App in Java with Cassandra
C*ollege Credit: Creating Your First App in Java with CassandraC*ollege Credit: Creating Your First App in Java with Cassandra
C*ollege Credit: Creating Your First App in Java with CassandraDataStax
 
Service discovery with Eureka and Spring Cloud
Service discovery with Eureka and Spring CloudService discovery with Eureka and Spring Cloud
Service discovery with Eureka and Spring CloudMarcelo Serpa
 
Effective Actors
Effective ActorsEffective Actors
Effective Actorsshinolajla
 
Effective Scala (SoftShake 2013)
Effective Scala (SoftShake 2013)Effective Scala (SoftShake 2013)
Effective Scala (SoftShake 2013)mircodotta
 
Using Apache Solr
Using Apache SolrUsing Apache Solr
Using Apache Solrpittaya
 
Composable and streamable Play apps
Composable and streamable Play appsComposable and streamable Play apps
Composable and streamable Play appsYevgeniy Brikman
 

Viewers also liked (20)

Hystrix in Action - Ein Weg zu robuster Software
Hystrix in Action - Ein Weg zu robuster SoftwareHystrix in Action - Ein Weg zu robuster Software
Hystrix in Action - Ein Weg zu robuster Software
 
Spring 3.1 and MVC Testing Support - 4Developers
Spring 3.1 and MVC Testing Support - 4DevelopersSpring 3.1 and MVC Testing Support - 4Developers
Spring 3.1 and MVC Testing Support - 4Developers
 
Chicago Hadoop Users Group: Enterprise Data Workflows
Chicago Hadoop Users Group: Enterprise Data WorkflowsChicago Hadoop Users Group: Enterprise Data Workflows
Chicago Hadoop Users Group: Enterprise Data Workflows
 
Reactive Programming With Akka - Lessons Learned
Reactive Programming With Akka - Lessons LearnedReactive Programming With Akka - Lessons Learned
Reactive Programming With Akka - Lessons Learned
 
The no-framework Scala Dependency Injection Framework
The no-framework Scala Dependency Injection FrameworkThe no-framework Scala Dependency Injection Framework
The no-framework Scala Dependency Injection Framework
 
A Sceptical Guide to Functional Programming
A Sceptical Guide to Functional ProgrammingA Sceptical Guide to Functional Programming
A Sceptical Guide to Functional Programming
 
Effective akka scalaio
Effective akka scalaioEffective akka scalaio
Effective akka scalaio
 
Actor Based Asyncronous IO in Akka
Actor Based Asyncronous IO in AkkaActor Based Asyncronous IO in Akka
Actor Based Asyncronous IO in Akka
 
Efficient HTTP Apis
Efficient HTTP ApisEfficient HTTP Apis
Efficient HTTP Apis
 
Spring Cloud and Netflix OSS overview v1
Spring Cloud and Netflix OSS overview v1Spring Cloud and Netflix OSS overview v1
Spring Cloud and Netflix OSS overview v1
 
Beginning Haskell, Dive In, Its Not That Scary!
Beginning Haskell, Dive In, Its Not That Scary!Beginning Haskell, Dive In, Its Not That Scary!
Beginning Haskell, Dive In, Its Not That Scary!
 
C*ollege Credit: Creating Your First App in Java with Cassandra
C*ollege Credit: Creating Your First App in Java with CassandraC*ollege Credit: Creating Your First App in Java with Cassandra
C*ollege Credit: Creating Your First App in Java with Cassandra
 
Service discovery with Eureka and Spring Cloud
Service discovery with Eureka and Spring CloudService discovery with Eureka and Spring Cloud
Service discovery with Eureka and Spring Cloud
 
Effective Actors
Effective ActorsEffective Actors
Effective Actors
 
Spring cloud sleuth
Spring cloud sleuthSpring cloud sleuth
Spring cloud sleuth
 
Curator intro
Curator introCurator intro
Curator intro
 
Unix Philosophy
Unix PhilosophyUnix Philosophy
Unix Philosophy
 
Effective Scala (SoftShake 2013)
Effective Scala (SoftShake 2013)Effective Scala (SoftShake 2013)
Effective Scala (SoftShake 2013)
 
Using Apache Solr
Using Apache SolrUsing Apache Solr
Using Apache Solr
 
Composable and streamable Play apps
Composable and streamable Play appsComposable and streamable Play apps
Composable and streamable Play apps
 

Similar to Building ‘Bootiful’ microservices cloud

2017 Microservices Practitioner Virtual Summit: Microservices at Squarespace ...
2017 Microservices Practitioner Virtual Summit: Microservices at Squarespace ...2017 Microservices Practitioner Virtual Summit: Microservices at Squarespace ...
2017 Microservices Practitioner Virtual Summit: Microservices at Squarespace ...Ambassador Labs
 
Developing Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideDeveloping Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideMohanraj Thirumoorthy
 
Microservices and modularity with java
Microservices and modularity with javaMicroservices and modularity with java
Microservices and modularity with javaDPC Consulting Ltd
 
'How to build efficient backend based on microservice architecture' by Anton ...
'How to build efficient backend based on microservice architecture' by Anton ...'How to build efficient backend based on microservice architecture' by Anton ...
'How to build efficient backend based on microservice architecture' by Anton ...OdessaJS Conf
 
Lagom : Reactive microservice framework
Lagom : Reactive microservice frameworkLagom : Reactive microservice framework
Lagom : Reactive microservice frameworkFabrice Sznajderman
 
Easy Microservices with JHipster - Devoxx BE 2017
Easy Microservices with JHipster - Devoxx BE 2017Easy Microservices with JHipster - Devoxx BE 2017
Easy Microservices with JHipster - Devoxx BE 2017Deepu K Sasidharan
 
Devoxx Belgium 2017 - easy microservices with JHipster
Devoxx Belgium 2017 - easy microservices with JHipsterDevoxx Belgium 2017 - easy microservices with JHipster
Devoxx Belgium 2017 - easy microservices with JHipsterJulien Dubois
 
Kenzan: Architecting for Microservices
Kenzan: Architecting for MicroservicesKenzan: Architecting for Microservices
Kenzan: Architecting for MicroservicesDarren Bathgate
 
Day in the life event-driven workshop
Day in the life  event-driven workshopDay in the life  event-driven workshop
Day in the life event-driven workshopChristina Lin
 
NetflixOSS Open House Lightning talks
NetflixOSS Open House Lightning talksNetflixOSS Open House Lightning talks
NetflixOSS Open House Lightning talksRuslan Meshenberg
 
Comparison of Current Service Mesh Architectures
Comparison of Current Service Mesh ArchitecturesComparison of Current Service Mesh Architectures
Comparison of Current Service Mesh ArchitecturesMirantis
 
Monolithic to Microservices Migration Journey of iyzico with Spring Cloud
Monolithic to Microservices Migration Journey of iyzico with Spring CloudMonolithic to Microservices Migration Journey of iyzico with Spring Cloud
Monolithic to Microservices Migration Journey of iyzico with Spring CloudMustafa Can Tekir
 
Triangle Devops Meetup 10/2015
Triangle Devops Meetup 10/2015Triangle Devops Meetup 10/2015
Triangle Devops Meetup 10/2015aspyker
 
Microservices @ Work - A Practice Report of Developing Microservices
Microservices @ Work - A Practice Report of Developing MicroservicesMicroservices @ Work - A Practice Report of Developing Microservices
Microservices @ Work - A Practice Report of Developing MicroservicesQAware GmbH
 
Monolithic to microservices migration journey with spring cloud
Monolithic to microservices migration journey with spring cloudMonolithic to microservices migration journey with spring cloud
Monolithic to microservices migration journey with spring cloudzeynelkocak
 
C. Sotiriou, Vodafone Greece: Adopting Quarkus for the digital experience layer
C. Sotiriou, Vodafone Greece: Adopting Quarkus for the digital experience layerC. Sotiriou, Vodafone Greece: Adopting Quarkus for the digital experience layer
C. Sotiriou, Vodafone Greece: Adopting Quarkus for the digital experience layerUni Systems S.M.S.A.
 
Better Deployments with Sub Environments Using Spring Cloud and Netflix Ribbon
Better Deployments with Sub Environments Using Spring Cloud and Netflix RibbonBetter Deployments with Sub Environments Using Spring Cloud and Netflix Ribbon
Better Deployments with Sub Environments Using Spring Cloud and Netflix RibbonVMware Tanzu
 
Spring cloud for microservices architecture
Spring cloud for microservices architectureSpring cloud for microservices architecture
Spring cloud for microservices architectureIgor Khotin
 
OpenStack Neutron: What's New In Kilo and a Look Toward Liberty
OpenStack Neutron: What's New In Kilo and a Look Toward LibertyOpenStack Neutron: What's New In Kilo and a Look Toward Liberty
OpenStack Neutron: What's New In Kilo and a Look Toward Libertymestery
 

Similar to Building ‘Bootiful’ microservices cloud (20)

2017 Microservices Practitioner Virtual Summit: Microservices at Squarespace ...
2017 Microservices Practitioner Virtual Summit: Microservices at Squarespace ...2017 Microservices Practitioner Virtual Summit: Microservices at Squarespace ...
2017 Microservices Practitioner Virtual Summit: Microservices at Squarespace ...
 
Developing Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideDeveloping Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's Guide
 
Microservices and modularity with java
Microservices and modularity with javaMicroservices and modularity with java
Microservices and modularity with java
 
'How to build efficient backend based on microservice architecture' by Anton ...
'How to build efficient backend based on microservice architecture' by Anton ...'How to build efficient backend based on microservice architecture' by Anton ...
'How to build efficient backend based on microservice architecture' by Anton ...
 
Springboot Microservices
Springboot MicroservicesSpringboot Microservices
Springboot Microservices
 
Lagom : Reactive microservice framework
Lagom : Reactive microservice frameworkLagom : Reactive microservice framework
Lagom : Reactive microservice framework
 
Easy Microservices with JHipster - Devoxx BE 2017
Easy Microservices with JHipster - Devoxx BE 2017Easy Microservices with JHipster - Devoxx BE 2017
Easy Microservices with JHipster - Devoxx BE 2017
 
Devoxx Belgium 2017 - easy microservices with JHipster
Devoxx Belgium 2017 - easy microservices with JHipsterDevoxx Belgium 2017 - easy microservices with JHipster
Devoxx Belgium 2017 - easy microservices with JHipster
 
Kenzan: Architecting for Microservices
Kenzan: Architecting for MicroservicesKenzan: Architecting for Microservices
Kenzan: Architecting for Microservices
 
Day in the life event-driven workshop
Day in the life  event-driven workshopDay in the life  event-driven workshop
Day in the life event-driven workshop
 
NetflixOSS Open House Lightning talks
NetflixOSS Open House Lightning talksNetflixOSS Open House Lightning talks
NetflixOSS Open House Lightning talks
 
Comparison of Current Service Mesh Architectures
Comparison of Current Service Mesh ArchitecturesComparison of Current Service Mesh Architectures
Comparison of Current Service Mesh Architectures
 
Monolithic to Microservices Migration Journey of iyzico with Spring Cloud
Monolithic to Microservices Migration Journey of iyzico with Spring CloudMonolithic to Microservices Migration Journey of iyzico with Spring Cloud
Monolithic to Microservices Migration Journey of iyzico with Spring Cloud
 
Triangle Devops Meetup 10/2015
Triangle Devops Meetup 10/2015Triangle Devops Meetup 10/2015
Triangle Devops Meetup 10/2015
 
Microservices @ Work - A Practice Report of Developing Microservices
Microservices @ Work - A Practice Report of Developing MicroservicesMicroservices @ Work - A Practice Report of Developing Microservices
Microservices @ Work - A Practice Report of Developing Microservices
 
Monolithic to microservices migration journey with spring cloud
Monolithic to microservices migration journey with spring cloudMonolithic to microservices migration journey with spring cloud
Monolithic to microservices migration journey with spring cloud
 
C. Sotiriou, Vodafone Greece: Adopting Quarkus for the digital experience layer
C. Sotiriou, Vodafone Greece: Adopting Quarkus for the digital experience layerC. Sotiriou, Vodafone Greece: Adopting Quarkus for the digital experience layer
C. Sotiriou, Vodafone Greece: Adopting Quarkus for the digital experience layer
 
Better Deployments with Sub Environments Using Spring Cloud and Netflix Ribbon
Better Deployments with Sub Environments Using Spring Cloud and Netflix RibbonBetter Deployments with Sub Environments Using Spring Cloud and Netflix Ribbon
Better Deployments with Sub Environments Using Spring Cloud and Netflix Ribbon
 
Spring cloud for microservices architecture
Spring cloud for microservices architectureSpring cloud for microservices architecture
Spring cloud for microservices architecture
 
OpenStack Neutron: What's New In Kilo and a Look Toward Liberty
OpenStack Neutron: What's New In Kilo and a Look Toward LibertyOpenStack Neutron: What's New In Kilo and a Look Toward Liberty
OpenStack Neutron: What's New In Kilo and a Look Toward Liberty
 

Building ‘Bootiful’ microservices cloud

  • 1. Building ‘Bootiful’ microservices cloud Powered by Spring Cloud Netflix libraries Idan Fridman, Tikal
  • 2. Agenda ● Microservices - Quick overview ● Implementing microservices - Build your endpoints with Spring-Boot ● Spring Cloud and Netflix ● Service Discovery: Eureka instances ● Circuit Breaker: Hystrix ● Client Side Load Balancer: Ribbon ● Router and Filter: Automatic registration of Zuul ● RxJava: Aggregation of multiple micro-service requests ● Declarative REST Client: Feign
  • 3. ● There is a strong trend in distributed systems with lightweight architectures ● People have started to call them "microservices"
  • 4. What are microservices? (In short, I promise;P)
  • 5. ● Smaller units of a larger system small enough to be owned by a small agile development team re-writable within one or two agile sprints ( typically two to four weeks) The complexity does not require to refactoring or require further divide into another microservice. ● Not monolithic ● Runs in its own process Running independently of the application If fail app won't fail and deliver workarounds Life continues as if nothing has happened. ● Lightweight communication protocols Rely on HTTP(Rest, etc..) or a lightweight message bus Establish a boundary between components Ensures loose coupling. ● Single responsibility principle(SRP) Should perform a single business function Must be functionally complete Also knowns as bounded context from Domain-Driven Design ● Independent data source
  • 6. Soa vs Microservices - SOA and microservices don’t conflict or replace each other -> they complement - SOA is about how to reuse existing functionality as services - Microservices is about how to make functionality to scale better with high resilience and short release cycles...
  • 7. Challenges with Microservices ● Distributed/versioned configuration ○ Auto configurations and refresh on runtime ● New services can auto-register at startup ○ Service registration and discovery ● Routing and load balancing ○ Clients can detect new instances as they are started up ● Centralized log management ○ Collects and visualize log events from distributed processes ● Circuit Breaker ○ Prevent problems with chain of failures ● Security
  • 8. Open source to the rescue
  • 9. Agenda ● Microservices - Quick overview ● Implementing microservices - Build your endpoints with Spring-Boot ● Spring Cloud and Netflix ● Service Discovery: Eureka instances ● Circuit Breaker: Hystrix ● Client Side Load Balancer: Ribbon ● Router and Filter: automatic registration of Zuul ● RxJava: Aggregation of multiple micro-service requests ● Declarative REST Client: Feign
  • 10. Build your endpoints with Spring- Boot It can get pretty much small: @RestController class ThisWillActuallyRun { @RequestMapping("/") String home() { "Hello World!" } } Pretty much micro?
  • 11. Spring Boot ● A tool for getting started very quickly with Spring ● Common non-functional requirements for a "real" application ● Exposes a lot of useful features by default ● Gets out of the way quickly if you want to change defaults ● Available for web, batch, integration, data, amqp, aop, jdbc, ...
  • 12. Spring Boot Modules ● Spring Boot - main library supporting the other parts of Spring Boot ● Spring Boot Autoconfigure - single @EnableAutoConfiguration annotation creates a whole Spring context ● Spring Boot Starters - a set of convenient dependency descriptors that you can include in your application.
  • 13. Spring Boot Modules ● Spring Boot Actuator - common non-functional features that make an app instantly deployable and supportable in production ● Spring Boot Tools - for building and executing self-contained JAR and WAR archives ● Spring Boot Samples - a wide range of sample apps
  • 14. Agenda ● Microservices - Quick overview ● Implementing microservices - Build your endpoints with Spring-Boot ● Spring Cloud and Netflix ● Service Discovery: Eureka instances ● Circuit Breaker: Hystrix ● Client Side Load Balancer: Ribbon ● Router and Filter: automatic registration of Zuul ● RxJava: Aggregation of multiple micro-service requests ● Declarative REST Client: Feign
  • 15. Spring cloud - Netflix ● Spring Cloud Netflix provides Netflix OSS integration ● With simple annotations enable and configure can build large distributed systems with battle-tested Netflix components. ● The patterns provided include Service Discovery (Eureka), Circuit Breaker (Hystrix), Intelligent Routing (Zuul) and Client Side Load Balancing (Ribbon)..
  • 17. Agenda ● Microservices - Quick overview ● Implementing microservices - Build your endpoints with Spring-Boot ● Spring Cloud and Netflix ● Service Discovery: Eureka instances ● Circuit Breaker: Hystrix ● Client Side Load Balancer: Ribbon ● Router and Filter: automatic registration of Zuul ● RxJava: Aggregation of multiple micro-service requests ● Declarative REST Client: Feign
  • 19. Motivation ● When you’re running your software across a large number of replaceable pieces of hardware, it’ s inevitable that one of them will fail at some point. ● In a cloud environment you are guaranteed failure, and it is absolutely ● Critical to have a service discovery system that can survive failures.
  • 20. Eureka features ● Eureka has a built-in concept of service heartbeats to prevent stale data - if a service doesn’t phone home often enough, then Eureka will remove the entry from the service registry ● HeartBeat - New services can register, but “dead” ones will be kept, just in case a client might still be able to contact them ● Cache - Eureka caches on the client side. So even if every last Eureka server goes down, or there is a partition where a client can’t talk to any of the Eureka servers, then the service registry still won’t be lost. ● HA - The server can be configured and deployed to be highly available, with each server replicating state about the registered services to the others.
  • 21.
  • 23. Agenda ● Microservices - Quick overview ● Implementing microservices - Build your endpoints with Spring-Boot ● Spring Cloud and Netflix ● Service Discovery: Eureka instances ● Circuit Breaker: Hystrix ● Netflix Turbine ● Client Side Load Balancer: Ribbon ● Router and Filter: automatic registration of Zuul ● RxJava: Aggregation of multiple micro-service requests ● Declarative REST Client: Feign
  • 25. What is the circuit breaker pattern? ● Communication with microservices(or any other services) ○ Remote calls ○ Different machines across a network ○ API calls and dependencies ● Unresponsive supplier ● Hang without a response ● Critical resources leading to cascading failures across systems Failure risks
  • 26.
  • 27. How it works? Hystrix uses the bulkhead pattern to isolate dependencies and limit concurrent access.
  • 28. The idea behind circuit breaker 1. Monitor For failures 2. Failure occur -> Circuit is open -> Protected call wont be made -> Do something else + raise alert 3. Need external intervention to reset it when things are well again Not all errors should trip the circuit, some should reflect normal failures and be dealt regularly Remote function call Circuit breaker object wrapper
  • 29. Circuit breaker monitoring ● Any change in breaker state should be logged ● Breakers should reveal details of their state for deeper monitoring
  • 30. What’s next after the break? ● You need to consider what to do in case of failure. ○ perhaps business decision? ○ Workarounds? ○ Show partials results? Examples: 1. A bank action authorization could be put on a queue to deal with later. 2. Show partial content (better than nothing right?)
  • 32. What’s Hystrix? ● Hystrix evolved out of resilience engineering work that the Netflix API team began in 2011 ● Isolating points of access between the services ● Handling fallbacks and protect API calls by stopping them(defining thresholds, etc..) ● Provide temporary fallback exchanges ● Monitoring dashboard to watch our our critical access points Taken from spring.io:
  • 33. HystrixCommand ● Wrap calls to dependencies in a HystrixCommand object ● HystrixCommand follows the command pattern and typically executes within a separate thread ● Hystrix maintains a thread-pool (or semaphore) for each dependency and rejects requests (instead of queuing requests) ● if the thread-pool becomes exhausted -> It provides circuit-breaker functionality that can stop all requests to a dependency.
  • 34. Spring cloud for the rescue ● Using spring-cloud-netflix library we can implement circuit breaker logic easily: ○ Hystrix Synchronous ○ Hystrix Asynchronous ○ Hystrix Observable
  • 35. Hystrix synchronous fallbackMethod @HystrixCommand(fallbackMethod = "fallbackInvocation") private void generateService(ObjectInput input) { //invoke your service } public void fallbackInvocation(ObjectInput input) { //keepDefaultvalues //raise alert //getNextServer from Eureka and invoke the method //return data from a local cache }
  • 36. Hystrix asynchronous Using future @HystrixCommand(fallbackMethod = "stubbedBro") public Future<String> runFutureBro(final String name) { return new AsyncResult<String>() { public String invoke() { return(executeRemoteService(name)); } };} //and somewhere else: this.runFutureBro(name).get();
  • 37. Hystrix asynchronous Using subscriptions @HystrixCommand(fallbackMethod = "stubbedBro") public Observable<String> executeObservableBro(String name) { return new ObservableResult<String>() { @Override public String invoke() { return executeRemoteService(name); } }; }
  • 38. Hystrix asynchronous Using subscriptions broConsumerService.executeObservableBro(input).subscribe(new Observer<String>() { @Override public void onCompleted() { System.out.println("completed"); } @Override public void onError(Throwable e) { System.out.printf(e.getMessage()); } @Override public void onNext(String s) { System.out.println("on next.." + s); } });
  • 39. Command properties @HystrixCommand(commandProperties = { //execute on local thread or separate thread(Thread,Semaphore) @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "500") //sets the time in milliseconds after which the caller will observe a timeout and walk away from the command //execution (default 1000) }, threadPoolProperties = { @HystrixProperty(name = "coreSize", value = "30"), //maximum number of HystrixCommands that can execute concurrently @HystrixProperty(name="hystrix.command.default.circuitBreaker.requestVolumeThreshold", value = "30"), //sets the minimum number of requests in a rolling window that will trip the circuit. //maximum queue size @HystrixProperty(name = "metrics.rollingStats.numBuckets", value = "12"), @HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds", value = "1440") })
  • 40. Drawbacks ● Each command execution involves: ○ Queueing ○ Scheduling ○ Context switching involved in running a command on a separate thread. ● Netflix’s experiences proved it minor enough to not have major cost or performance impact.
  • 41. Demo - 2 Protected with Hystrix
  • 42. Hystrix Dashboard ● You can Monitor your access points(wrapped points) via ui dashboard and grab metrics
  • 43.
  • 46. Agenda ● Microservices - Quick overview ● Implementing microservices - Build your endpoints with Spring-Boot ● Spring Cloud and Netflix ● Service Discovery: Eureka instances ● Circuit Breaker: Hystrix ● Netflix Turbine ● Client Side Load Balancer: Ribbon ● Router and Filter: automatic registration of Zuul ● RxJava for aggregation of micro-service requests ● Declarative REST Client: Feign
  • 47. Netflix Turbine ● Aggregating metrics streams from all cloud instances into one stream ● Use case: Use Hystrix real-time dashboard that uses Turbine to aggregate from many machines Demo
  • 48. Rabbitmq ● Turbine can aggregate all streams by receiving all clients metrics via amqp ● Hystrix commands push metrics to Turbine and Spring Cloud enables that with AMQP messaging ● Hysteric use RabbitMQ to communicate between circuit breakers and dashboards
  • 49. Annotate your turbine server with: @EnableTurbineAmqp Have all your Hystrix clients importing: compile("org.springframework.cloud:spring-cloud-starter-hystrix:1.0.0.RELEASE") compile("org.springframework.cloud:spring-cloud-starter-bus-amqp:1.0.0.RELEASE") compile("org.springframework.cloud:spring-cloud-netflix-hystrix-amqp:1.0.0.RELEASE") That library has everything you need in order to find running rabbitMQ broker and start pushing messages. In your Hystrix dashboard add the turbine’s amqp listening port: http://host:8989 (set via application. yaml)
  • 50. Demo4 1. Start rabbitmq sbin/rabbitmq-server 2. Stream Turbine using port 8989
  • 52. Agenda ● Microservices - Quick overview ● Implementing microservices - Build your endpoints with Spring-Boot ● Spring Cloud and Netflix ● Service Discovery: Eureka instances ● Circuit Breaker: Hystrix ● Netflix Turbine ● Client Side Load Balancer: Ribbon ● Router and Filter: automatic registration of Zuul ● RxJava: Aggregation of multiple micro-service requests ● Declarative REST Client: Feign
  • 53. Netflix Ribbon Client Side Load Balancing ● Dynamic Routing ● Load Balancer ● Support rules: ○ round robin ○ response time weighted ○ random load balancing ○ Custom rules ● Ribbon does not run as a separate service but instead as an embedded component in each service consumer.
  • 54. Using Ribbon with Eureka ● Ribbon includes load balancers that are capable of service discovery in a dynamic environment ● Ribbon uses the information available in Eureka to locate appropriate service instances. ● Ribbon will apply load balancing to spread the requests over the available instances. ● Add new instance dynamically -> Registered automatically on discovery services -> Ribbon choose instance to invoke
  • 56. Ribbon and RestTemplate ● Inject RestTemplate and use your instance-id ● Spring Cloud Ribbon will handle automatically the load-balancing @EnableEurekaClient @RestController public class Application { @Autowired RestTemplate restTemplate @RequestMapping("/") String consume() { Response response = restTemplate.getForObject("http://baggage-service", Response.class) } } Does make sense: Eureka’s service name The ribbon-loadbalancer must be on the classpath (e.g. via "spring-cloud-starter- ribbon"). Then you can inject one as a LoadBalancerClient or you can inject a RestTemplate (it will be load-balancer aware if you have a LoadBalancerClient).
  • 57. Demo
  • 58. Agenda ● Microservices - Quick overview ● Implementing microservices - Build your endpoints with Spring-Boot ● Spring Cloud and Netflix ● Service Discovery: Eureka instances ● Circuit Breaker: Hystrix ● Netflix Turbine ● Client Side Load Balancer: Ribbon ● Router and Filter: automatic registration of Zuul ● RxJava for aggregation of micro-service requests ● Declarative REST Client: Feign
  • 59. Netflix Zuul - Edge Server Zuul the Gatekeeper of Gozer
  • 60. The Gatekeeper of our microservices world ● Entry point to the microservices ● Zuul is a JVM based router and server side load balancer by Netflix. ● Intelligent Routing ● Using Ribbon to lookup available services and routes the external request to an appropriate service instance ● By default Zuul set up a route to every service it can find in Eureka
  • 61. Using Routings ● Routing in an integral part of a microservice architecture. For example, / -> mapped to your web application, /api/bookings -> mapped to the flight-booking service /api/coupon -> mapped to the coupon service.
  • 62. Zuul harmonically integrated with Netflix stack ● Zuul using Ribbon to locate an instance to forward to via Eureka ● All requests are executed in a hystrix command -> failures will show up in Hystrix metrics ● once the circuit is open the proxy will not try to contact the service.
  • 63. Use cases ● Use case where a UI application wants to proxy calls to one or more back end service ● Other use cases: ● Authentication ● Stress Testing ● Security ● Service Migration ● Active/Active traffic management
  • 64. Set your routings On application.yaml you can set your routings and roles In this example all services are ignored except coupon-service. [Demo]
  • 66. Agenda ● Microservices - Quick overview ● Implementing microservices - Build your endpoints with Spring-Boot ● Spring Cloud and Netflix ● Service Discovery: Eureka instances ● Circuit Breaker: Hystrix ● Netflix Turbine ● Client Side Load Balancer: Ribbon ● Router and Filter: automatic registration of Zuul ● RxJava: Aggregation of multiple micro-service requests ● Declarative REST Client: Feign
  • 67. How many services being called?
  • 68. Scenario Example 1. Client calls to our app’s web service -> 2. our webservice need to request multiple micro-services-> 3. uses a callbacks interface to pass the successful result to the next web service call 4. define another success callback- > 5. and then moves on to the next web service request. Orchestrator A B C F Client Request
  • 69. Looks like that-> Also known as: “The Callback Hell”
  • 70. //The "Nested Callbacks" Way public void fetchUserDetails() { //first, request the users... mService.requestUsers(new Callback<GithubUsersResponse>() { @Override public void success(final GithubUsersResponse githubUsersResponse, final Response response) { Timber.i(TAG, "Request Users request completed"); final List<GithubUserDetail> githubUserDetails = new ArrayList<GithubUserDetail>(); //next, loop over each item in the response for (GithubUserDetail githubUserDetail : githubUsersResponse) { //request a detail object for that user mService.requestUserDetails(githubUserDetail.mLogin, new Callback<GithubUserDetail>() { @Override public void success(GithubUserDetail githubUserDetail, Response response) { Log.i("User Detail request completed for user : " + githubUserDetail.mLogin); githubUserDetails.add(githubUserDetail); if (githubUserDetails.size() == githubUsersResponse.mGithubUsers.size()) { //we've downloaded'em all - notify all who are interested!
  • 71. Async our microservices call (Using Reactor) A library for composing asynchronous and event-based programs by using observable sequences. ● Allow you to compose sequences together declaratively ● Abstracting away : ○ low-level threading ○ synchronization ○ thread-safety ○ concurrent data structures ○ non-blocking I/O.
  • 72. RxJava for the rescue ● RxJava is single jar lightweight library. ● Using the Observable abstraction and related higher-order functions. (Support Java6+) The following external libraries can work with RxJava: ● Camel RX provides an easy way to reuse any of the Apache Camel components, protocols, transports and data formats with the RxJava API ● rxjava-http-tail allows you to follow logs over HTTP, like tail -f ● mod-rxvertx - Extension for VertX that provides support for Reactive Extensions (RX) using the RxJava library And ->> Hystrix latency and fault tolerance bulkheading library. (Which is why we here)
  • 73. Using Observables “Go do this thing and when that thing is done then invoke that other code” @HystrixCommand(fallbackMethod = "stubbedBro") public Observable<String> executeObservableBro(String name) { return new ObservableResult<String>() { @Override public String invoke() { return executeRemoteService(name); } }; }
  • 74. Agenda ● Microservices - Quick overview ● Implementing microservices - Build your endpoints with Spring-Boot ● Spring Cloud and Netflix ● Service Discovery: Eureka instances ● Circuit Breaker: Hystrix ● Netflix Turbine ● Client Side Load Balancer: Ribbon ● Router and Filter: automatic registration of Zuul ● RxJava: Aggregation of multiple micro-service requests ● Declarative REST Client: Feign
  • 75. Demo
  • 76. Feign Client ● It makes writing web service clients easier ● Feign connect your code to http API’S with minimal overhead. ● Maps to the REST API methods that are exposed by a service ● Customizable decoders and error handlings ● Feign works by processing annotations into a templatized request
  • 77. Feign and Spring-Cloud ● Create interface and annotate ● Support Feign annotations and JAX-RS annotations ● Collaborated with Spring-MVC annotations(Using convertors like: HttpMessageConverters ) ● Eureka-aware REST clients that uses Ribbon for client-side load-balancing to pick an available service instance ● You can call methods on an interface instead of manually handling URLs, Spring Cloud takes care of auto-instantiating the interface implementation and will use Eureka for discovery.