Can Redis be used as a Primary database?

Hussein Nasser · Intermediate ·🔧 Backend Engineering ·4y ago

Key Takeaways

The video discusses whether Redis can be used as a primary database, covering its features, consistency, availability, and concurrency control, as well as its ability to handle various use cases beyond caching.

Full Transcript

can reduce take the place of your primary database system can you replace your relational postgres or mysql database with redis or your nosql mongodb or cassandra would reduce can radius be more than just a cache these are questions that you will be able to answer by the end of the video stay tuned this episode of the backend engineering show is sponsored by my friends at redis labs i'm gonna break this video into three sections first of all we're gonna define what really is a primary database what qualifies a primary database the second thing is does redis actually check the boxes of a primary database and then finally we're going to go through features and radius that go beyond just a primary database i was personally surprised by by most of these features to be honest let's just jump into this video so first of all what qualifies a database as a primary database these are few features slash capabilities that a primary database must have in order to be considered your teller data store where you store your information and these are not set on stone features you can argue about these kind of features but in my opinion i think these features are what qualifies the database as to be your primary main database system atomosity individual statements in a transaction should all succeed or fail thus provide a unit of work isolation how isolated a given transaction is from changes made by other concurrent transactions durability rights committed by a transaction must persist on a storage medium that even if a case of a failure we should see these rights and these rights should not be lost consistency it's the spectrum by which a read transaction gets a consistent value from the database system and i call this a spectrum because you can get a consistent value or you can get an eventually consistent value after some certain time so your system might not be consistent at this time but after a while it will eventually converge and get consistent so consistency eventual consistency consistency all of these fall into this category availability the spectrum by which a read or write transaction get a successful execution from your database system again availability is also a spectrum because you can configure this based on the cap theorem that i talked about you can check that video right here and finally concurrency control what happened when a transaction tries to change a value that actually had been changed since the transaction started do you block that change or do you allow it and fail later pessimistic versus optimistic currency control very popular to method there's no right or wrong i talked about this video in detail if you want to learn about concurrency control here check it out now that we know some of the properties of our primary database does radius actually check those boxes let's see atomicity yes radius is atomic you can start a transaction and you can do multiple statements multiple commands and then you can commit these changes and if there is a failure if you're using aof append only file writers will make sure to only commit all of these commands or none of them at all so this is atomic isolation redis uses the highest level of isolation which is called serializable so if you're executing two transaction at the same time they will be serialized to be exactly after each other durability radius have something called append only file durability format which is very similar to the wall right ahead log or the redo files in other databases and any command or transaction that you commit goes into this append only file and and it's very fast because it happened only so you can achieve high durability with append only file and the good thing about redis with durability is that you can configure this durability it's almost like a spectrum unlike other databases you can go with the snapshot durability that means all rights that have been happening to memory which is very fast will be flushed to disk that snapshot of the memory will be flush to disk asynchronously on the background every x amount of seconds the power of that your rights will be super fast because you're always right into memory and asynchronously you're gonna write and persist this to this yeah there is a possibility of failure but this is something you can figure do you want strong durability go with aof if you want fast right you go with snapshot and you can actually combine those two as well just like other databases you can configure it is to be strongly consistent or eventually consistent strong consistency is done by generally synchronous replications that means you issue a right to a master node that right does not commit until it commits to all other worker nodes if you want faster rights you do asynchronous applications so as long as the master rights succeeds commit and tell me it's done asynchronously in the background update your worker nodes and as a result yeah reads might get a little bit of a staler version but the rights are fast it's a choice that you make speaking of consistency it's worth mentioning that redis enterprise offers strong eventual consistency in active active clusters between data centers when we use active active clusters conflicts are inescapable since we are writing to both instances at the same time and when we get conflicts we are bound to be weakly consistent redis enterprise offers conflict-free replication through predefined rules and as a result we get strong eventual consistency between those instances and availability redis is available and you can configure this availability based on the asynchronous replication versus synchronous replication if you chose strong consistency usually you're not that available because if any right from the master to the worker failed then you're really not available right because you're gonna fail the right right and on the other hand if you chose eventual consistency then yeah your rights will always succeed as you are available but you might get a little bit of a stale data what are the mercy of the cap theorem finally concurrency control as i talk about many time in the channel reduce is a simple single threaded database system so there isn't really a true concurrency but you can still prevent other transaction from changing something that you're about to read through something called optimistic locks or optimistic concurrency control and this is achieved by something called the watch command in redis you watch a value you start your transaction and if someone else committed a change to that value your transaction eventually at the end when you try to execute it or to commit it it will fail thus turning you telling you to retry it that's the effectively the optimistic approach right there's obviously pros and cons to each approach but yeah it does support that and starting from redis version 6 io in redis is actually now threaded while the core remains single threaded and we have knew this even before redis 6 redis still uses multi-threading to take the snapshot of the memory and write it to the desk and it seems now they expanded that to almost all ios pretty good now that we know that redis has the properties of a primary database let's go beyond just a storage system and actually i made a few videos talking about some of these features you may know red is for caching but it's actually used for about 20 completely different things here are a few common use cases caching obviously it's a very fast in-memory right cache so you can use it as a right through cache right back cache you can use it as search for session management you can use it for pub sub yes it's very popular i've seen many many many many companies users use redis for pop sub systems so just like that you get features from a q and a pop subsystem so if you're looking for a pop sub system you can replace your kafka or rabbitmq with radius and speaking of kafka you can use redis streams which works like kafka to ingest real-time data for example from an iot devices to connect different microservices together uber actually uses radio streams to replicate their data across data centers they also obviously use redis for other common use cases such as queuing and caching i'll have a link to their video in the cards a lot of other users use it for rate limiting especially if you're building an eye api gateway or ip white listing because you can you you're quickly looking at our ip and because it's a key value store you're going to get it very fast in addition redis is also used for real-time search knowledge graph real-time analytics application metrics and forecasting and real-time artificial intelligence and all these use cases really are even possible because redis provides more than 15 data structures and six modules which work natively in redis to make it all possible this is why redis is not just a primary database but it's actually a multi-model multi-structure database so here are few data types that redis supports strings obviously lists sets hashes sorted sets bitmaps and hyperlog logs another fundamental benefit of having these native data structures is they make it easy for engineers to store data naturally without transformation for example in java you have sets arrays hash maps etc all these types exist in redis natively however if you're using an rdbms you'll need to morph and transform these data structures into tables not only that you'll also need to access this data using sql this is as opposed to regular array set or hash map commands this additional overhead is a result of the mismatch between how you think an object in object-oriented programming versus relational databases tables this is known as the object relational impedance mismatch martin fuller has talked about impedance mismatch and object oriented programming a bit i'm going to reference his video in the description below another plus for red is because it's a very popular database you have many supports for a lot of languages and sdks as well another thing i love about this and i talked about this in my previous videos about reddish is the redis binary protocol which is called resp that that protocol actually supports something called pipelining which i talked about in my http videos pipelining is the ability to send multiple commands at the same time on the same tcp connection and instead of doing a request response like so send a command wait for results in the command wait for a result so you get much much better throughput as a result so during this video we learned what a primary database is we saw that rellis checks these boxes of a primary database we also seen that radius use cases go beyond just a primary database we've seen how red this is a multi-modal database we've seen it reduce the impedance mismatch in programming with native data types and finally redis enterprise provides even more enterprise grade features such as active active conflict-free geo replication now i gotta ask the question to you guys what do you think can rudders be used as a primary database let me know in those comments down below i'm gonna see you on the next one you guys stay awesome goodbye

