Today's Deep-Dive: Redis
Ep. 272

Today's Deep-Dive: Redis

Episode description

Redis is a versatile, high-speed tool essential for modern applications, particularly those requiring real-time data and AI features. It is an in-memory data structure server that offers sub-millisecond latency, making it ideal for caching, session management, messaging, and real-time analytics. Redis’s design focuses on performance, using RAM to avoid slow disk I/O, which is crucial for handling millions of requests per second. Its versatility extends beyond simple key-value storage, offering specialized data structures like sorted sets, hashes, and probabilistic structures. Redis is also pivotal in AI, serving as a vector store for fast semantic searches, enabling retrieval-augmented generation and potentially reducing AI costs by up to 90% through semantic caching. For beginners, Redis can be easily set up using Redis Cloud or Docker, with user-friendly tools like Redis Insight and Redis Copilot available for interaction and management. The deep dive encourages considering Redis as a central tool to simplify application architecture by consolidating multiple functions into one efficient system.

Gain digital sovereignty now and save costs

Let’s have a look at your digital challenges together. What tools are you currently using? Are your processes optimal? How is the state of backups and security updates?

Digital Souvereignty is easily achived with Open Source software (which usually cost way less, too). Our division Safeserver offers hosting, operation and maintenance for countless Free and Open Source tools.

Try it now for 1 Euro - 30 days free!

Download transcript (.srt)
0:00

Welcome back to the deep dive, you know

0:02

Sometimes you run into these massive tech docs full of code snippets configs weird

0:07

terms like data structure server

0:09

It can feel pretty overwhelming definitely and today we're tackling one of those

0:14

redis

0:14

If you're building anything modern, especially apps needing speed real-time data or

0:20

even AI features

0:21

You're bumping into redis constantly. Absolutely. So our mission today is really

0:26

for you the learner

0:27

We want to give you a clear path like a beginner friendly way to understand what

0:31

redis actually is right and why developers call it the preferred

0:35

fastest option for data and

0:37

Importantly how this tool which has been around for a bit is now suddenly super

0:42

critical for things like gen AI

0:43

We'll cut through the jargon think of it as you know

0:45

You're a quick guide to understanding why basically every big platform out there

0:49

social media e-commerce

0:50

You name it uses redis to handle huge scale and stay fast

0:54

Okay, but before we jump in just a quick shout out to the supporter of this deep

0:57

dive safe server

0:59

They handle software hosting and support digital transformation work

1:03

So if you're aiming for that kind of speed we're talking about that sub millisecond

1:07

performance

1:08

You need solid infrastructure check them out. You can find more info at

1:12

www.safeserver.de

1:15

Okay, let's get started the official docs. They paint a big picture for redis

1:20

They say it's a cache and a data structure server and a vector query engine

1:25

That sounds ambitious like it's trying to be everything. Yeah, it does sound like a

1:30

lot and usually

1:31

You know when software tries to do everything there are trade-offs. Maybe it's not

1:35

great at any one thing, right? So what's the deal here?

1:38

What's the core idea? Well, the sources are pretty clear

1:41

The reason it can wear all those hats is because its entire design is just obsessed

1:45

with one thing raw speed

1:47

Performance, then how does it get that speed? What's the magic? It's mainly about

1:50

keeping the data in memory

1:51

Ram, that's the crucial bit. Okay, so not constantly reading from a slow desk like

1:57

a traditional database

1:58

Exactly by avoiding disk.io for most things and using really smart efficient ways

2:04

to organize that data in RAM

2:05

It gets incredibly low latency

2:07

We're talking like the source says sub millisecond often even faster like microseconds

2:13

for both reads and writes

2:16

Millisecond. Wow, that's hard to even picture faster than blinking

2:20

Pretty much and that explains why the sources call it battle tested at massive

2:25

scale

2:26

If you're handling millions of requests a second saving even tiny fractions of a

2:30

second adds up massively right and costs

2:33

User happiness. Oh, absolutely. You literally can't build some of these huge modern

2:38

web apps without

2:39

Something that fast handling key operations. So speed is king, but you also

2:44

mentioned versatility

2:45

