Hazelcast is an in-memory data grid that allows multiple instances of an application to communicate and share data between each other. It keeps data in main memory for fast processing and provides structures like maps, lists, sets and queues to store distributed data. Hazelcast makes it easy to set up distributed caching and synchronization between nodes with no need to manually discover instances.
2. What is Hazelcast?
• A way to enable multiple instances of your app to communicate
between themselves
• Keeps your data in main memory, processing performance of which is
800 times faster than an HDD
• Option for keeping data in RDMS
3. Scenario
• Say You have deployed multiple instances of your heavily used app for
load balancing. Now you are thinking how you will keep track of
logged in user as user can log in by any instance. Several ideas can be
captured in your brain:
• Keep a map for logged in users, update the map between instances by sending data between
themselves
• Keep a separate component for storing the logged in user and enable the instances to put/ get data
from it
• Keep logged in user record in database
• All of the above methods are either cumbersome or time consuming
4. Now what shall you do?
• Just use hazelcast
• Easy to set up and use
• Open source
• No hassle of discovering nodes or instances manually
• Structures to store data: List, Map, Set, Queue
• Locking mechanism: You can conduct a synchronization in multiple
distributed systems by using a single lock
• Sql like query can be used: select, like, having etc
• Distributed thread pools
• Uses TCP connection to communicate between threads
• SSL support
5. Lets see how easy it is to use
• Add dependency for hazelcast
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>3.1</version>
</dependency>
6. Run and watch
public static void main(String args[]) throws InterruptedException {
HazelcastInstance h1 = Hazelcast.newHazelcastInstance();
Map map = h1.getMap( "map" );
int i = 0;
while(true){
map.put( i, "value" + i );
i++;
Thread.sleep(4000);
}
}
App 1
public static void main(String args[]) throws InterruptedException {
HazelcastInstance h1 = Hazelcast.newHazelcastInstance();
Map map = h1.getMap( "map" );
while(true){
System.out.println(map.size());
Thread.sleep(4000);
}
}
App 2
Prints
1
2
3
4
.
.
.
.
7. • As we have understood how easy hazelcast is to use, now it can be
assumed that you can easily solve your data sharing problem of log in
module
• Lets see how it works
10. DB caching
Hazelcast database
caching stores
frequently accessed
data in-memory and
across an elastically
scalable data grid
Separating hazelcast
caching layer: Any
applications or
groups within the
organization can
add caching into
their application
without worrying
about the cache
implementation
11. Hibernate Second Level Cache
• responsible for caching objects across
sessions
• offers the ability to plug in a second-level
cache which keeps pre-provisioned object
data in-memory
• associates with the Session Factory object
• improves application performance as
commonly used data can be held in-
memory in the application tier
• For more information on caching:
https://dzone.com/articles/all-about-
hibernate-second
12. Conclusion
• That’s all for today
• Visit hazelcast site https://hazelcast.com for more information and
details; there are large scale resources and documentations there.
• Thanks for your patience