DEV Community

Zhalok Rahman
Zhalok Rahman

Posted on Edited on

Redis Is Durable, You're Just Poor

What exactly is the difference between redis and any other typical databases and why exactly you can not use redis as your primary database?

Most of us think redis stores data into the memory and databases store data into the disk and thus redis is not durable and data will be wiped out if any crash takes place

But it turns out both the redis and typical databases primary store data into memory pages and writes logs into the disks which makes data recoverable in both
Then whats the difference exactly?

The difference lies not in how they store the data but how they evict the data from the memory
Since memory is a limited resource, therefore you can not fit all your data into the memory and thus you need to evict existing memory pages and remove some of the data from the memory when new data comes in and your memory is full

In redis the evicted page data is completely lost but in typical databases the evicted page is writen into the disk which makes its data persisted permanently
And this is exactly the reason why you can not use redis as your primary database

So moral of the story, you can not use redis as your primary database not because its not durable but its simply youre not rich enough to buy infinite amount of memory 🥲

Top comments (0)