It's not just fast. It does a lot precisely. That's where people often get the

2:49

wrong idea

2:49

They hear in memory key values store

2:52

I think it's just simple storage like putting a label on a box, but it's way more

2:55

sophisticated, right?

2:56

So it's how you use that speed. What are the big use cases where Redis is basically

3:00

the standard tool now according to the sources

3:02

Okay, let's break down. Maybe the four main ones first the obvious one caching

3:06

Yeah, it's bread and butter totally you store stuff. You need all the time user

3:10

profiles

3:11

Maybe parts of a web page leaderboards in Redis. So you don't keep hammering your

3:15

main slower database

3:16

It's like a really efficient gatekeeper for data and the sources mentioned it has

3:20

built-in smarts for that, right?

3:21

Yeah rules for kicking out old data setting timers on keys exactly eviction

3:26

policies key expiration

3:28

Crucial stuff for managing a cache properly. Otherwise, it just fills up with junk

3:33

makes sense. Okay, what's next second big one?

3:36

Distributed session management think about logging into a big website like an

3:40

online store during a huge sale. Okay. Yeah chaos, right?

3:44

You might hit different servers behind the scenes, but your login your shopping

3:48

cart

3:48

It all needs to be consistent and instant

3:51

Redis handles that session data across all those servers super fast without slowing

3:56

anything down

3:57

Ah, so it keeps track of who's logged in what's in their cart. No matter which

4:01

server answers the request

4:02

That's huge for making things feel smooth. Exactly. Then number three is more about

4:06

communication

4:07

Messaging and inner service communication like different parts of an application

4:12

talking to each other. Yeah, especially with micro services

4:15

Developers use Redis as a super fast central hub for things like background job queues

4:21

or

4:22

Sending messages between services using public subscribe cubs up right or even more

4:27

advanced streaming

4:28

When services need to coordinate or pass tasks quickly Redis is often that middleman

4:33

making sure nothing gets dropped

4:35

And it happens instantly got it fast reliable communication and the last one you

4:41

mentioned analytics

4:42

Yeah, real-time analytics. This is where that sub millisecond speed is absolutely

4:47

critical for the business

4:48

Like what kind of analytics think about personalization showing you recommendations

4:52

right as you're browsing or maybe more importantly things like fraud detection

4:56

Ah, okay. Like when you swipe a credit card exactly

4:59

The system needs to decide instantly if that transaction looks suspicious if it

5:03

takes half a second the fraud might have already happened

5:06

Redis can power that kind of instant check risk assessment to Wow. Okay, so caching

5:12

sessions messaging real-time analytics

5:14

That's a lot built on speed, but you said it's more than just a key value store

5:19

that data structure server part

5:21

That sounds key to the versatility. It really is. This is where it moves beyond

5:26

just storing simple values

5:27

Think of Redis not just as storage but as a toolbox

5:31

It gives developers pre-built highly optimized tools data structures to solve

5:36

common problems really efficiently

5:38

Okay, like specialized tools instead of just a generic hammer

5:40

Exactly, and the most basic tool the hammer everyone uses first is the string type

5:46

Simple key value storage perfect for caching basic objects, but also really good

5:50

for atomic counters counters like counting website hits

5:53

Yep, you can have millions of users hitting a page and Redis can increment a

5:57

counter instantly and safely with one simple command

5:59

INCR no complex database locks needed

6:03

Surprisingly powerful. Okay, so string is the basic. What are some of the more

6:07

specialized tools?

6:08

Well, a really popular one is the sorted set

6:11

Imagine a collection of items, but each item have a score and the whole collection

6:15

is always kept sorted by that score

6:16

Oh, okay. What would you use that for? The classic examples are real-time leaderboards

6:22

in games scores change

6:23

rankings update instantly or

6:26

Maybe less obviously for building really effective rate limiters to protect your

6:30

API's

6:30

You can track request counts per user within time windows very efficiently. Huh

6:35

belt right in that saves a ton of custom coding

6:38

What else is in the toolbox? There's the hash which is great for representing

6:42

objects

6:42

Like you could store a whole user profile name email user ID all under a single key

6:48

But a separate fields you can access individually keeps related data together

