next image
next image
Fernando DoglioJune 23, 2023

How to Add Sentinels to Memurai

Technical articles and news about Memurai.

Setting up Memurai with a basic master-replica configuration is easy, and while it does provide some advantages over a basic setup (with a single instance of Memurai running), it can easily be improved upon. In this guide, we'll delve into the integration of sentinels into your Memurai setup, exploring their significance and benefits.

If you're looking for a reliable Redis installation on a Windows-based architecture, the Memurai Sentinels are the dependable guardians you're looking for. Tirelessly overseeing your systems' well-being, sentinels ensure smooth operation by actively monitoring their primary's health and swiftly stepping in when necessary.

By integrating sentinels into your Memurai setup, you add an extra layer of protection, boosting the robustness and fault-tolerance of your infrastructure.

We'll highlight the advantages of distributing these sentinels across separate machines, fostering an environment of redundancy, and minimizing the risk of single points of failure.

So, without further ado, let's embark on this adventure!

What are Sentinels and Why Do You Need Them?

Sentinels play a crucial role in safeguarding your system's well-being. But what exactly are they doing, and why do you need them? In a nutshell, sentinels are specialized processes that monitor the health and status of your Memurai setup, tirelessly keeping watch and springing into action when needed. Think of them as ever-watchful eyes, constantly scanning for any signs of trouble or potential hiccups.

Now, you might be wondering, "But why do I need these sentinels in the first place?" Sentinels bring a plethora of benefits that make them an invaluable addition to your infrastructure.

  1. First and foremost, sentinels offer automatic failover. Picture this: one of your Memurai instances experiences a hiccup, maybe due to a hardware failure or a temporary network glitch. Without Sentinels, you'd have to manually intervene to redirect the traffic and restore order. However, with Sentinels, they swiftly detect the problem and automatically orchestrate a failover to a healthy instance, which becomes the new "primary." They save you time, effort, and the headache of manual intervention.

  2. Sentinels are also masters of real-time monitoring. They keep a close eye on the overall health of your Memurai setup, meticulously observing its performance, replication, and system availability.

  3. They're great at identifying potential issues even before they become major headaches. By detecting warning signs, such as high latency or replica lag, sentinels can give you a heads-up, allowing you to address and resolve problems before they escalate. So, whether it's ensuring automatic failover, providing real-time monitoring, or preemptively troubleshooting, sentinels are the indispensable guardians of your instances.

Now that you know what sentinels are and why you need them, let's answer an important question: how many do you need?

The Magic Number: Three Sentinels and Their Importance

In the realm of sentinels and Memurai, there's a magic number that holds tremendous significance: three. Yes, three sentinels are the recommended practice, and here's why they hold such importance in fortifying your setup.

Majority Rules: Having an odd number of sentinels, specifically three, ensures an odd number of voters in the decision-making process. Why does this matter? When it comes to making critical decisions like failover or promoting replicas, having an odd number prevents tie-breaker situations. With three sentinels, reaching a majority consensus is much easier. They form a sort of "democratic council" that swiftly resolves any conflicts and takes decisive action.

Fault-Tolerance at Its Finest: Imagine a scenario with two sentinels. Now, what happens if one of them goes offline or encounters an issue? Suddenly, the decision-making power is compromised, leaving you in a precarious situation. However, with three sentinels, even if one goes offline, the remaining two sentinels can still function as a majority, ensuring fault tolerance and maintaining the integrity of your Memurai installation. It's like having a backup plan for your backup plan.

Balanced Load Distribution: Deploying three sentinels allows you to distribute them across different machines, striking a balance in load distribution. By avoiding a single point of failure, you create a more robust and resilient architecture. Sentinels actively monitor all nodes and continuously discover all instances within the network, sharing the responsibility and alleviating any potential bottlenecks. It's like having a team of sentinels covering all corners of your architecture, ensuring constant vigilance and protection.

Now, it may seem tempting to have an army of sentinels at your disposal, after all, if three work great, why not five or eleven? Keep in mind that each Sentinel consumes system resources. Having too many sentinels can lead to unnecessary overhead and might not provide significant additional benefits in terms of fault tolerance or decision-making.