Original Description

This episode of the backend engineering show is sponsored by my friends at RedisLabs. I’m going to break this video into three sections, we will first define features that qualify a primary database? Then we will see if Redis actually check the boxes of a primary database and finally we explore the features of Redis that take it beyond a primary database. I was personally surprised by most of those. Addendum: Redis also provides strict serializability through RedisRaft project. RedisRaft has passed the Jepsen tests, an industry standard for verifying consistency of distributed database systems. Read more on RedisRaft here https://jepsen.io/analyses/redis-raft-1b3fbf6 Redis Raft github https://github.com/RedisLabs/redisraft Strict Serializability https://jepsen.io/consistency/models/strict-serializable Chapters 0:00 Intro 1:00 What Qualifies a primary database 3:00 Does Redis Check the boxes? 7:40 beyond Redis Resources Try Free: https://bit.ly/3hWr1Uj Redis Advantages: https://bit.ly/3ztx2xw Martin Fowler talking about Impedance Mismatch: https://bit.ly/36ZEOD8 Transactions: https://bit.ly/3wTMKAw ACID 0.5 MM Ops/Seconds on AWS: https://bit.ly/3ruMB5s Consistency and Durability: https://bit.ly/3wYNLr8 Watch and Rollbacks: https://redislabs.com/blog/you-dont-need-transaction-rollbacks-in-redis/#:~:text=Redis%20has%20a%20main%2C%20single,is%20required%20to%20implement%20WATCH Redis Enterprise https://redislabs.com/redis-enterprise/advantages/ https://redis.io/topics/transactions#cas https://redislabs.com/blog/you-dont-need-transaction-rollbacks-in-redis/#:~:text=Redis%20has%20a%20main%2C%20single,is%20required%20to%20implement%20WATCH. https://docs.redislabs.com/latest/rs/concepts/data-access/consistency-durability/
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Hussein Nasser · Hussein Nasser · 0 of 60

