Hazelcast Open Source In Memory Data Grid

I just happened to attend the GIDS Summit last week and had an opportunity to see this product seminar and was quiet impressed with it and hence used it and sharing my experience.

In this tutorial we shall see how to install, run and use Hazelcast – A Open Source In Memory Data Grid NoSQL based distributed cache.

1. Hazelcast Download & Installation

Hazelcast can be downloaded from here. Its just a zip file and extract it on some of directory and you are done. The below screenshot describes my installation.


The installation is done at /Users/msampath/dev in my case. Once you go to bin folder inside the installation folder then you shall see the above when you list all the files.

2. Starting the first node and adding data

In order to start a node just run the script run.sh or run.bat based on your Operating System, once the node starts up we get the below startup message and we also get a hazelcast prompt using which we can add/update/remove elements from the cache.


Note: Observe the below lines in the log which describes the number of nodes present in the distributed cache.

Hazelcast supports various data structures such as Map, Queue etc, we shall consider Map for our example. We can add elements to the cache by the command

Similarly we add more elements.

when we run m.entries we get the below output.


3. Starting the second node and adding/updating cache

Lets open a new Terminal window/tab and execute run.sh/run.bat and see what happens.


Note: Observe the below lines in the log which describes the number of nodes now two, the current one and the previous one present in the distributed cache.

Now lets add more entries to the cache and update that as well.

We added a new entry with key 5 and updated the value on key 2 to Bombay.


What we achieved just now is added a new entry from Node 2 and updated an entry which was added in Node 1.

4. Remove Node 2 from the Distributed Grid

To check the distributed behaviour and no single point of failure we shall close this Terminal Tab this will essentially deregister the Node from the Grid and the data stored on this node shall be saved to other nodes.

Lets close the Node 2 and see what happens to Node 1.


From the above logs we could clearly see that Node 1 wasn’t able to communicate with Node 2 repeatedly and hence it removed the member Node 2 from the Grid. The below log summarises that.

5. Verify Data

Now lets do m.entries on Node 1 and see the result.


We could see that there are 5 entries i.e. the entry that was added in Node 2 and the update done on Node 2 here in Node 1

6. Summary

  • I liked the Hazelcast very much for its simplicity, this would be a very good alternative for replicated EHCache.
  • We don’t need JGroups/JMS for cache replication.
  • The framework is light weight.
  • The Hazelcast admin console through which we can monitor each nodes in the Grid is available for up to 2 Nodes in open source version.
  • The licensed version of Hazelcast offers premium support as well as Admin Console, Elastic Memory (no GC overheads).

I hope this has been useful for you and I’d like to thank you for reading. If you like this article, please leave a helpful comment and share it with your friends.

Leave a Reply

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