Creating Regional Replicas With Multiple Redis Clusters on Java

Many Java developers today are tasked with creating globally distributed applications that perform well in any part of the world. Low latency and uninterrupted service are critical requirements. That's why developers turn to a fast, in-memory data store like Redis. However, for optimal performance, you need regional replicas that provide local servers to global users.

There are many ways to set up regional replicas with multiple Redis clusters on Java. Most options, though, require you to set up proxy servers, which can hinder replica performance. Here's a look at the options for creating regional replicas with multiple Redis clusters on Java and how you can do it without proxy servers.

Why Choose Regional Replicas?

Regional replicas enhance an app's responsiveness and resilience for globally distributed applications. Ideally, this will reduce latency for users closer to a local Redis replica, compared to accessing a single, distant cluster.

If one regional cluster becomes unavailable, your app can seamlessly switch to another regional replica. This makes regional replication a good defense against network failures, power outages, and natural disasters. That's why regional replicas are a common component of disaster recovery plans and high-availability implementations.

What Is the Role of Proxy Servers in Replicas?

The primary challenge of managing multiple regional clusters is intelligently routing client requests. For most replication solutions, proxy servers do this by routing requests to the appropriate cluster based on the user's location.

Redis used to offer a native solution, Redis Cluster Proxy, but it's no longer maintained. Java developers are left to implement a third-party solution, but they soon find that reliance on proxy servers introduces some new challenges.

The Downsides of Proxy Servers

For all the potential benefits of proxy servers, they also have several potential downsides, including:

  • An additional point of failure: Should the proxy server malfunction, experience downtime, or be the target of an attack, it could disrupt your entire application's communication.
  • Latency: Introducing a proxy server adds an extra hop between the client and the target server. This additional step can lead to increased latency.
  • Potential attack target: Proxy servers can be attractive targets for attackers. If a proxy server is compromised, it could expose sensitive information or be used to launch attacks on your app or infrastructure.

The Regional Replication Solution Without Proxy Servers

Unlike other regional replication solutions, Redisson PRO supports multiple Redis Cluster setups without proxies. This is thanks to Redisson PRO's multi-cluster mode, which offers Java developers a simple config:

Config config = new Config();

config.useMultiClusterServers()

    .setScanInterval(2000) // cluster state scan interval in milliseconds

    // use "rediss://" for SSL connection

    .addAddress("redis://cluster1:7000", "redis://cluster2:70002");

RedissonClient redisson = Redisson.create(config);

Other important settings include primaryDiscoveryMode, with these available values:

  • FIRST_PRIMARY - Primary database is the first address in the list of addresses
  • AUTO - Primary database is selected if all master nodes are available

replicationMode, with these available values:

  • NONE - No replication executed by Redisson. Replication should be executed on Redis side
  • SYNC - Each Redisson method invocation which modifies data is completed only if it has been replicated to all Redis setups
  • ASYNC - Each Redisson method invocation which modifies data doesn't wait for replication to complete on other Redis setups

datastoreMode, with these available values:

  • ACTIVE - Only primary (active) cluster is used
  • ACTIVE_PASSIVE - Primary (active) cluster is used for read/write operations and secondary (passive) clusters are used for read operations only
  • WRITE_ACTIVE_READ_PASSIVE - Primary (active) cluster is used for write operations and secondary (passive) clusters are used for read operations only

With these settings, you can easily manage any number of regional replicas with multiple Redis Clusters. To learn more about multi-cluster mode and other Redisson PRO features, visit the Redisson website.

Similar articles