SlideShare a Scribd company logo
Clustering your
application with
Hazelcast
Talip Ozturk
@oztalip
Founder & CEO @hazelcast
Keywords
In-memory data grid
Distributed(Elastic) Cache
NoSQL
Clustering, Scalability, Partitioning
Cloud Computing
Why Hazelcast?
To build highly
available and scalable
applications
Who uses Hazelcast?
Financials
Telco
Gaming
e-commerce
Every sec. one Hazelcast node starts around the globe
Map
import java.util.Map;
import java.util.HashMap;
Map map = new HashMap();
map.put(“1”, “value”);
map.get(“1”);
Concurrent Map
import java.util.Map;
import java.util.concurrent.*;
Map map = new ConcurrentHashMap();
map.put(“1”, “value”);
map.get(“1”);
Distributed Map
import java.util.Map;
import com.hazelcast.core.Hazelcast;
Map map = Hazelcast.getMap(“mymap”);
map.put(“1”, “value”);
map.get(“1”);
Alternatives
Oracle Coherence
IBM Extreme Scale
VMware Gemfire
Gigaspaces
Redhat Infinispan
Gridgain
Terracotta
Difference
License/Cost
Feature-set
API
Ease of use
Main focus (distributed map, tuple space, cache,
processing vs. data)
Light/Heavy weight
Clustering your Application with Hazelcast
Apache License
2 MB jar
Lightweight without any dependency
Introducing Hazelcast
Map, queue, set, list, lock, semaphore, topic and
executor service
Native Java, C#, REST and Memcache Interfaces
Cluster info and membership events
Dynamic clustering, backup, fail-over
Transactional and secure
Use-cases
Scale your application
Share data across cluster
Partition your data
Send/receive messages
Balance the load
Process in parallel on many JVM
Where is the Data?
Data Partitioning in a Cluster
Fixed number of partitions (default 271)
Each key falls into a partition
partitionId = hash(keyData)%PARTITION_COUNT
Partition ownerships are reassigned upon membership change
A B C
New Node Added
DA B C
Migration
DA B C
Migration
DA B C
Migration
DA B C
Migration
DA B C
Migration
DA B C
Migration
DA B C
Migration Complete
DA B C
Node Crashes
DA B C
Crash
Restoring Backups
DA B C
Crash
Restoring Backups
DA B C
Crash
Restoring Backups
DA B C
Crash
Restoring Backups
DA B C
Crash
Restoring Data from Backup
DA B C
Crash
Data is Recovered from Backup
DA B C
Crash
Backup for Recovered Data
DA B C
Crash
Backup for Recovered Data
DA B C
Crash
Backup for Recovered Data
DA B C
Crash
All Safe
DA C
Node Types
Topology
Native Client:
HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
Lite Member:
-Dhazelcast.lite.member=true
Hazelcast
Enterprise
Community vs Enterprise
Enterprise =
Community +
Elastic Memory + Security + Man. Center
Elastic Memory is OFF-HEAP storage
<hazelcast>
...
<map name="default">
...
<storage-type>OFFHEAP</storage-type>
</map>
</hazelcast>
JAAS based Security
Credentials
Cluster Login Module
Cluster Member Security
Native Client Security
Authentication
Authorization
Permission
Code Samples
Hazelcast
Hazelcast is thread safe
Many instances on the same JVM
Config config = new Config();
HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config)
HazelcastInstance h2 = Hazelcast.newHazelcastInstance(config)
All objects must be serializable
class Employee implements java.io.Serializable
//better
class Employee implements com.hazelcast.nio.DataSerializable
Map<String, Employee> = Hazelcast.getMap(“employees”);
List<Users> = Hazelcast.getList(“users”);
Cluster Interface
import com.hazelcast.core.*;
import java.util.Set;
Cluster cluster = Hazelcast.getCluster();
cluster.addMembershipListener(listener);
Member localMember = cluster.getLocalMember();
System.out.println (localMember.getInetAddress());
Set<Member> setMembers = cluster.getMembers();
Distributed Map
import com.hazelcast.core.*;
import java.util.ConcurrentMap;
Map<String, Customer> map = Hazelcast.getMap("customers");
map.put ("1", customer);
Customer c = map.get("1");
//ConcurrentMap methods
map.putIfAbsent ("2", new Customer(“Chuck Norris”));
map.replace ("3", new Customer(“Bruce Lee”));
Distributed Queue
import com.hazelcast.core.Hazelcast;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;
BlockingQueue<Task> queue = Hazelcast.getQueue(“tasks");
queue.offer(task);
Task t = queue.poll();
//Timed blocking Operations
queue.offer(task, 500, TimeUnit.MILLISECONDS)
Task t = queue.poll(5, TimeUnit.SECONDS);
//Indefinitely blocking Operations
queue.put(task)
Task t = queue.take();
Distributed Lock
import com.hazelcast.core.Hazelcast;
import java.util.concurrent.locks.Lock;
Lock mylock = Hazelcast.getLock(mylockobject);
mylock.lock();
try {
// do something
} finally {
mylock.unlock();
}
//Lock on Map
IMap<String, Customer> map = Hazelcast.getMap("customers");
map.lock("1");
try {
// do something
} finally {
map.unlock("1");
}
Distributed Topic
import com.hazelcast.core.*;
public class Sample implements MessageListener {
public static void main(String[] args) {
Sample sample = new Sample();
ITopic<String> topic = Hazelcast.getTopic ("default");
topic.addMessageListener(sample);
topic.publish ("my-message-object");
}
public void onMessage(Object msg) {
System.out.println("Got msg :" + msg);
}
}
Distributed Events
import com.hazelcast.core.*;
public class Sample implements EntryListener {
public static void main(String[] args) {
Sample sample = new Sample();
IMap map = Hazelcast.getMap ("default");
map.addEntryListener (sample, true);
map.addEntryListener (sample, "key");
}
public void entryAdded(EntryEvent event) {
System.out.println("Added " + event.getKey() + ":" +
event.getValue());
}
public void entryRemoved(EntryEvent event) {
System.out.println("Removed " + event.getKey() + ":" +
event.getValue());
}
public void entryUpdated(EntryEvent event) {
System.out.println("Updated " + event.getKey() + ":" +
event.getValue());
}
}
Executor Service
Hello Task
A simple task
Execute on any member
ExecutorService ex = Hazelcast.getExecutorService();
Future<String> future = executor.submit(new HelloTask());
// ...
String result = future.get();
Attach a callback
DistributedTask task = ...
task.setExecutionCallback(new ExecutionCallback() {
public void done(Future f) {
// Get notified when the task is done!
}
});
public class HelloTask implements Callable<String>, Serializable{
@Override
public String call(){
Cluster cluster = Hazelcast.getCluster();
return “Hello from ” + cluster.getLocalMember();
}
}
Hazelcast can execute a task ...
ExecutorService executor = Hazelcast.getExecutorService();
FutureTask<String> task1, task2;
// CASE 1: Run task on a specific member.
Member member = ...
task1 = new DistributedTask<String>(new HelloTask(), member);
executor.execute(task1);
// CASE 2: Run task on a member owning the key.
Member member = ...
task1 = new DistributedTask<String>(new HelloTask(), “key”);
executor.execute(task1);
// CASE 3: Run task on group of members.
Set<Member> members = ...
task = new MultiTask<String>(new HelloTask(), members);
executor.execute(task2);
1. On a specific node
2. On any available node
3. On a collection of defined nodes
4. On a node owning a key
Executor Service Scenario
public int removeOrder(long customerId, long orderId){
IMap<Long, Customer> map = Hazelcast.getMap("customers");
map.lock(customerId);
Customer customer = map.get(customerId);
customer.removeOrder (orderId);
map.put(customerId, customer);
map.unlock(customerId);
return customer.getOrderCount();
}
Order Deletion Task
public class OrderDeletionTask implements Callable<Integer>, PartitionAware, Serializable
{
private long customerId; private long orderId;
public OrderDeletionTask(long customerId, long orderId) {
super();
this.customerId = customerId;
this.orderId = orderId;
}
public Integer call () {
IMap<Long, Customer> map = Hazelcast.getMap("customers");
map.lock(customerId);
customer customer = map. get(customerId);
customer.removeOrder (orderId);
map.put(customerId, customer);
map.unlock(customerId);
return customer.getOrderCount();
}
public Object getPartitionKey() {
return customerId;
}
}
Send computation over data
public static int removeOrder(long customerId, long orderId){
ExecutorService es = Hazelcast.getExecutorService();
OrderDeletionTask task = new OrderDeletionTask(customerId, orderId);
Future future = es.submit(task);
int remainingOrders = future.get();
return remainingOrders;
}
Persistence
import com.hazelcast.core.MapStore,
import com.hazelcast.core.MapLoader,
public class MyMapStore implements MapStore, MapLoader {
public Set loadAllKeys () {
return readKeys();
}
public Object load (Object key) {
return readFromDatabase(key);
}
public void store (Object key, Object value) {
saveIntoDatabase(key, value);
}
public void remove(Object key) {
removeFromDatabase(key);
}
}
Persistence
Write-Behind : asynchronously storing entries
Write-Through : synchronous
Read-Through : if get(key) is null, load it
Persistence
Recap
• Distributed implementation of
• Map
• Queue
• Set
• List
• MultiMap
• Lock
• Executor Service
• Topic
• Semaphore
• AtomicLong
• CountDownLatch
• Embedded, but accessible through
• Native Java & C# clients
• REST
• Memcache
Thank You!!
JOIN US!
github.com/hazelcast/
hazelcast@googlegroups.com
@hazelcast
Hazelcast Hackers Linkedin group

More Related Content

PDF
Easy Scaling with Open Source Data Structures, by Talip Ozturk
PPTX
Hazelcast
PPTX
Hadoop Puzzlers
PPTX
WaveEngine 2D components
PPTX
WaveEngine 3D components
PDF
Vielseitiges In-Memory Computing mit Apache Ignite und Kubernetes
PPTX
IPC: AIDL is sexy, not a curse
PPTX
Ipc: aidl sexy, not a curse
Easy Scaling with Open Source Data Structures, by Talip Ozturk
Hazelcast
Hadoop Puzzlers
WaveEngine 2D components
WaveEngine 3D components
Vielseitiges In-Memory Computing mit Apache Ignite und Kubernetes
IPC: AIDL is sexy, not a curse
Ipc: aidl sexy, not a curse

What's hot (19)

PDF
Fun Teaching MongoDB New Tricks
PDF
Modern Android app library stack
PDF
JJUG CCC 2011 Spring
PDF
PDF
Cassandra summit 2013 - DataStax Java Driver Unleashed!
PPTX
Getting Started with Datatsax .Net Driver
PDF
The Ring programming language version 1.7 book - Part 32 of 196
PDF
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
PDF
Cassandra Summit 2015
PDF
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
PDF
Cassandra summit keynote 2014
PDF
Python in the database
PDF
Programming with ZooKeeper - A basic tutorial
PDF
【Unity】Scriptable object 入門と活用例
PDF
Cassandra 2.1
PPTX
Cassandra 2.2 & 3.0
PPTX
Python database interfaces
PPTX
Sharing of Distributed Objects in a DX Cluster, thanks to Hazelcast - Online ...
PPTX
Enabling Search in your Cassandra Application with DataStax Enterprise
Fun Teaching MongoDB New Tricks
Modern Android app library stack
JJUG CCC 2011 Spring
Cassandra summit 2013 - DataStax Java Driver Unleashed!
Getting Started with Datatsax .Net Driver
The Ring programming language version 1.7 book - Part 32 of 196
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
Cassandra Summit 2015
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Cassandra summit keynote 2014
Python in the database
Programming with ZooKeeper - A basic tutorial
【Unity】Scriptable object 入門と活用例
Cassandra 2.1
Cassandra 2.2 & 3.0
Python database interfaces
Sharing of Distributed Objects in a DX Cluster, thanks to Hazelcast - Online ...
Enabling Search in your Cassandra Application with DataStax Enterprise
Ad

Similar to Clustering your Application with Hazelcast (20)

PDF
Hazelcast
PDF
AJUG April 2011 Cascading example
PPTX
Hazelcast and MongoDB at Cloud CMS
PPTX
Instroduce Hazelcast
PDF
Store and Process Big Data with Hadoop and Cassandra
PDF
Hadoop Integration in Cassandra
PDF
Akka Cluster in Java - JCConf 2015
PDF
Hacking JavaFX with Groovy, Clojure, Scala, and Visage: Stephen Chin
PDF
Apache Cassandra and Go
PPT
Java util concurrent
DOCX
Ejemplo radio
PPTX
Vert.x - Reactive & Distributed [Devoxx version]
PPTX
Hadoop Puzzlers
PDF
Deep dive into deeplearn.js
PDF
Writing Maintainable JavaScript
PPTX
Akka Actor presentation
PDF
Managing parallelism using coroutines
PPTX
Map-Interface-and-HashMap-in-Java-A-Deep-Dive.pptx.pptx
PDF
Celery with python
PDF
Elastic search integration with hadoop leveragebigdata
Hazelcast
AJUG April 2011 Cascading example
Hazelcast and MongoDB at Cloud CMS
Instroduce Hazelcast
Store and Process Big Data with Hadoop and Cassandra
Hadoop Integration in Cassandra
Akka Cluster in Java - JCConf 2015
Hacking JavaFX with Groovy, Clojure, Scala, and Visage: Stephen Chin
Apache Cassandra and Go
Java util concurrent
Ejemplo radio
Vert.x - Reactive & Distributed [Devoxx version]
Hadoop Puzzlers
Deep dive into deeplearn.js
Writing Maintainable JavaScript
Akka Actor presentation
Managing parallelism using coroutines
Map-Interface-and-HashMap-in-Java-A-Deep-Dive.pptx.pptx
Celery with python
Elastic search integration with hadoop leveragebigdata
Ad

More from Hazelcast (20)

PDF
Hazelcast 3.6 Roadmap Preview
PDF
Time to Make the Move to In-Memory Data Grids
PDF
The Power of the JVM: Applied Polyglot Projects with Java and JavaScript
PDF
JCache - It's finally here
PDF
Speed Up Your Existing Relational Databases with Hazelcast and Speedment
PDF
Shared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorgan
PDF
Applying Real-time SQL Changes in your Hazelcast Data Grid
PDF
WAN Replication: Hazelcast Enterprise Lightning Talk
PDF
JAAS Security Suite: Hazelcast Enterprise Lightning Talk
PDF
Hazelcast for Terracotta Users
PDF
Extreme Network Performance with Hazelcast on Torusware
PDF
Big Data, Simple and Fast: Addressing the Shortcomings of Hadoop
PDF
JAXLondon - Squeezing Performance of IMDGs
PDF
OrientDB & Hazelcast: In-Memory Distributed Graph Database
PDF
How to Use HazelcastMQ for Flexible Messaging and More
PDF
Devoxx UK 2014 High Performance In-Memory Java with Open Source
PDF
JSR107 State of the Union JavaOne 2013
PDF
Jfokus - Hazlecast
PDF
In-memory No SQL- GIDS2014
PDF
In-memory Data Management Trends & Techniques
Hazelcast 3.6 Roadmap Preview
Time to Make the Move to In-Memory Data Grids
The Power of the JVM: Applied Polyglot Projects with Java and JavaScript
JCache - It's finally here
Speed Up Your Existing Relational Databases with Hazelcast and Speedment
Shared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorgan
Applying Real-time SQL Changes in your Hazelcast Data Grid
WAN Replication: Hazelcast Enterprise Lightning Talk
JAAS Security Suite: Hazelcast Enterprise Lightning Talk
Hazelcast for Terracotta Users
Extreme Network Performance with Hazelcast on Torusware
Big Data, Simple and Fast: Addressing the Shortcomings of Hadoop
JAXLondon - Squeezing Performance of IMDGs
OrientDB & Hazelcast: In-Memory Distributed Graph Database
How to Use HazelcastMQ for Flexible Messaging and More
Devoxx UK 2014 High Performance In-Memory Java with Open Source
JSR107 State of the Union JavaOne 2013
Jfokus - Hazlecast
In-memory No SQL- GIDS2014
In-memory Data Management Trends & Techniques

Recently uploaded (20)

PDF
AI in Product Development-omnex systems
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
System and Network Administration Chapter 2
PPTX
Introduction to Artificial Intelligence
PDF
Digital Strategies for Manufacturing Companies
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
history of c programming in notes for students .pptx
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
How Creative Agencies Leverage Project Management Software.pdf
AI in Product Development-omnex systems
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
System and Network Administration Chapter 2
Introduction to Artificial Intelligence
Digital Strategies for Manufacturing Companies
Odoo Companies in India – Driving Business Transformation.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Understanding Forklifts - TECH EHS Solution
history of c programming in notes for students .pptx
Wondershare Filmora 15 Crack With Activation Key [2025
Upgrade and Innovation Strategies for SAP ERP Customers
PTS Company Brochure 2025 (1).pdf.......
2025 Textile ERP Trends: SAP, Odoo & Oracle
wealthsignaloriginal-com-DS-text-... (1).pdf
VVF-Customer-Presentation2025-Ver1.9.pptx
Design an Analysis of Algorithms II-SECS-1021-03
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
How Creative Agencies Leverage Project Management Software.pdf

Clustering your Application with Hazelcast