next image
next image
Fernando DoglioMay 30, 2023

How to Set Up a Master Replica on Memurai

Technical articles and news about Memurai.

If you’re looking to install a fast in-memory database like Redis®* on a Windows server, Memurai is the answer to your problems. Installing Redis on Windows is trivial now thanks to Memurai. Not only that, but configuring a master-slave architecture, like the one described in this guide, is also quite easy to achieve!

In this guide, we'll guide you through the process of setting up a master-replica architecture on a Windows machine using Memurai.

Prerequisites: Before we dive into the setup process, make sure you have the following prerequisites in place:

• A Windows machine with Memurai installed.

• Basic knowledge of Redis commands and concepts.

• Optionally, two additional Windows machines for setting up the replica instances. If you don’t have the extra machines, you can still install the replicas for testing, however, they will only be valuable if they’re installed in different machines.

How does Memurai replication work?

Memurai replication operates in a similar fashion to Redis replication. Just like Redis, Memurai has the Replica role, which mirrors the functionality of Redis Replica and is fully compatible with its configuration flags. So, developers familiar with Redis replication will find themselves in familiar territory when working with Memurai replication.

Here are some key points for developers to keep in mind when setting up Memurai replication:

  1. Establishing Replication: Replication can be configured between two or more Memurai instances. You'll have a master instance that serves as the primary node for write requests, while the replica instances act as secondary nodes, receiving a copy of the data stored in the master.

  2. Read and Promote: Replica instances not only handle read requests efficiently but also come to the rescue if the master instance experiences a failure. In such cases, a replica can be promoted to become the new master, ensuring uninterrupted operations.

  3. Asynchronous Replication: It's important to note that Memurai replication is asynchronous. This means that replica instances might not always have the latest data at their disposal. Developers must consider this aspect when designing their applications to ensure data consistency and avoid any potential inconsistencies.

  4. Read-Only Replicas: To scale read requests effectively, replica instances can be configured as read-only (this is actually their default state). This prevents direct writes to these replicas and allows them to focus solely on serving read operations. It's a handy feature to optimize performance.

  5. Resource Management: Adequate resource allocation is crucial for replica instances to handle both replication traffic and read requests. Falling behind the master instance might necessitate resynchronization, a process that can be time-consuming. So, ensure that replica instances have sufficient resources to handle their tasks efficiently.

By keeping these considerations in mind, developers can configure Memurai replication in a reliable and scalable manner, empowering their applications with efficient data distribution and fault tolerance capabilities.

Why is Replication Needed:

Problems happen all the time, you can’t create a plan to avoid them altogether, so why not set up an architecture that is capable of withstanding them instead? Let’s see some of the benefits that this setup brings to the table:

  1. High Availability: Replication ensures that even if the master instance experiences a failure or goes offline, the replica instances can continue serving data. By distributing the workload across multiple replicas, you can minimize downtime and maintain high availability for your applications.

  2. Fault Tolerance: In the event of a system crash or data corruption, having replica instances acts as a safety net. If the master instance becomes inaccessible, the replicas can step in and continue serving requests, preventing data loss and minimizing the impact on your applications. Keep in mind this is a behavior that can only be achieved if you use Sentinel on top of a master-replica set up. We’ll talk more about that in another guide.

  3. Scalability: Replication enables horizontal scaling by allowing you to distribute the read workload across multiple replica instances. As the load on your system increases, you can add more replicas to handle the additional read traffic, thereby improving overall performance.

  4. Geographic Redundancy: Replication also allows you to create replicas in different geographical locations. This setup provides data redundancy and allows you to serve users from various regions more efficiently. Additionally, it can help reduce network latency by serving requests from replicas closer to the users.

Setting Up Memurai with a Master-Replica Configuration:

Now that we understand the importance of replication, let's proceed with the step-by-step guide to setting up Memurai using a basic master-replica configuration.

Step 1: Setting Up Replica Instances

  1. Install Memurai on the two additional Windows machines following the same steps as for the master instance.

  2. Open the Memurai configuration file (usually located here: "C:\Program Files\Memurai\memurai.ini") on both replica machines.

  3. Add the following line to each replica's configuration file, specifying the IP and port of the master instance:

     slaveof <primary_IP> <primary_port>
    

Replace <primary_IP> with the IP of the master instance of Memurai, and <primary_port> with the port number of the primary instance the replica will connect to (i.e the master).

  1. Save the configuration files and start the Memurai service on both replicas and the master with the following line. Keep in mind that if you’re testing this within the same machine (having all 3 instances on the same computer), you’ll have to configure different ports for each instance.

     memurai.exe --service-install memurai.conf
     memurai.exe --service-start
    

Alternatively to all of this setup, if you’re just testing the replication feature, you can directly start the replicas configured as such with the CLI tool, like this:

memurai.exe --port <port> --slaveof <primary_IP> <primary_port>

Once again, you’ll have to replace < port >, <primary_IP> and <primary_port> with the corresponding values for each one. Note that instead of using the --slaveof parameter here, you could use the --replicaof parameter, which is an alias of the former.

Step 2: Verifying the Configuration

  1. Connect to the master instance using a Redis client.

  2. Execute the INFO replication command to check the replication status. The output will display details about the replica instances, including their IP addresses, port numbers, and replication lag, if any.

  3. Test the replication by modifying some data on the master and verifying that the changes are reflected on the replicas. You can connect to a replica directly with the MemuraiCLI tool like this:

     memurai-cli.exe -h <replica_IP> -p <replica_port>
    

.

Conclusion

Congratulations! You have successfully set up Memurai using a basic master-replica configuration. This setup provides you with increased data availability, fault tolerance, scalability, and even geographic redundancy. By distributing the workload and ensuring data consistency across multiple instances, you can build robust and high-performing applications. If you found this guide valuable, why not share it with your friends, colleagues, or fellow developers? Spread the knowledge and help others benefit from the power of Memurai.

If you need even more assistance or in-depth guidance, don't hesitate to reach out to the Memurai team, they'll be more than happy to provide you with additional support.

Remember, your feedback is invaluable to us. Let's build a vibrant community of Memurai users who can learn from each other and explore the full potential of this fantastic in-memory database for Windows.

Thank you for choosing Memurai, and we look forward to seeing what you build with it!