← Previous Next →
1 Extending ArcObjects (IGeometry) - 01 - Getting Started
Extending ArcObjects (IGeometry) - 01 - Getting Started
Hussein Nasser
2 Extending ArcObjects  (IGeometry) - 02 - The Document, The Map and The Layers
Extending ArcObjects (IGeometry) - 02 - The Document, The Map and The Layers
Hussein Nasser
3 Channel Update - New Book, New Job, New Videos
Channel Update - New Book, New Job, New Videos
Hussein Nasser
4 Learn Programming with VB.NET - 01 - Getting Started
Learn Programming with VB.NET - 01 - Getting Started
Hussein Nasser
5 Learn Programming with VB.NET - 02 - Classes and Objects (Part 1)
Learn Programming with VB.NET - 02 - Classes and Objects (Part 1)
Hussein Nasser
6 Learn Programming with VB.NET - 03 - Classes and Objects (Part 2)
Learn Programming with VB.NET - 03 - Classes and Objects (Part 2)
Hussein Nasser
7 Learn Programming with VB.NET - 04 - User Interface
Learn Programming with VB.NET - 04 - User Interface
Hussein Nasser
8 Learn Programming with VB.NET - 05 - By Value v. By Reference
Learn Programming with VB.NET - 05 - By Value v. By Reference
Hussein Nasser
9 Learn Programming with VB.NET - 06 - Variable size, 32 bit vs 64 bit
Learn Programming with VB.NET - 06 - Variable size, 32 bit vs 64 bit
Hussein Nasser
10 Learn Programming with VB.NET - 07 - Conditional Statements
Learn Programming with VB.NET - 07 - Conditional Statements
Hussein Nasser
11 Learn Programming with VB.NET - 08 - Inheritance
Learn Programming with VB.NET - 08 - Inheritance
Hussein Nasser
12 Learn Programming with VB.NET - 09 - Strategy Design Pattern
Learn Programming with VB.NET - 09 - Strategy Design Pattern
Hussein Nasser
13 Learn Programming with VB.NET - 10 -  How did I learn programming
Learn Programming with VB.NET - 10 - How did I learn programming
Hussein Nasser
14 IGeometry 2016 Retrospective - Channel Update
IGeometry 2016 Retrospective - Channel Update
Hussein Nasser
15 Javascript by Example - The Vook
Javascript by Example - The Vook
Hussein Nasser
16 Vlog - Keep your servers close and your database closer
Vlog - Keep your servers close and your database closer
Hussein Nasser
17 Vlog - Client/Server Programming Languages
Vlog - Client/Server Programming Languages
Hussein Nasser
18 Javascript By Example L1E01 - Getting Started
Javascript By Example L1E01 - Getting Started
Hussein Nasser
19 Persistent Connections (Pros and Cons)
Persistent Connections (Pros and Cons)
Hussein Nasser
20 Javascript By Example L1E02 - Building the Calculator Interface
Javascript By Example L1E02 - Building the Calculator Interface
Hussein Nasser
21 Happy new Year from IGeometry!
Happy new Year from IGeometry!
Hussein Nasser
22 Synchronous v. Asynchronous
Synchronous v. Asynchronous
Hussein Nasser
23 Javascript By Example L1E03 - Displaying the Digits on Calculator Screen
Javascript By Example L1E03 - Displaying the Digits on Calculator Screen
Hussein Nasser
24 Show Your Work. Blog, Vlog, Write, Create and Develop!
Show Your Work. Blog, Vlog, Write, Create and Develop!
Hussein Nasser
25 Relational Database Atomicity Explained By Example
Relational Database Atomicity Explained By Example
Hussein Nasser
26 Javascript By Example L1E04 - Operators, All Clear with Arrow Functions
Javascript By Example L1E04 - Operators, All Clear with Arrow Functions
Hussein Nasser
27 What Comes First, User Experience or Software Architecture?
What Comes First, User Experience or Software Architecture?
Hussein Nasser
28 Javascript By Example L1E05 -  Evaluate the Calculator Expressions with eval
Javascript By Example L1E05 - Evaluate the Calculator Expressions with eval
Hussein Nasser
29 Fastest Way to Learn Programming Language or Technology
Fastest Way to Learn Programming Language or Technology
Hussein Nasser
30 Javascript By Example L1E06 -  Fix Leading Zero Bug with Conditions
Javascript By Example L1E06 - Fix Leading Zero Bug with Conditions
Hussein Nasser
31 Stateful vs Stateless Applications (Explained by Example)
Stateful vs Stateless Applications (Explained by Example)
Hussein Nasser
32 Javascript By Example L1E07 - Running our Calculator on the Mobile Phone
Javascript By Example L1E07 - Running our Calculator on the Mobile Phone
Hussein Nasser
33 Advice for New Software Engineers and Developers
Advice for New Software Engineers and Developers
Hussein Nasser
34 Why JSON is so Popular?
Why JSON is so Popular?
Hussein Nasser
35 Building Scalable Software - SLA, HS, VS
Building Scalable Software - SLA, HS, VS
Hussein Nasser
36 Vlog (Istanbul) - Datacenter Proximity
Vlog (Istanbul) - Datacenter Proximity
Hussein Nasser
37 Should Software Engineers Learn Bleeding-Edge Technologies?
Should Software Engineers Learn Bleeding-Edge Technologies?
Hussein Nasser
38 Do Developers Build Bad User Interfaces/Experience?
Do Developers Build Bad User Interfaces/Experience?
Hussein Nasser
39 Learn By Doing.
Learn By Doing.
Hussein Nasser
40 I Wrote Bad Front-End Code That Broke Chrome
I Wrote Bad Front-End Code That Broke Chrome
Hussein Nasser
41 My Story
My Story
Hussein Nasser
42 Vlog - Horizontal vs Vertical Scaling
Vlog - Horizontal vs Vertical Scaling
Hussein Nasser
43 Can User Experience Help Build Better Rest API?
Can User Experience Help Build Better Rest API?
Hussein Nasser
44 Reverse engineering Instagram in flight mode
Reverse engineering Instagram in flight mode
Hussein Nasser
45 The Benefits of the 3-Tier Architecture (e.g. REST API)
The Benefits of the 3-Tier Architecture (e.g. REST API)
Hussein Nasser
46 Stateless v. Stateful Architecture (Podcast)
Stateless v. Stateful Architecture (Podcast)
Hussein Nasser
47 The evolution from virtual machines to containers
The evolution from virtual machines to containers
Hussein Nasser
48 Proxy vs. Reverse Proxy (Explained by Example)
Proxy vs. Reverse Proxy (Explained by Example)
Hussein Nasser
49 Canary Deployment (Explained by Example)
Canary Deployment (Explained by Example)
Hussein Nasser
50 No Excuses
No Excuses
Hussein Nasser
51 Synchronous vs Asynchronous Applications (Explained by Example)
Synchronous vs Asynchronous Applications (Explained by Example)
Hussein Nasser
52 What is an Asynchronous service?
What is an Asynchronous service?
Hussein Nasser
53 Difference between Client Polling vs Server Push in Notifications
Difference between Client Polling vs Server Push in Notifications
Hussein Nasser
54 Software vs. Hardware AdBlockers (Explained by Example)
Software vs. Hardware AdBlockers (Explained by Example)
Hussein Nasser
55 HTTP Caching with E-Tags -  (Explained by Example)
HTTP Caching with E-Tags - (Explained by Example)
Hussein Nasser
56 Simple Object Access Protocol Pros and Cons (Explained by Example)
Simple Object Access Protocol Pros and Cons (Explained by Example)
Hussein Nasser
57 Nodejs Express "Hello, World"
Nodejs Express "Hello, World"
Hussein Nasser
58 Reverse Engineering Instagram feed
Reverse Engineering Instagram feed
Hussein Nasser
59 Popup Modal Dialog with Javascript and HTML
Popup Modal Dialog with Javascript and HTML
Hussein Nasser
60 MIME and Media Type sniffing explained and the type of attacks it leads to
MIME and Media Type sniffing explained and the type of attacks it leads to
Hussein Nasser

This video explores the possibility of using Redis as a primary database, discussing its features, consistency, availability, and concurrency control, as well as its ability to handle various use cases beyond caching. By the end of this video, you will understand the trade-offs and considerations for using Redis as a primary database.

Key Takeaways
  1. Define the features that qualify a primary database
  2. Evaluate Redis's consistency and availability based on the CAP theorem
  3. Configure Redis for strong consistency or eventual consistency using synchronous or asynchronous replication
  4. Implement concurrency control using the watch command
  5. Explore Redis's ability to handle various use cases beyond caching
  6. Consider the trade-offs and limitations of using Redis as a primary database
💡 Redis can be used as a primary database, but its consistency and availability depend on the specific configuration and use case, and it is essential to consider the trade-offs and limitations of using Redis as a primary database.

Related Reads

Chapters (4)

Intro
1:00 What Qualifies a primary database
3:00 Does Redis Check the boxes?
7:40 beyond Redis
Up next
How I Built an App with Lovable in Under 1 Hour (2025 Tutorial)
Alex Leischow
Watch →