REDIS As a Primary Database

 

We may heard about Redis many times, but we don’t know what is actually Redis is? Some part of people will tell it is a database and another part will say it is a caching system. First we clarify about data, database and caching system.

Data:

Data can be anything and everything, any information of fact can be considered as data (like name, age, address etc.) and data can be in any form (numbers, image, video, audio, text)

Database:

Database is systematic collections of data which is electronically stored into the computer, the purpose of storing data in a database is, it can be easily accessed, modified, protected and analyzed.

Is database is DBMS?

It is not entirely correct, Data base is just a container only used for storing data.

Where DBMS-data base management system is a software used for manage database, you need DBMS to interact with database (to retrieve, modify ,create and protect data).Users use DBMS in a specific language to interact with database .some popular DBMS are,

(ORACLE, MYSQL, POSTGRESQL, MONGODB, REDIS, SQLITE)

Caching:

Cache is a software or a hardware component that stores data so that the future requests served faster. Caching data is a process that stores multiple copies of data in a temporary storage so they can be accessed faster. It saves data for servers , websites , applications to speed up the site loading.

What is Redis?

REDIS-Remote dictionary server

Redis is an open source (BSD licensed), in-memory data structure store used as a database/cache, and message broker.it is a No SQL data base. all the data in Redis are stored in key value pair like Json. It is often referred to as a data structure server, since the keys can contain strings, hashes, lists, sets and sorted sets. Redis is written in C. 

 Redis began as a caching database to increase the application performance, but it has since evolved to a primary database. Many applications built today use Redis as a primary database.

Multi-model Database:



Many modern applications runs through polygot persistence architecture. Through this structure multiple micro services communicate with multiple databases, and databases communicate among themselves.

This polygot persistence architecture is more complex, cause of the complexity in the structure and  communication  performance of the application is slow.

Multiple micro services use multiple databases in this system, having and maintaining the multiple data bases is too expensive.and also it needs a separate database for caching.


 

 

REDIS as Primary Database:


Redis as a primary database solves the challenges faced by the polygot persistence architecture. Redis provides multi-model functionality in a single database through Redis modules. So having one database, like Redis, that allows you to store different types of data or basically allows you to have multiple types of databases in one as well as act as a cache.

How it Works?

The way it works is that you have Redis Core, which is a key value store that already supports storing multiple types of data and then you can extend that core with what's called modules for different data types, which your application needs for different purposes. So for example RediSearch for search functionality like ElasticSearch or Redis Graph for graph data storage .

 

NO Need of cache:

By having Redis as a database you don’t need a separate database for cache, because you have that automatically with Redis. You don’t need to manage and invalidate cache.

Redis is superfast:

Redis is a in-memory database  and also simple in structure makes it more faster than the multi-model databases.

 

Persist and Recovering Data:

The simplest way of having backup is by creating replicas. if the master instance goes down the replicas will still run .if Redis instances goes down we will loss all data

So Redis have two system for persist and recovering the data.

1.Snap shots:

Snap shots are configured by time or requests by the user. So snap shots of your data will be stored on a disk.so you can recover the data if the instances goes down.but you will loss the last minute data cause snapshots are configured for a specific time and requests.

2.  AOF:

AOF means append only file, it stores every changes made on a disk continuously. If you restart Redis or after a crash it will show append only log files to re-built the state. AOF is more reliable than snapshot but slower.

 

Scaling:

If the redis instance runs out of memory snd can’t able to accept requests from the user in that case you need to increase the capacity and the memory. for that redis have two options called sharding and clustering.

 

1.Clustering :

Clustering means having a primary/master Redis instance for reading and writing the data. and you can have multiple replicas of primary instance for reading data. by this way you can handle many requests .if master fails one of replicas will take over and Redis data base will run without any issues. This replicas have all the file copies of the master instance. if you run all the replicas in one server if the server goes down All the data in the master and the replicas will loss for that you need to have multiple servers, by this you can avoid the data loss caused by server down.

 

but what if

your dataset grows too large to fit in a memory on a single server.

we have scaled the reads in the database, so all the requests that basically just query the data. But our master instance is still alone and still has to handle all the writes.

For that we use the concept of sharding, which is a general concept in databases and which Redis also supports.

 

2.Sharding:

Sharding means instead of having one master instance that handles all the writes to the complete data set, you can split it into say 4 shards, each of them responsible for reads and writes to a subset of the data. And each shard also needs less memory capacity, because they just have a fourth of the data. This means you can distribute and run shards on smaller nodes and basically scale your cluster horizontally. So having multiple nodes, which run multiple replicas of Redis which are all sharded gives you a good performance highly available Redis database that can handle much more requests.

 

  

     

 

Comments

Popular posts from this blog

Oracle Database Server Architecture: Overview

Oracle E-Business Suite (EBS) - Introduction

Why enterprises must not ignore Azure DevOps Server