Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Cloud-Native Microservices With Circuit Breakers and Service Discovery

DZone's Guide to

Cloud-Native Microservices With Circuit Breakers and Service Discovery

Because monoliths aren't realistic anymore, new design patterns have to emerge to solve the challenges of independent, distributed microservices.

· Integration Zone
Free Resource

Modernize your application architectures with microservices and APIs with best practices from this free virtual summit series. Brought to you in partnership with CA Technologies.

Cloud-native microservices offer many benefits. You can develop, test, deploy, and maintain independent lightweight services. You can easily combine various technologies, including programming languages such as Java or Go and tools like integration middleware.

However, as you do not build monoliths anymore, "that complexity has moved and […] increased [to] the outer architecture," as Gartner states. For this reason, new design patterns have to emerge to solve the challenges of independent, distributed microservices.

Middleware is used to interconnect everything. This is even more important in microservice architectures in which you have even more independent, distributed, and scaled business logic. Thus, as I discussed around two years ago, microservices might be the death of the Enterprise Service Bus, but integration and middleware (and other things like API management and cloud-native concepts) will be needed more than ever before for microservice architectures.

Circuit Breaker Design Pattern

The circuit breaker is one of the cloud-native design patterns. It offers the following benefits.

  • Fail fast and rapidly recover.
  • Prevent cascading failures.
  • Latency tolerance logic.
  • Fault tolerance logic.
  • Fallback options.

This is realized by rejecting service requests if a service is not available for whatever reason. In a microservice architecture, there can be many reasons or issues. The rejection is configured by various parameters such as request volume threshold and error threshold percentage.

Martin Fowler has a great explanation of the circuit breaker design pattern. Therefore, I will just explain it using one of his graphics:

circuit breaker diag

The circuit is closed in the beginning. All service requests get a successful response from the service. If a threshold of five failures is reached, the circuit is opened. New service requests are rejected. After a timeout of one minute, a new service request tries if the service is available again; therefore, the circuit is half-open in this state. Depending on the success or failure, the circuit is opened or closed after this service request.

This relatively simple pattern can get very powerful (depending on the configuration options) and allows us to build resilient microservice architectures with reduced latency and lowered resource consumption.

Hystrix: The Netflix Open-Source Implementation

Hystrix was open-sourced by Netflix a few years ago and is by far the most widely used framework for using the circuit breaker pattern in a microservices architecture.

Microservice architectures and cloud-native platforms such as CloudFoundry and Kubernetes can leverage Hystrix to build resilient microservice deployments. In addition, you can use the Hystrix Dashboard to get some near real-time visualization. The video Hystrix Dashboard: Tech Talk and Demo shows a great introduction. Here is a screenshot explaining the key aspects of the dashboard:

dashboard

The dashboard does its job. But in a more sophisticated microservices architecture, you might leverage the benefits or a real-time streaming analytics visualization tool such as Zoomdata, Striim, or TIBCO Live Datamart. This allows not just monitoring live streaming data, but also applies continuous aggregations, rules, consolidation, and predictive analytics for automated or human-driven decision-making instead of just showing a monitoring dashboard for every microservice.

Hystrix and Middleware

A resilient architecture is even more important for integration services because they interconnect everything. If the integration service is not resilient, fails all the time or get irresponsive, the complete enterprise gets into trouble. Therefore, circuit breakers can help a lot to make integration services more resilient.

A few middleware vendors already adopted cloud-native principles and offer native out-of-the-box support in their offerings. For example, Red Hat’s Middleware Services run on the Kubernetes-based OpenShift PaaS. WSO2 is another open source middleware vendor which already supports cloud-native platforms like Kubernetes. TIBCO offers BusinessWorks Container Edition (BWCE), which allows developers to build, test, and package an integration microservice once and deploy it everywhere, including Docker, Kubernetes, and CloudFoundry.

Note that cloud-native means much more than just putting your middleware into a Docker container! You need to support cloud-native concepts like circuit breakers and service discovery and integrate natively with frameworks like Hystrix, Consul, or Eureka. If you just put your existing application or middleware software into a container, then you just “cloud wash” your solution, and your architecture still looks like it did before it was leveraging cloud-native concepts.

The following shows the demo setup for the two videos recordings below. It includes several cloud-native components.

architecture diagram

With a focus on Circuit Breakers, we use TIBCO's BWCE, Docker, and Netflix’s Hystrix. The same could be achieved on other cloud-native platforms like Kubernetes or CloudFoundry in the same way.

BWCE offers out-of-the-box support for circuit breakers. You just enable it and configure the required parameters:

parameters

Details about the configuration and options can be found in the BWCE documentation. In the same way, you can also leverage service discovery frameworks like Consul or Eureka and combine that with cloud-native platforms like Kubernetes or CloudFoundry.

Conclusion

The following video shows how to use BWCE with Netflix’s Hystrix to develop, deploy, and monitor cloud-native middleware microservices:

In the next video, you can see how to deploy an independent middleware microservice using Docker, Kubernetes, and Cloud Foundry without re-compiling, re-testing, or re-packaging:

I appreciate any feedback or questions about cloud-native middleware or any other related topic.

The Integration Zone is proudly sponsored by CA Technologies. Learn from expert microservices and API presentations at the Modernizing Application Architectures Virtual Summit Series.

Topics:
microservices ,middleware ,circuit breaker ,service discovery ,histrix ,cloud-native ,integration

Published at DZone with permission of Kai Wähner, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}