Hazelcast Tutorial - Getting started with Hazelcast | CodeUsingJava

Hazelcast Tutorial - Getting started with Hazelcast

Hazelcast IMDG is an open source in-memory data grid based on Java. It is clustered data-grid, backed by physical or virtual machines. In this tutorial we will be looking at hazelcast basic, in the next tutorial we will be implementing Spring Boot + Hazelcast Hello World Tutorial.

Video Tutorial

Need for Hazelcast

Let us take an example of a simple banking application that performs CRUD operations for User Bank Accounts. Initially we develop this application using monolithic approach as follows-
Monolithic Application
The major drawback of above application is that each time a call will be made to the database. So this will be a network call which can slow down the application. We can make the application faster using a cache. A cache is a simple inmemory datastructure like a map. where key will be the account number and and value will be the account object. So the account details for a user will be stored both in this map as well as the database. Whenever the user needs the account details for a particular account number, instead of making a call to the database we will be getting it from this map and return it. This will save us a network call to the database and so is much faster. This will improve the performance of our application.
Monolithic Cache Application
But the above approach will lead to problems when -
  • Suppose the application load increases a lot as more and more users are now performing operations like adding new account.  The cache we created is usually stored in in JVM memory. It has limitations of size
  • To solve above problem(and also many other problems of monolithic application) we now move to distributed microservices architecture where we have  started multiple instance of our banking application for better load balancing.
    Distributed Microservices Cache Application
    Suppose a request comes in and banking application 1 inserts the data and also updates it cache. But how will banking application 2 and application 3 know about this cache update. They are not aware of this transaction. Also suppose banking application 1 has    modified/deleted an account. Again application 2 and application 3 will then have stale or wrong data in their cache now.
    To resolve these problems we make use of distributed in memory cache i.e Hazelcast
Distributed Microservices Hazelcast Application
The goal of In-Memory Data Grids (IMDG) is to provide extremely high availability of data by keeping it in memory and in highly distributed fashion. The advantages of Hazelcast are as follows-
  • Clustering - Hazelcast has a clustered set of Nodes that work in unison
  • Distributed - The data in Hazelcast is distributed in all the nodes
    Hazelcast Distributed Application
  • Fault Tolerant - Hazelcast maintains replicated copies of data.
    Hazelcast Resilient Application
  • Application scaling - Hazelcast can be scaled horizontally. It is Elastic in nature. New nodes can be added in cluster, and the data in the nodes get automatically distributed again in all the nodes
    Hazelcast Elastic Application