Remember, balance is the key.

So, with three sentinels, you strike the perfect harmony between majority decision-making, fault tolerance, and load distribution. They form a formidable trio, working together to keep your architecture complying with the "3Rs principle": Resilient, reliable, and Ready to face any challenges that come its way.

How to set up Sentinels on your Memurai installation?

Now that we understand the importance of sentinels, it's time to embark on the integration process. But before you do that, take a moment to assess your needs. Determine how many sentinels you require based on the scale and complexity of your setup. Remember, the magic number is three! Aim to deploy an odd number of sentinels for optimal fault tolerance and decision-making.

Install and Configure Sentinels

Configuring the sentinel mode is easy, the tricky part is to get the initial setup correct. You'll have to have a primary (or master) instance and one or more replicas. Each replica is configured to capture the content written on the primary and allow for potential read queries to lower the load on the primary node. If you don’t know how to get started, read this guide explaining how to set up a basic master-replica architecture using Memurai.

With your Memurai setup ready, there are many ways in which you can configure your Sentinels. All of these options are correct, just make sure you keep the following considerations in mind when configuring everything:

All Sentinels should be installed on computers (or VMs) that can fail independently from each other. You need at least 3 Sentinels (as stated above) to make sure there is enough quorum when either the primary or one of the replicas fails. Be careful when mixing Docker and Sentinel configurations. Docker will remap ports which will break the Sentinel's auto+-discovery process. Read the Redis configuration guide when using Docker + Sentinel to understand how to solve this problem.

The following diagram shows a classical Primary-Replica setup with two replicas and three sentinels:

In this scenario, if the primary suddenly becomes unreachable, the other sentinels will step in and choose a new Primary. Bear in mind running Sentinels on separate machines can further improve fault tolerance, but the scenario above provides a cost-effective way to introduce Sentinels.

Starting a sentinel

To start the Memurai server as a sentinel, you have two options:

  1. Use the --sentinel flag like this: memurai.exe memurai.conf --sentinel
  2. Rename the memurai.exe file to memurai-sentinel.exe and execute it specifying the configuration file, like so: memurai-sentinel.exe memurai.conf.

Note that when starting in Sentinel mode, you must specify the configuration file.

Here is an example of a configuration file for a sentinel instance:

sentinel monitor primary_1 127.0.0.1 6379 2
sentinel down-after-milliseconds primary_1 60000
sentinel failover-timeout primary_1 180000
sentinel parallel-syncs primary_1 1

sentinel monitor primary_2 192.168.1.3 6380 4
sentinel down-after-milliseconds primary_2 10000
sentinel failover-timeout primary_2 180000
sentinel parallel-syncs primary_2 5

The points you have to notice are:

  • The first line (the monitor configuration directive) specifies a name for the master, the IP, and PORT, and the last number is the quorum (the number of sentinels that have to agree that there is a problem to flag it).
  • The quorum value will only be used to flag the failing instance, when it’s time to perform the failover, all sentinels will be used.
  • Only the primary nodes are specified. Replicas will be used, but they will be auto-discovered by the algorithm.
  • The down-after-milliseconds parameter specifies how long an instance needs to be unreachable to be considered “down” by the Sentinels.
  • The parallel-syncs parameter specifies how many replicas will be re-configured to load using the new master. The higher the number, the faster is the failover, however, there is a point at which the instance might be blocked. So to keep it safe, use a lower number to ensure fewer instances are blocked at the same time during failover.

While the integration process may have its challenges, rest assured that the rewards are well worth it. By seamlessly integrating sentinels into your Memurai setup, you're bolstering the resilience and reliability of your infrastructure. So gear up, embrace the adventure, and let sentinels be your trusted companions on this exhilarating journey.

Conclusion

Congratulations! You have successfully read through this guide! With this approach, you gain another level of availability and fault tolerance over a basic primary replica setup. While there might still be ways to improve it, this setup will apply to most use cases.

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 contact 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!!