Spring Boot + Hazelcast Tutorial
It all started when we had the following problem: How can you enable High Availability in a Rest API based on Spring Boot?
As you may know, we have two products: (both based on Spring Boot)
- OctoPerf Saas-Edition: the online saas platform,
- OctoPerf Enterprise-Edition: the full on-premise installable version.
While Saas-Edition
absolutely needs High Availability, the Enterprise-Edition
doesn't share the same requirements. But, as astonishing as it may seem, both versions share exactly the same code, while working slightly differently.
That's how I've come up with an elegant solution I'd like to share with you. This article aims to give an answer to multiple problems arising when clustering a web application (and especially Rest APIs):
- Get an understanding of why clustering is inherently difficult (but not insurmountable),
- How to hide clustering problematics behind a service that handles the difficult work for us,
- How to enable clustering in a Spring Boot Rest API? Which framework should I use? (obviously we're talking about
Hazelcast
here) - How to make your Spring Boot App configurable to support High Availability without changing a single line of code, (using
@ConditionalOnProperty
) - How to implement a very simple Leader Election mechanism using Hazelcast and know when your instance is the leader.
The whole article is based on real-world code examples available on Github. Don't expect any long explanations on Distributed Systems theories.