6:51

neatly. Okay strings sorted sets hashes

6:54

Any really unusual ones? Yeah, this is where it gets interesting. The source has

6:58

mentioned probabilistic structures

7:00

Like hyper log log hyper log log. Okay, that's a name. What on earth does that do?

7:05

It solves a really specific but important problem counting unique things when you

7:10

have a massive number of them like counting unique visitors to a huge

7:13

Website exactly imagine your say Twitter or Facebook and you want to know how many

7:19

distinct users logged in yesterday

7:21

You can't possibly store every single user ID in memory just to count them. You'd

7:27

run out of RAM instantly, right?

7:28

That would be astronomical. So hyper log log lets you estimate that unique count

7:33

Incredibly accurately with a tiny predictable error rate using a very very small

7:39

Fixed amount of memory. It's like a magic trick for big data counting. Wow

7:43

That's computational efficiency right there solving problems that seem impossible

7:48

Otherwise it is and Redis isn't even limited to these built-in types. The source is

7:53

mentioned

7:53

It has a modules API so developers can actually add completely new data structures

7:58

and commands if they need something super specialized

8:00

It's extensible. Okay, that flexibility is key and that adaptability probably

8:05

explains how it pivoted into this next area AI

8:08

Exactly. It seems like a leap right from caching and leaderboards to powering AI.

8:12

Yeah, you wouldn't immediately connect the dots

8:14

How does Redis fit into chat bots and gen AI? It fits in mainly through this

8:18

concept of a vector store. Vector store

8:20

Okay, unpack that a bit. So AI models, especially language models, don't really

8:25

understand words or images directly

8:27

They understand numbers data gets converted into these numerical arrays called

8:32

vector embeddings

8:33

Right embeddings capture the meaning or context of the data numerically precisely

8:37

and Redis with its speed and now specialized query

8:40

capabilities is becoming a go-to place to store and

8:43

More importantly search through millions or billions of these vector embeddings

8:49

incredibly quickly

8:50

And why is searching vectors so important for AI? It's critical for something

8:54

called retrieval augmented generation or RA

8:58

This is huge in gen AI right now

9:00

When you ask a chap bought a question

9:03

Especially about recent events or specific internal knowledge

9:06

It wasn't trained on the rx system needs to quickly find relevant information to

9:10

augment its response

9:11

It searches the vector store may be containing company documents recent news

9:16

Product info for vectors that are semantically similar to your questions vector

9:20

meaning it looks for documents

9:22

That means something similar even if the wording is different exactly and Redis

9:25

does that semantic similarity search

9:27

Super fast this lets the AI pull in relevant up-to-date context to give you a much

9:33

better more accurate answer

9:34

Than it could generate on its own. It's like giving the AI a fast access external

9:39

memory. Okay, that makes sense

9:40

Fast vector search for smarter AI

9:43

now the sources mentioned something really eye-catching here semantic caching and

9:48

Saving huge amounts of money. Yes

9:51

This is a massive practical benefit using tools like Redis lang cache for semantic

9:56

caching

9:56

The sources claim it can cut your large language model LLM cost by potentially up

10:01

to 90 percent 90 percent

10:03

How think about how expensive calling those big LLM API's like GPT-4 can be?

10:07

semantic caching stores the answers to previous prompts if a new prompt comes in

10:12

that is

10:12

Semantically identical meaning it's asking the same thing just maybe phrase

10:15

differently

10:16

Redis intercepts it

10:17

I'll check the cache

10:18

Finds the previous similar query and just returns the already computed answer

10:22

instantly you completely avoid making that expensive slow call to the LLM API

10:26

Wow, so it recognizes tell me about Redis speed is basically the same question as

10:31

how fast is Redis and just gives the cash

10:34

answer that's the idea over time with many users asking similar things the savings

10:39

can be

10:40

Enormous it tackles both latency and cost. Okay cutting latency and potentially 90%

10:46

off your AI bill

10:48

That makes Redis seem almost essential for any serious gen. AI project

10:52

It really shifts it from a nice-to-have performance booster to a core piece of the

10:56

economic puzzle for AI deployment

10:58

