Rechercher

Ce contenu n'est pas disponible dans la langue sélectionnée.

Chapter 1. Introduction to the circuit breaker add-on for Red Hat build of Node.js

download PDF

Red Hat provides a circuit breaker add-on for Red Hat build of Node.js, which is a fully supported implementation of the open source Opossum module. Opossum is a Node.js module developed by the NodeShift project team to provide circuit breaker functionality. You can use the circuit breaker add-on in your Node.js applications to ensure that application failures are monitored and handled appropriately.

Note

In the subsequent sections of this document, the term "circuit breaker" refers to the circuit breaker add-on for Red Hat build of Node.js.

1.1. Importance of handling application failures in microservice architectures

The circuit breaker add-on helps to reduce the impact of failures on service architectures, where services asynchronously invoke other services.

A failure can occur in either of the following situations:

  • If a service is unable to respond to requests in a timely manner because of latency issues and unusually high traffic volumes
  • If a service is temporarily unavailable because of network connection issues

In these situations, other services might exhaust critical resources by attempting to contact a service that is too slow or unable to respond. These other services can then become unusable, which causes a cascading failure that affects the entire microservice architecture. By using the circuit breaker add-on in your Node.js application code, you can make your applications more fault tolerant and resilient.

1.2. Circuit breaker design pattern

The circuit breaker pattern is designed to handle failures in service architectures and to prevent cascading failures across multiple systems. A circuit breaker can act as a proxy for a client function that is sending requests to a remote service endpoint that might fail. You can wrap any requests sent to the remote service endpoint in a circuit breaker object. The circuit breaker then calls the remote service and monitors its status. If the number of failures reaches a specified percentage threshold, the circuit breaker is triggered. The circuit breaker then ensures that any further requests to the remote service are automatically blocked with an error message or fallback response for a specified time period.

Based on the circuit breaker design pattern, the circuit breaker has one of the following states at any specific time:

Closed
The number of failures is below the specified percentage threshold that can trigger the circuit breaker. You can define the percentage threshold as an optional parameter that is passed to the circuit breaker in your Node.js application. The default percentage threshold is 50%. When the number of failures is low and the circuit breaker is closed, the client function can continue to send requests to the remote service endpoint.
Open
The number of failures has reached the specified percentage threshold that triggers the circuit breaker. For example, based on the default options, the circuit breaker moves to an open state if 50% of requests fail. The circuit breaker then blocks all calls to the remote service endpoint, with an error message or fallback response, for a specified timeout period. You can define the timeout period as an optional parameter that is passed to the circuit breaker in your Node.js application. The default timeout period is 30 seconds.
Half open
The specified timeout period has ended. For example, based on the default options, the timeout period ends and the circuit breaker moves to a half-open state after 30 seconds. The circuit breaker then attempts to send a limited number of test calls to the remote service endpoint. If the test calls succeed, the circuit breaker moves to a closed state, and the client function can continue to send requests to the remote service. However, if the test calls fail, the circuit breaker reverts to an open state, and it continues to block all calls to the remote service for the specified timeout period.
Red Hat logoGithubRedditYoutubeTwitter

Apprendre

Essayez, achetez et vendez

Communautés

À propos de la documentation Red Hat

Nous aidons les utilisateurs de Red Hat à innover et à atteindre leurs objectifs grâce à nos produits et services avec un contenu auquel ils peuvent faire confiance.

Rendre l’open source plus inclusif

Red Hat s'engage à remplacer le langage problématique dans notre code, notre documentation et nos propriétés Web. Pour plus de détails, consultez leBlog Red Hat.

À propos de Red Hat

Nous proposons des solutions renforcées qui facilitent le travail des entreprises sur plusieurs plates-formes et environnements, du centre de données central à la périphérie du réseau.

© 2024 Red Hat, Inc.