Hazelcast Map Configuration For Data Backup
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
In the realm of distributed computing, data redundancy and backup are critical for ensuring high availability and resilience against data loss. Hazelcast, an open-source in-memory data grid, provides robust mechanisms for data backup through its distributed map feature, commonly known as IMap. This article delves into the configuration options for data backup within a Hazelcast map, providing technical explanations and practical examples.
Understanding Hazelcast's Map Backup
Hazelcast IMap is designed to hold data in-memory which makes data access extremely fast. However, the volatile nature of memory necessitates mechanisms to prevent data loss. Hazelcast addresses this by allowing data in maps to be stored across multiple nodes in a cluster. This means that if one node fails, the data is still available from another node.
By default, each entry in a Hazelcast map is stored in one member and optionally backed up on one or more other members, depending on the configuration. These backups can be synchronous or asynchronous.
Synchronous vs Asynchronous Backup
Hazelcast provides two modes of backup: synchronous and asynchronous.
- Synchronous backups ensure that a map entry update operation does not complete until the data is safely stored in the primary member and the backup members. While this mode guarantees strong consistency, it can lead to higher latencies for write operations.
- Asynchronous backups, on the other hand, return control to the calling operation as soon as the data is updated on the primary member, while the backup is updated in the background. This can improve write performance but at the cost of potential consistency issues during node failure.
Configuration Examples
The backup configuration in Hazelcast can be set programmatically or via XML/JSON/YAML configuration files. Here is an example using Java:
In the above example, setBackupCount(2) configures the map to have 2 synchronous backups, and setAsyncBackupCount(1) configures an additional asynchronous backup.
Backup Count and Replication Factor
Key to Hazelcast's backup configuration is the understanding of the backup count and the total number of replicas (or the replication factor). The replication factor includes the primary replica plus the backup replicas. For example, with a backup count of 1, the total number of replicas is 2 (1 primary + 1 backup).
Table: Backup Configuration Parameters
| Parameter | Description | Typical Values |
backupCount | Number of synchronous backups. Ensures data safety at the cost of write performance. | 0 to 7, where 7 means 7 synchronous backups. |
asyncBackupCount | Number of asynchronous backups. Enhances write performance with a slight risk during failures. | 0 to 7, asynchronous backups do not block caller. |
readBackupData | Whether to allow reading from backup data. This can balance the read load but might show stale data. | true/false |
Tuning Backup Configuration
The choice between synchronous and asynchronous backups often depends on the specific requirements of the application regarding consistency, latency, and throughput. For applications that require strong consistency and can tolerate higher write latency, synchronous backups are preferable. Conversely, for applications prioritizing write speed over consistency, asynchronous backups may be more suitable.
Furthermore, Hazelcast allows you to fine-tune how backups are handled upon node failure. For instance, the configuration might include details on how backups are promoted or how data integrity is verified during a network partition.
Conclusion
Configuring data backups in Hazelcast involves crucial decisions about synchronous and asynchronous backups, as well as the number of backups to create. Each of these configurations impacts system performance and consistency differently, requiring a careful evaluation based on specific application needs. Ultimately, the flexibility provided by Hazelcast's backup configurations allows for tailored solutions to achieve the desired balance between data safety and performance.
Related reading
- HBase installation in cluster - Master is initializing error
- Hbase Understanding difference between smallCompactions and largeCompactions under majorCompaction
- Hbase vs Cassandra vs Kafka for high resolution time series data storage
- Hibernate - A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance
- Hibernate - Batch update returned unexpected row count from update 0 actual row count 0 expected 1
- Hibernate 4.1.9 latest final build reporting nested transactions not supported
- Hibernate 6.1.5.Final unable to determine table reference
- Hibernate embeddables component property not found

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.