Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

REDIS

D A T E : 11 T H S E P T E M B E R 2017
AUTHOR: LALIT KHANNA

REDIS
Table of Contents
1. R E D I S .......................................................................................................................................... 3
1.1. P U R P O S E ................................................................................................................................. 3
1.2. W H Y R E D I S ........................................................................................................................... 3
1.3. H I G H L E V E L A R C H I T E C T U R E D I A G R A M ( M A S T E R D A T A ) ................................... 4
1.4. S E Q U E N C E D I A G R A M ( C H E C K M A S T E R D A T A I N C A C H E ) ......................................... 5
1.5. HOW WEB SERVER WILL KNOW REDIS CACHE OR CACHE SERVER IS
A V A I L A B L E .............................................................................................................................................. 6

1.6. F A I L O V E R P R O C E S S .............................................................................................................. 7
1.7. S E C U R I T Y ................................................................................................................................ 8
1.8. M U L T I T E N A N T ....................................................................................................................... 9
1.9. S U P P O R T & P R I C I N G / L I C E N S I N G .................................................................................. 10
1.10. S O M E F A Q ........................................................................................................................... 10
1.11. S T I L L Y O U H A V E Q U E S T I O N S .......................................................................................... 10

REDIS
1. REDIS
1.1. PURPOSE

Purpose of this document to explain about why we choose Redis &


what would be the architecture, security & support.

1.2. WHY REDIS

INTRODUCTION
Redis is an open source, in-memory data structure store, used as
database, cache and message broker. It supports data structures such
as strings, hashes, lists, sets, sorted sets with range queries, bitmaps
and geospatial indexes with radius queries.
Redis has built-in replication & failover, Lua scripting, LRU eviction,
transactions and different levels of on-disk persistence, and provides
high availability via Redis Sentinel and automatic partitioning with
Redis Cluster.

WHO USES REDIS ?


 Twitter ,GitHub, Weibo, Pinterest, Snapchat, Craigslist, Digg,
StackOverflow, Flickr
 Microsoft offers this is as part of their Azure offering.
 LEVERAGING REDIS
 Use distribution cache
 Use it for nonvolatile data sets
 Use expiration policy for data which changes occasionally
 Use intelligent, write, read cache algorithms
 Use for Session DB
 OPERATIONALIZING REDIS
 Short Term- Use Redis for static data
 Long Tem- Use Redis for Dynamic data (Which don’t change
frequently)
 Use Redis for session state

REDIS
WHAT DOES IT INVOLVE?
 For session state it is a configuration change
 For data caching given the current architecture of AHS we can start
with one method change and this will yield significant benefits.

1.3. HIGH LEVEL ARCHITECTURE DIAGRAM (MASTER


DATA)
Please note : Respect to caching,You don’t need to do anything on DB Server
side while introducing REDIS in our system. App/Web server only talk to Cache
Server.
This is simply cache mechanism which we usually use for application.

Web
Server 1

Sql Server
Balancer 1
Load

Sql Server
Mirror

Web
Server 2

REDIS
1.4. SEQUENCE DIAGRAM (CHECK MASTER DATA IN CACHE)
This sequence diagram shows how we will access the cache & in case absent, how
system will work.

Web Cache DB
User
Server Server Server

Request

Data exists in Cache

Get Data from Cache

Response Yes, then Return Data

Data don't exists in Cache


Data is not in Cache->Goto DB

Get Data

Update Data in Cache

Response

REDIS
1.5. HOW WEB SERVER WILL KNOW REDIS CACHE OR CACHE
SERVER IS AVAILABLE
We would have Redis reference in our application which helps to talk to Redis.After setting up the
reference we need to pass server name,User/Pwd on application side.

We’ve already written some standard classes on App side which will help us to get or
set in the Redis Cache.
Sample code
<connectionStrings>

<add name="RedisConnectionString" connectionString="192.168.1.33,connectTimeout=5000"


/>
</connectionStrings>

<appSettings>

<add key="REDISCACHESERVER" value="192.168.1.33" />


<add key="REDISCACESPLISTEXPIRY" value="01:00:00:00" />
<add key="ENABLECACHELOGIC" value="1" />

</appSettings>

This code

Code Side (App)

Private List<Coutries> GetCountryData()

List<Coutries> CoutryData;

If Cache[“CoutryData]==null

{ CoutryData =GetDataFromDB();

Cache[“CoutryData]!= CoutryData;

Else

{ CoutryData= Cache[“CoutryData]; return CoutryData ;} }

REDIS
1.6. FAILOVER PROCESS
In case of server (Redis) crash then automatically data will come from slave, if even
slave will also fail then data will come from DB.

Web Redis Redis


DB
Server Master Slave
Get Cache Data

Found Data

Return Data

Get Cache Data

Server Down

Get Data from Salve

Found Data

Return Data

Get Data

Server Down

Get Data from Salve

Server Down

Data Not found

Get Data from DB

Return Data

REDIS
1.7. SECURITY

Here is roadmap.

1.) Cache can only be access using User/Pwd. We would have different user/pwd based
on environments (i.e . Dev/QA/Prod)

2.) Nobody can access on Cache machine (Production)

3.) As this is under Linux system which is also protect all the resources.

4.) In case of sensitive data then we will use encryption from application side.

Encryption type : AES 256 with salt.

Please find below links which tells some of tips to secure for Redis Sever
https://www.1and1.com/cloud-community/learn/database/redis/securing-a-redis-installation/

REDIS
1.8. MULTITENANT

Redis running on an average Linux system can deliver even 1 million requests per
second. Redis can handle up to 2^32 keys, and was tested in practice to handle at least
250 million keys per instance.
Every hash, list, set, and sorted set, can hold 2^32 elements.
We could use this for multiple clients respect to caching because we've common master
data for all the clients, In case you've different data then we could have different key to
store in same server. This will bring very low cost model for us & awesome results.

Client C
Client B
Client A

Master
DB:D1Ma Data/
ster Data changeable
Data

Redis Server
Master
Master Data/
Data changeable
Data

Client F
Client D Client E

REDIS
1.9. SUPPORT & PRICING/LICENSING

We can explore more here for pricing

https://redislabs.com/pricing/

We could also explore azure Redis cache.

https://azure.microsoft.com/en-in/pricing/details/cache/

I'm not sure buying support from Redis because it is not that complicated technology
which can't be built in house. Off-course there is some learning curve. One point as I
said in section 1.5, If Master Server fails, it goes to Salve.. in worst situation if salve fails
then Automatically data will come from DB server so no big impact .Redis is very much
Robust system. It never crash just like that.

Just FYI: We've already built the servers & did one round of testing.

Respect to the software pricing or licensing, it’s the open source(BRD)

https://redis.io/topics/license

Cost Benefits from Redis Cache: In current environment our focus is only SQL Server
because of that all the burden is on SQL Server, so we're keep increasing RAM, Core etc
in SQL Server which is going to surely cut in future with the REDIS, at least limiting
what we've. As we’re using REDIS for multitenant which will help us to save lot of
money.

Bonus would be ULTIMATE PERFORMANCE & less hits on DB side.

1.10. SOME FAQ

https://redis.io/topics/faq

1.11. STILL YOU HAVE QUESTIONS


Please mail me at lkhanna@altruistahealth.com

REDIS

You might also like