Microservices

Bulkhead Pattern-MicroServices

Microservices are inherently distributed. In a distributed architecture, dealing with any unexpected failure is one of the biggest challenges to solve.

It could be a hardware failure, network failure, etc. The ability of the system to recover from the failures and remain functional makes the system more resilient. It also avoids any cascading errors.

Problem Statement:

Assume you have a request-based, multi-threaded application (for example a typical web application) that uses three different components, A, B, and C. If requests to component C start to hang, eventually all request handling threads will hang on waiting for an answer from C. This would make the application entirely non-responsive. If requests to C are handled slowly we have a similar problem if the load is high enough.

Bulkhead Pattern:

The bulkhead pattern is one type of error-tolerant application design. Bulkhead architecture isolates elements of the application into pools so that if one fails, the others continue to function.

The name of the bulkhead pattern comes from the shipbuilding practice of having ships with internal chambers that insulate the hull to prevent water from breaking through rocks and spreading across the ship if it sinks.

bulkhead pattern
Ship

In the same way, the application should be split into multiple components and resources should be isolated in such a way that the failure of one component is not affecting the other.

Partition service instances into different groups, based on consumer load and availability requirements. This design helps to isolate failures, and allows you to sustain service functionality for some consumers, even during a failure.

Benefits of this pattern:

  • Isolates consumers and services from cascading failures.
  • Allows you to preserve some functionality in the event of a service failure. Other services and features of the application will continue to work.
  • Allows you to deploy services that offer a different quality of service for consuming applications.

Drawbacks:

  • The bulkhead pattern does add complexity to your application.
  • There might be a performance hurdle for your application.

This pattern may not be suitable when:

  • Less efficient use of resources may not be acceptable in the project.
  • The added complexity is not necessary

BulkHead implementation in Hystrix:

Hystrix provides the means to implement the bulkhead pattern and create thread pools for every remote resource call. If one resource call may be using all the available resources, then only the associated thread pool is likely to fail, and other parts of the client remain intact.

The default implementation of the Hystrix thread pool contains 10 threads for handling hystrix calls.

Hystrix had two different approaches to the bulkhead, thread and semaphore isolation.
1)Thread isolation
Semaphore isolation

Helpful Articles:

Thank you for reading this article. Please share your comments, questions, and feedback. Would be more than happy to help.

Loading

Translate ยป