Bulkhead Pattern in Cloud Native Applications

Introduction

The bulkhead pattern is essential when developing a cloud native application which uses microservices. Let us see the definition for bulkhead as given by Webster dictionary: a structure or partition to resist pressure or to shut off water, fire, or gas“. The word bulkhead reminds of two places it is used ships and planes.

When talking about ships the famous sunken ship Titanic pops into our heads and begets this question:  Did the titanic have bulkheads?

 

Yes, and was labeled ‘unsinkable’.  This same structural design pattern is useful when building cloud native applications for resiliency, separation of functionality and robustness.

Context

In a cloud native application there are many micro services which connect to another service say the database connection pool service, or the LDAP service. Each microservice can use the same service as shown in the diagram  ‘without Bulkhead‘ :

 

In the ‘Without Bulkhead’ scenario we have an issue as when the service goes down for various reasons then all the clients cannot connect to the service and subsquently the resource. This is not a resilient application.

Now in the scenario ‘With Bulkhead’ we can see that if Service Instance 1 for Client in red color goes down then only that microservice is down. The other two clients have a different service to connect to the resource.

This resiliency is essential when developing a cloud native application. Remember in the cloud we can scale up and down quickly and also the cost is per usage. To utilize these features of the cloud we use the Bulkhead pattern to connect to services.

Conclusion

Some benefits of this pattern are isolation of services by consumers so that there is no cascading effect on to the consumers; preserve functionality of the application when one service fails in Single Page Application (SPA).

This pattern can be implemented by Resilience4J which gives the choice of using Semaphore Bulkhead or ThreadPool Bulkhead. Another option is to use the cloud configuration to   deploy multiple instances of the same service. Kubernetes does a good job using replica sets.

Now, back to the Titanic which had many bulkheads and still sank. The reason is given by Ajay Harish in his blog:

“The front of the ship started to go into the water, leading to the lifting of the stern of the ship out of it.

When the ship was almost at 45 degrees, the stresses in the ship’s midsection increased beyond the material limits of steel.

The Titanic almost split wide open in the middle! This is how the Titanic sank.”

Another nice read is over here with a video on how it actually sank from a bulkhead perspective.

References

  1. Thanks to Pratik Pandey for use of his image in his excellent post on Bulkhead Pattern -Distributed Design Pattern
  2. Spring Boot example for Bulkhead Pattern is here.
  3. Ajay Harish on reasons for sinking of Titanic.
  4. Detailed Video of how it sank is here.

Leave a comment

Your email address will not be published. Required fields are marked *