SlideShare a Scribd company logo
Redis: Your magical superfast Database
Saurabh Minni
Who am I
• Technical Architect at Adnear
• Been part of planners at Barcamp Bangalore for past 6 years
• Previously worked at Intuit and Adobe for desktop and mobile products
What we do with Redis
Achieve <5 millisecond response times for ad serving traffic of over 250M requests daily
We use redis for
• Searching the right ad for the users location
• Searching the right ad for the users profile
Some real problem it solves
• Search for hyperlocal ads which are spread across multiple countries and with various radius’s
• Search and select ads for over 100+ million profiled users
So what is Redis
• Key-value based NoSQL
• In memory Database
• Variety of data-types supported
• Support for persistence
• Support for Master Slave cluster setup
• Its written in C, and is super efficient
• Its Open Source
What Redis is not
• Relational Database
• Document Store
• Structured Database
• HTTP Store
Redis Data Types
• Strings
• Lists
• Sets
• Hashes
• Sorted Sets
Strings
Most basic types of Redis value
Redis Strings are binary safe
A String value can be at max 512 Megabytes in length.
What you can do :
• INCR,DECR,INCRBY.
• APPENDcommand.
• GETRANGEandSETRANGE.
• GETBITandSETBIT.
Lists
• lists of strings
• sorted by insertion order
• max length of a list is 2
32
- 1 elements (4294967295)
• LPUSH,RPUSH
Sets
• unordered collection of Strings
• add, remove, and test for existence of members in O(1)
• property of not allowing repeated members
• max number of members in a set is 2
32
- 1 (4294967295)
Hashes
• Redis Hashes are maps between string fields and string values
• Represent objects (eg: A User with fields like name, surname, age etc)
• Every hash can store up to 2
32
- 1 field-value pairs
Sorted Sets
• Similar to Redis Sets, non repeating collections of Strings
• every member of a Sorted Set is associated with score used in order to take the sorted set ordered, from the smallest to the
greatest score
• While members are unique, scores may be repeated.
• Complexity to add, remove and update is O(log n)
Different configurations
Scaling to specs
In Memory with persistence (RDB)
Redis Instance
Dump File
Data to Disk
In Memory with persistence (AOF)
Redis Instance
AOF File
Command Loggin
Redis Client
Data change command
Redis Cluster
Replication - Single Slave
Master RedisNode Slave RedisNode
Data Replicated
Redis Client
Data change command
Redis Cluster
Replication - Multiple Slave
Master RedisNode
Slave RedisNode 1
Data Replicated
Redis Client
Write Command
Slave RedisNode 2
Slave RedisNode 3
Read Command
Sharding - Vertical
Master RedisNode
Slave RedisNode 1
User Info
Slave RedisNode 2
Master RedisNode
Slave RedisNode 1 Slave RedisNode 2
Content
Sharding - Range
Master RedisNode
Slave RedisNode 1 Slave RedisNode 2
Master RedisNode
Slave RedisNode 1 Slave RedisNode 2
Key % Number of Shard(Key % 2)
How we do it at Adnear
Master RedisNode
Slave RedisNode 1 Slave RedisNode 2
Master RedisNode
Slave RedisNode 1 Slave RedisNode 2
Ad Engine A
Ad Engine B
ZMQ

More Related Content

PPT
NoSQL Databases
Carlos Alberto Benitez
 
PPTX
The Hive Think Tank: Rocking the Database World with RocksDB
The Hive
 
PDF
Indexing, searching, and aggregation with redi search and .net
Stephen Lorello
 
PDF
Redis Overview
Hoang Long
 
ODP
Redis IU
Isaiah Edem
 
PPTX
An Intro to NoSQL Databases
Rajith Pemabandu
 
PPTX
The Hive Think Tank: Rocking the Database World with RocksDB
The Hive
 
PDF
ORCID for DSpace
Bram Luyten
 
NoSQL Databases
Carlos Alberto Benitez
 
The Hive Think Tank: Rocking the Database World with RocksDB
The Hive
 
Indexing, searching, and aggregation with redi search and .net
Stephen Lorello
 
Redis Overview
Hoang Long
 
Redis IU
Isaiah Edem
 
An Intro to NoSQL Databases
Rajith Pemabandu
 
The Hive Think Tank: Rocking the Database World with RocksDB
The Hive
 
ORCID for DSpace
Bram Luyten
 

What's hot (20)

PPTX
Redis database
Ñáwrás Ñzár
 
PPTX
NoSQL document oriented data access for .net systems with postgresql and marten
Bojan Veljanovski
 
PDF
Steam Learn: An introduction to Redis
inovia
 
KEY
Redis
Ramon Wartala
 
PPTX
RocksDB detail
MIJIN AN
 
PPTX
Using MongoDB For BigData in 20 Minutes
András Fehér
 