All right. So we know what it is why it's fast what it's used for even in cutting-edge

11:03

AI now the practical bit

11:04

How does someone especially beginner actually start using it because looking at the

11:08

source stocks Wow

11:10

There are pages on compiling it from scratch on Linux Mac OS specific commands. It

11:15

looks intent

11:16

It totally does look intimidating

11:17

And yeah, those build from source instructions are there for folks doing deep

11:21

custom production setups

11:22

But honestly for learning or even most standard deployments, you absolutely do not

11:27

need to do that. There are much much easier ways in

11:29

Okay, good. What's the simplest path? Probably the easiest is Redis cloud. It's the

11:33

official managed service

11:34

You basically click a few buttons on AWS Google Cloud or Azure and they set up

11:39

Manage and scale Redis for you zero infrastructure hassle. Okay cloud service makes

11:44

sense

11:45

What if you want to run it locally on your own machine just to play around then the

11:49

official Docker images are your best friend?

11:51

Seriously, it's usually one command in your terminal something like Docker run tan

11:55

DP six three seven nine point six three seven nine

11:58

Redis dot latest and that just starts a Redis server. Yep runs in the background

12:02

ready to go in seconds

12:03

Super simple way to get a local instance for development or testing nice. Okay, so

12:09

you've got it running via cloud or Docker

12:11

How do you actually talk to it? Is that complicated? Not at all. The simplest way

12:15

is the command line tool read is Clive

12:16

It connects you directly and what can you do there? You can literally just start

12:20

typing commands type ping and it should reply

12:23

Pong it's the classic test. Then you can try storing something set my key. Hello

12:28

world. It'll reply. Okay

12:30

Then type get my key and you get hello world back exactly or try that counter enter

12:35

the page visits

12:37

It'll reply integer one hit it again. You get integer two. You're directly

12:41

interacting with Redis seeing how fast and simple the core operations are

12:45

No code needed initially. They actually sounds surprisingly easy to experiment with

12:50

takes away the scary factor

12:52

It really does and if you prefer a visual tool over the can line the sources

12:56

mention Redis insight

12:58

Oh a GUI. Yeah a free graphical interface lets you browse your data see server

13:03

stats manage keys visually

13:05

Much more approachable for some folks and they've even added something called Redis

13:09

copilot into it recently copilot like an AI assistant

13:13

Yep

13:13

A natural language AI helper built right into the GUI to help you understand your

13:17

data or figure out Redis commands

13:19

Just are really thinking about usability for everyone. That's cool making powerful

13:23

tech accessible is key

13:25

Okay, so let's try and wrap this up key takeaways for our listener today. I'd say

13:30

one Redis is fundamentally about speed

13:33

Achieved by its in-memory design giving you that sub millisecond latency to it's

13:37

incredibly versatile acting is way more than just a cache

13:41

It's a data structure server powering sessions cues leaderboards and more right and

13:46

three

13:47

It's now a critical player in the AI space serving as a fast vector store for our

13:51

and offering huge cost savings via

13:53

semantic caching exactly fast flexible and increasingly essential for modern apps

13:59

from basic web functions to complex AI

14:01

So here's maybe a final thought for you the listener to chew on a provocation from

14:06

the expert. Okay. How about this?

14:07

We've seen Redis can handle caching session management message cues real-time

14:12

analytics and AI vector storage

14:14

Often all at the same time from one system with incredible speed

14:18

Yeah

14:18

So the question becomes instead of adding five different specialized tools or

14:21

databases to your application stack

14:23

Could you leverage the speed and versatility of Redis to actually simplify your

14:27

architecture?

14:28

Could using Redis more broadly reduce complexity rather than add to it?

14:32

That's a great question using one powerful fast tool for multiple jobs instead of juggling

14:38

many single-purpose ones

14:39

Definitely something to think about for designing efficient systems worth

14:42

considering. Okay, fantastic and one last

14:45

Thank you to our supporter for this deep dive safe server. Remember they handle

14:50

hosting and support digital transformation

14:52

Check them out for your high-speed application needs more information at

14:56

www.saveserver.de

14:58

time keep exploring and keep building fast

14:58

time keep exploring and keep building fast