Redis is a very fast In Memory NoSQL database that is commonly used for caching data for fast reads and writes with milliseconds latency.
It can reach > 1 million OPS (Operations Per Second) very easily and reduce the disk’s IOPS load (input/output = read/write operations per second) ,which heavily influences databases and applications performance.
It is being used very widely for web and mobile applications to store more static information like dimensions tables , user data and dynamic data like user logins and sessions to speed up application response time.
Redis uses key value records where the value can be anything text or binary.
127.0.0.1:6379> SET key1 hello
127.0.0.1:6379> GET key1
Another use of redis can be for pub sub ( message queueing) where clients apps can write information into the channel and many subscribers can listen and ingest the data in realtime from it.
Redis has an enterprise commercial edition which contains support and additional tools and community free addition where you can build a robust Redis cluster with all the features and functionality applications and organizations need.
Redis is in the memory database; some may want to not lose data when redis service is down. Redis support data persistency by writing the data into disk in several methods which you need to use according to the application use:
Redis can be installed in the same server as the application which holds its own redis instance for local caching reducing the network speed and can achieve high availability in case the application server is down and other servers are still up and running (Can be good when the cache size is small).
It can also be installed on a dedicated server shared between all application servers (good when caches data is big and should be shared between all app servers).
To avoid SPOF (single point of failure) when Redis Installed on a dedicated server – master slave deployment should be used.
In this type of deployment any data that is written to the master node is replicated to the slave .Incase the master crash, manual failover should be done to clients direct connection to the new master and rebuild the old master when it’s up again.
Redis Sentinel supports automatic failover and close to 0 downtime, its additional service that can be installed on another server (like app servers). Redis Sentinel monitors the cluster, verify if the master is not active, decides which node should be the master and does the automatic failover .This topology requires at least 3 instances or any other odd number of sentinel instances for quorum and voting to be able to achieve majority (when it’s even number of servers – you can get even results), elect the new master and avoid split brain (situation where more than 1 server can be the master)
The replication is being done in an asynchronous way and there can be data loss in case master crashes before replication was sent to the slaves.
To avoid it you can use the WAIT where WAIT 2 0 causes writes to wait until 2 replicas are acknowledged. Using this method reduces write performance.
Redis has a client library for all major programming languages that also support sentinel clusters. The Sentinel library registers the Redis Cluster nodes addresses and at connection time knows which one is the active master, Here is Python Sentinel Client – so no need for Load balancer in front.
In order to scale writes and reads Redis Cluster should be used.
Redis Cluster is used to scale out writes and reads. It is combined from several masters minimum 3 where each master holds a portion of the data = sharding where the shard distribution is being done by the document key hashing. each master node responsible for a subset of hash slots. So in cluster of 3 nodes:
Adding or removing nodes redistribute the hash slots between the nodes without downtime.
In order to have high availability every master node must have at least one replica so in case it fails the replica continues to operate.
Using the redis benchmark tool shows how you can reach 1.85 million writes per second In cluster of 9 masters.
SeaData makes lots of high scale projects so if you need help with redis or any database to consult or to build and manage such clusters don’t hesitate to contact us , we will be happy to assist.
MySQL Galera Cluster Introduction MySQL Galera cluster is the common solution for MySQL high availability and bring