Tracing and Circuit-Breaker with Microservices


Up to now I have discussed about using Spring Boot for developing microservices [1]. Netflix stack has provided utility solutions for microservices deployments. And I have shown some of those solutions can be used with Spring Boot microservices [2]. So this article is going to be a continuation from the last article on microservices. In here I am going to discuss on using Zipkin tracing, Hystrix Circuit-Breaker and Hystrix Dashboard with Turbine.

The use-case so far

The use-case we have taken is 2 microservices; payment-service and customerinfo-service communicating each other and fronted by a gateway service (based on Zuul). Eureka-service sits as a registry service and helps to figure out the correct service. In this article we are going to implement tracing functionality and circuit-breaker functionality to payment-service.

Implementing zipkin-service

Zipkin is the solution provided in Netflix OSS for distributed tracing of requests. To add it to your microservice setup, you need to implement the zipkin-service first and then configure other services to send tracing events to that service.

First add following two dependencies to each service’s pom file

Then you have to create the zipkin-service with following artifacts, similar to other microservices.

pom.xml file, refer : file with @EnableZipkinServer annotation

package com.buddhima.example.service.zipkin;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import zipkin.server.EnableZipkinServer;

public class Application {

    public static void main(String[] args) {
        new SpringApplication(Application.class).run(args);

application.yml file

  port: 9411

    name: zipkin-service

Following image depicts zipkin tracing of a request through microservices:


Implementing Hystrix Circuit-Breaker

In short, a circuit-breaker is a design pattern which helps clients to be fault-tolerant with frequently failing endpoints. You will get a more detailed explanation on that concept through references [3], [4].

In this case I have added circuit-breaker functionality to the client-implementation of customerinfo-service at payment-service. In last article I have discussed how feign is used as the client. In addition to those attributes mentioned, we need to add hystrix dependencies in the pom file, implement fallback methods and point to those at feign client definition.

Following dependencies are required for hystrix and hystrix-dashboard

<!-- dependency for hystrix -->

<!-- dependencies for hystrix-dashboard -->


Together with Hystrix, I have enabled Hystrix-Dashboard to view the status of each endpoint. This can be done via @EnableCircuitBreaker, @EnableHystrixDashboard annotations.

Then the client interface has been modified, specifying the fallback class as below:

package com.buddhima.example.service.payment.clients;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@FeignClient(value = "customerinfo-service", path = "/customerinfo", fallback = CustomerInfoClientFallback.class)
public interface CustomerInfoClient {

@RequestMapping(method = RequestMethod.GET, value = "/name")
public String getName();

@RequestMapping(method = RequestMethod.GET, value = "/age")
public int getAge();

You can refer the implementation of CustomerInfoClientFallback at here:

By-default endpoint dashboard is per microservice, which is not usable when you have many microservices. Therefore Netflix has introduced a solution called Turbine which can aggregate the endpoint statuses of each microservice and construct an aggregated stream to be displayed at hystrix-dashboard.

You may refer source code of turbine-service at here:

In the configuration file (application.yml), I have specified the names of microservices which need to be monitored

port: 9060

name: turbine-service

defaultZone: http://localhost:8761/eureka/
preferIpAddress: true

clusterNameExpression: new String("default")
combineHostPort: true

(Here I have configured hystrix in the payment-service only. You may add hystrix configs to other services as well)

Hystrix Dashboard

You can check the git repository containing the complete source code at here [5].


[1] Getting start with Spring Boot :
[2] Netflix OSS with Spring Boot :
[3] How Hystrix works :
[4] Spring sample for Circuit-Breaker :
[5] Source code :


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s