PDF
RDF Seminar Presentation
Muntazir Mehdi
 
PPTX
Introduction to MongoDB and CRUD operations
Anand Kumar
 
PPTX
The Hive Think Tank: Rocking the Database World with RocksDB
The Hive
 
PPTX
Introduction To MongoDB
Yubraj Ghimire
 
PDF
The ECM world from the point of view of Alfresco - Linux Day 2013 - Rome
Piergiorgio Lucidi
 
PPTX
Introduction to Big Data and Hadoop
SSandip Patil
 
KEY
MongoDB Hadoop DC
Mike Dirolf
 
PPTX
Introduction to Redis Data Structures: Hashes
ScaleGrid.io
 
PDF
So we all have ORCID integrations, now what?
Bram Luyten
 
KEY
MongoDB Administration ~ Kevin Hanson
hungarianhc
 
PDF
NOSQL Databases
hicham jabbour
 
PPTX
Storage Engine Wars at Parse
MongoDB
 
PPTX
Why Your MongoDB Needs Redis
Itamar Haber
 
PPTX
MongoDB
Ganesh Kunwar
 
NoSQL document oriented data access for .net systems with postgresql and marten
Bojan Veljanovski
 
Steam Learn: An introduction to Redis
inovia
 
Redis
Ramon Wartala
 
RocksDB detail
MIJIN AN
 
Using MongoDB For BigData in 20 Minutes
András Fehér
 
RDF Seminar Presentation
Muntazir Mehdi
 
Introduction to MongoDB and CRUD operations
Anand Kumar
 
The Hive Think Tank: Rocking the Database World with RocksDB
The Hive
 
Introduction To MongoDB
Yubraj Ghimire
 
The ECM world from the point of view of Alfresco - Linux Day 2013 - Rome
Piergiorgio Lucidi
 
Introduction to Big Data and Hadoop
SSandip Patil
 
MongoDB Hadoop DC
Mike Dirolf
 
Introduction to Redis Data Structures: Hashes
ScaleGrid.io
 
So we all have ORCID integrations, now what?
Bram Luyten
 
MongoDB Administration ~ Kevin Hanson
hungarianhc
 
NOSQL Databases
hicham jabbour
 
Storage Engine Wars at Parse
MongoDB
 
Why Your MongoDB Needs Redis
Itamar Haber
 
MongoDB
Ganesh Kunwar
 
Ad

Similar to Redis - Your Magical superfast database (20)

PPTX
Introduction to Redis
Ofer Zelig
 
PDF
Introduction to Redis
Dvir Volk
 
PPTX
Redis introduction
Federico Daniel Colombo Gennarelli
 
PDF
mar07-redis.pdf
AnisSalhi3
 
PDF
Redis - The Universal NoSQL Tool
Eberhard Wolff
 
PDF
An Introduction to Redis for Developers.pdf
Stephen Lorello
 
PPT
Introduction to redis
Tanu Siwag
 
PDF
Mini-Training: Redis
Betclic Everest Group Tech Team
 
PDF
Introduction to Redis
Itamar Haber
 
PPTX
Redis data structure and Performance Optimization
Knoldus Inc.
 
PPTX
Redis_Presentation.pptx ppt on redis and
tanishksaini51
 
PPTX
Get more than a cache back! - ConFoo Montreal
Maarten Balliauw
 
PDF
Introduction to redis - version 2
Dvir Volk
 
PDF
key value dbs , redis , cassandra , their architecture
VrajGaglani
 
PPT
Redis And python at pycon_2011
sunilar0ra
 
PDF
Redis Everywhere - Sunshine PHP
Ricard Clau
 
PPTX
REDIS327
Rajan Bhatt
 
PDF
An Introduction to Redis for .NET Developers.pdf
Stephen Lorello
 
ODP
Redis overview
Ahmad El-khuja
 
PDF
Tuga IT 2017 - Redis
Nuno Caneco
 
Introduction to Redis
Ofer Zelig
 
Introduction to Redis
Dvir Volk
 
mar07-redis.pdf
AnisSalhi3
 
Redis - The Universal NoSQL Tool
Eberhard Wolff
 
An Introduction to Redis for Developers.pdf
Stephen Lorello
 
Introduction to redis
Tanu Siwag
 
Mini-Training: Redis
Betclic Everest Group Tech Team
 
Introduction to Redis
Itamar Haber
 
Redis data structure and Performance Optimization
Knoldus Inc.
 
Redis_Presentation.pptx ppt on redis and
tanishksaini51
 
Get more than a cache back! - ConFoo Montreal
Maarten Balliauw
 
Introduction to redis - version 2
Dvir Volk
 
key value dbs , redis , cassandra , their architecture
VrajGaglani
 
Redis And python at pycon_2011
sunilar0ra
 
