Big Data analytics and its implications have made a huge impact on almost every business, starting from SMB and up to Fortune 500 enterprise companies. In the past few years, analyzing large amounts of data and transforming it into business and scientific insights has become a routine to companies in almost every field.
Big Data platforms have revolutionized the way companies approach information in their day to day operations, and thanks to that, businesses are able to reach valuable and reliable conclusions that were almost inaccessible in the past.
In order to simplify the Big Data analysis process and to improve agility and scalability, the transition of Big Data clusters to the public cloud was natural and coherent.
In this blog post, we will demonstrate how running Redis cluster slaves on the Spotinst Elastigroup platform assists in reducing the cluster’s cloud compute costs by leveraging AWS Spot Instances. Due to the fact that Redis clusters are stateful applications that require data continuity, we will deploy the slave servers using Spotinst Elastigroup’s Stateful feature.
What is Redis?
Redis is an open-source in-memory key-value database that persists the data in a rapid caching approach and has a highly distributed system.
What is Data caching?
Caching is the process of saving data on a fast and accessible memory. Redis is one of the caching methods which has a DB that caches the requests in order to provide a fast import of the results.
Why do we need Redis?
Redis enables developers to easily cache complex objects in order to retrieve faster results.
For example, Cassandra queries can take a while to process, due to the fact that Cassandra’s data is split through the nodes. In order to achieve results faster, Redis would cache the processed data, and serve the results to the client.
Redis cluster architecture
Redis has 2 main cluster modes, Sentinel and cluster mode.
In our use-case, we are going to focus on the cluster mode (the most common), where the cluster mode splits the Redis DB into shards. Every shard holds a portion of keys by using hash slots.
In Redis, there are 16384 hash slots, and in order to distribute the keys among the shards, every key is assigned to a hash slot by a hash function.
Every shard (Master) can have a slave replica that can failover from the master in case it fails. In order to failover, the cluster has to vote that the master isn’t healthy and then the slave will be promoted to a master.
How Spotinst reduces cluster costs?
Spotinst’s flag-ship product, Elastigroup, was designed to optimize performance and costs by reliably leveraging the cloud providers’ Excess Capacity, which in turn, reduces the cloud compute costs by up to 90%.
Elastigroup Stateful feature:
Ever since Spot Instances were introduced to the cloud compute market, leveraging them was applicable solely for stateless applications, due to the 2-minute interruption notification by AWS which causes a disturbance to the application’s operations.
In order to expand the reach of Spot Instances to additional use cases, we developed stateful capabilities that can run Stateful applications on spot instances while retaining high availability and data continuity.
Spotinst Elastigroup provides the user with the option to persist the root and data volumes, as well as the private IP of the EC2 instance.
Root volume persistency – When Spotinst persists the root volume of the EC2 instance, a back-end process is generating an AMI (Amazon Machine Image) every 5 minutes from the old instance, and in case an interruption is expected, the new instance will boot up from the latest AMI.
Data volume persistency – When Spotinst persists the data volume of the EC2 instance, a back-end process is generating an AMI using 2 possible methods: Reattach volumes or Snapshot backups.
Private IP persistency – When Spotinst will spin up the new instance it will de-attach the current ENI of the old instance and re-attach it to the new instance.
You can have an extended read on Spotinst’s stateful feature here
Spotinst’s prediction algorithm can detect an interruption 15 minutes prior to its occurrence, allowing enough time to spin up a new EC2 instance and migrate the private IP, and root and data volumes from the old instance.
Step by Step Tutorial:
In the following tutorial, we will demonstrate how to create a Stateful Elastigroup with Redis Slaves from the Spotinst console.
- Redis Master IP
- Network connection to the Redis Master cluster on ports 6379,16379
- From the Elastigroup dashboard, click on “Create Elastigroup” at the top right corner
- From the Use-Cases menu, select “Stateful Cluster”.
- Select “Create a new Elastigroup” and then click “Next”.
- Fill in the required details of your Stateful cluster and then click on “Next”
- Select “On-Demand” instance type, AZ’s, and Spot instance types that should be launched, and click “Next”
- On the “Persistence” tab, select “Persist Root Volume” and “Maintain Private IP”, and then click on “Next”.
- Fill in the “User-Data”, make sure to replace the <Master IP> in the script, and then click on “Next”
#!bin/bash sudo yum -y update sudo yum -y install gcc gcc-c++ make jemalloc tcl sudo mkdir /etc/redis /var/lib/redis cd /usr/local/src sudo wget "http://download.redis.io/redis-stable.tar.gz" sudo tar vxzf "redis-stable.tar.gz" sudo rm -f "redis-stable.tar.gz" cd "redis-stable" sudo make distclean sudo make sudo make install sudo sed -e "s/^bind 127.0.0.1$/bind $$(hostname -I | xargs)/" -e "s/^# cluster-enabled yes$/cluster-enabled yes/" -e "s/^# cluster-config-file nodes-6379.conf$/cluster-config-file nodes-6379.conf/" -e "s/^# cluster-node-timeout 15000$/cluster-node-timeout 15000/" -e "s/^daemonize no$/daemonize yes/" -e "s/^dir \.\//dir \/var\/lib\/redis\//" -e "s/^loglevel verbose$/loglevel notice/" -e "s/^logfile \"\"$/logfile \/var\/log\/redis.log/" redis.conf | sudo tee ./redisNew.conf redis-server ./redisNew.conf redis-cli --cluster add-node $$(hostname -I | xargs):6379 <Master IP>:6379 --cluster-slave
- Click on “Review” and then on “Create”
- After completing the deployment, we will see the instances online in the Elastigroup dashboard.
In this blog post, we have covered Spotinst Elastigroup’s stateful capabilities and how it’s data persistency enables additional use cases for utilizing Spot instances, which reduce the operational costs dramatically.
The use case demonstrated today is running Redis slave servers on Spot Instances and thus allowing a highly available and consistent cluster, at significantly lower costs.