Redis Everywhere - Sunshine PHP
Ricard Clau
 
REDIS327
Rajan Bhatt
 
An Introduction to Redis for .NET Developers.pdf
Stephen Lorello
 
Redis overview
Ahmad El-khuja
 
Tuga IT 2017 - Redis
Nuno Caneco
 
Ad

More from the100rabh (6)

PDF
Distributed Realtime Computation using Apache Storm
the100rabh
 
PDF
Apache kafka
the100rabh
 
PPTX
Barcamp Bangalore App
the100rabh
 
PPTX
Making your ui look good on android
the100rabh
 
PPT
Cloud @ Home
the100rabh
 
PPT
Pleasure Blogging
the100rabh
 
Distributed Realtime Computation using Apache Storm
the100rabh
 
Apache kafka
the100rabh
 
Barcamp Bangalore App
the100rabh
 
Making your ui look good on android
the100rabh
 
Cloud @ Home
the100rabh
 
Pleasure Blogging
the100rabh
 

Recently uploaded (20)

PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
PDF
Beyond Automation: The Role of IoT Sensor Integration in Next-Gen Industries
Rejig Digital
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PPT
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
PDF
This slide provides an overview Technology
mineshkharadi333
 
PDF
Software Development Company | KodekX
KodekX
 
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PPTX
Coupa-Overview _Assumptions presentation
annapureddyn
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
Beyond Automation: The Role of IoT Sensor Integration in Next-Gen Industries
Rejig Digital
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
This slide provides an overview Technology
mineshkharadi333
 
Software Development Company | KodekX
KodekX
 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Coupa-Overview _Assumptions presentation
annapureddyn
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 

Redis - Your Magical superfast database

  • 1. Redis: Your magical superfast Database Saurabh Minni
  • 2. Who am I • Technical Architect at Adnear • Been part of planners at Barcamp Bangalore for past 6 years • Previously worked at Intuit and Adobe for desktop and mobile products
  • 3. What we do with Redis Achieve <5 millisecond response times for ad serving traffic of over 250M requests daily We use redis for • Searching the right ad for the users location • Searching the right ad for the users profile
  • 4. Some real problem it solves • Search for hyperlocal ads which are spread across multiple countries and with various radius’s • Search and select ads for over 100+ million profiled users
  • 5. So what is Redis • Key-value based NoSQL • In memory Database • Variety of data-types supported • Support for persistence • Support for Master Slave cluster setup • Its written in C, and is super efficient • Its Open Source
  • 6. What Redis is not • Relational Database • Document Store • Structured Database • HTTP Store
  • 7. Redis Data Types • Strings • Lists • Sets • Hashes • Sorted Sets
  • 8. Strings Most basic types of Redis value Redis Strings are binary safe A String value can be at max 512 Megabytes in length. What you can do : • INCR,DECR,INCRBY. • APPENDcommand. • GETRANGEandSETRANGE. • GETBITandSETBIT.
  • 9. Lists • lists of strings • sorted by insertion order • max length of a list is 2 32 - 1 elements (4294967295) • LPUSH,RPUSH
  • 10. Sets • unordered collection of Strings • add, remove, and test for existence of members in O(1) • property of not allowing repeated members • max number of members in a set is 2 32 - 1 (4294967295)
  • 11. Hashes • Redis Hashes are maps between string fields and string values • Represent objects (eg: A User with fields like name, surname, age etc) • Every hash can store up to 2 32 - 1 field-value pairs
  • 12. Sorted Sets • Similar to Redis Sets, non repeating collections of Strings • every member of a Sorted Set is associated with score used in order to take the sorted set ordered, from the smallest to the greatest score • While members are unique, scores may be repeated. • Complexity to add, remove and update is O(log n)
  • 14. In Memory with persistence (RDB) Redis Instance Dump File Data to Disk
  • 15. In Memory with persistence (AOF) Redis Instance AOF File Command Loggin Redis Client Data change command
  • 16. Redis Cluster Replication - Single Slave Master RedisNode Slave RedisNode Data Replicated Redis Client Data change command
  • 17. Redis Cluster Replication - Multiple Slave Master RedisNode Slave RedisNode 1 Data Replicated Redis Client Write Command Slave RedisNode 2 Slave RedisNode 3 Read Command
  • 18. Sharding - Vertical Master RedisNode Slave RedisNode 1 User Info Slave RedisNode 2 Master RedisNode Slave RedisNode 1 Slave RedisNode 2 Content
  • 19. Sharding - Range Master RedisNode Slave RedisNode 1 Slave RedisNode 2 Master RedisNode Slave RedisNode 1 Slave RedisNode 2 Key % Number of Shard(Key % 2)
  • 20. How we do it at Adnear Master RedisNode Slave RedisNode 1 Slave RedisNode 2 Master RedisNode Slave RedisNode 1 Slave RedisNode 2 Ad Engine A Ad Engine B ZMQ

Editor's Notes

  • #9: You can do a number of interesting things using strings in Redis, for instance you can: Use Strings as atomic counters using commands in the INCR family:INCR,DECR,INCRBY. Append to strings with theAPPENDcommand. Use Strings as a random access vectors withGETRANGEandSETRANGE. Encode a lot of data in little space, or create a Redis backed Bloom Filter usingGETBITandSETBIT.
  • #15: Redis provides a different range of persistence options: The RDB persistence performs point-in-time snapshots of your dataset at specified intervals. the AOF persistence logs every write operation received by the server, that will be played again at server startup, reconstructing the original dataset. Commands are logged using the same format as the Redis protocol itself, in an append-only fashion. Redis is able to rewrite the log on background when it gets too big. If you wish, you can disable persistence at all, if you want your data to just exist as long as the server is running. It is possible to combine both AOF and RDB in the same instance. Notice that, in this case, when Redis restarts the AOF file will be used to reconstruct the original dataset since it is guaranteed to be the most complete. The most important thing to understand is the different trade-offs between the RDB and AOF persistence. Let&amp;apos;s start with RDB: RDB advantages RDB is a very compact single-file point-in-time representation of your Redis data. RDB files are perfect for backups. For instance you may want to archive your RDB files every hour for the latest 24 hours, and to save an RDB snapshot every day for 30 days. This allows you to easily restore different versions of the data set in case of disasters. RDB is very good for disaster recovery, being a single compact file can be transfered to far data centers, or on Amazon S3 (possibly encrypted). RDB maximizes Redis performances since the only work the Redis parent process needs to do in order to persist is forking a child that will do all the rest. The parent instance will never perform disk I/O or alike. RDB allows faster restarts with big datasets compared to AOF. RDB disadvantages RDB is NOT good if you need to minimize the chance of data loss in case Redis stops working (for example after a power outage). You can configure differentsave pointswhere an RDB is produced (for instance after at least five minutes and 100 writes against the data set, but you can have multiple save points). However you&amp;apos;ll usually create an RDB snapshot every five minutes or more, so in case of Redis stopping working without a correct shutdown for any reason you should be prepared to lose the latest minutes of data. RDB needs to fork() often in order to persist on disk using a child process. Fork() can be time consuming if the dataset is big, and may result in Redis to stop serving clients for some millisecond or even for one second if the dataset is very big and the CPU performance not great. AOF also needs to fork() but you can tune how often you want to rewrite your logs without any trade-off on durability.
  • #16: AOF advantages Using AOF Redis is much more durable: you can have different fsync policies: no fsync at all, fsync every second, fsync at every query. With the default policy of fsync every second write performances are still great (fsync is performed using a background thread and the main thread will try hard to perform writes when no fsync is in progress.) but you can only lose one second worth of writes. The AOF log is an append only log, so there are no seeks, nor corruption problems if there is a power outage. Even if the log ends with an half-written command for some reason (disk full or other reasons) the redis-check-aof tool is able to fix it easily. Redis is able to automatically rewrite the AOF in background when it gets too big. The rewrite is completely safe as while Redis continues appending to the old file, a completely new one is produced with the minimal set of operations needed to create the current data set, and once this second file is ready Redis switches the two and starts appending to the new one. AOF contains a log of all the operations one after the other in an easy to understand and parse format. You can even easily export an AOF file. For instance even if you flushed everything for an error using a FLUSHALL command, if no rewrite of the log was performed in the meantime you can still save your data set just stopping the server, removing the latest command, and restarting Redis again. AOF disadvantages AOF files are usually bigger than the equivalent RDB files for the same dataset. AOF can be slower than RDB depending on the exact fsync policy. In general with fsync set toevery secondperformances are still very high, and with fsync disabled it should be exactly as fast as RDB even under high load. Still RDB is able to provide more guarantees about the maximum latency even in the case of an huge write load. In the past we experienced rare bugs in specific commands (for instance there was one involving blocking commands like BRPOPLPUSH) causing the AOF produced to not reproduce exactly the same dataset on reloading. This bugs are rare and we have tests in the test suite creating random complex datasets automatically and reloading them to check everything is ok, but this kind of bugs are almost impossible with RDB persistence. To make this point more clear: the Redis AOF works incrementally updating an existing state, like MySQL or MongoDB does, while the RDB snapshotting creates everything from scratch again and again, that is conceptually more robust. However - 1) It should be noted that every time the AOF is rewritten by Redis it is recreated from scratch starting from the actual data contained in the data set, making resistance to bugs stronger compared to an always appending AOF file (or one rewritten reading the old AOF instead of reading the data in memory). 2) We never had a single report from users about an AOF corruption that was detected in the real world.