4 ms·
Can you replace Postgres with Redis (for some usecases)?
Hi there, I'm looking for a technical discussion. I'm looking for technical debate and I know what MySQL/PG and Redis are capable of. What I'm looking for is a debate where you disagree that following. I want to start with an analogy.
Gasoline cars vs. Electric cars We all know that you can use an electric battery to run a car.
But the thing is, when it comes to a gasoline car, even though it does literally have a battery, it’s not used for running the car. It uses batteries for starting the cars (generating an electric spark to light up the gas), A/C, audio systems, lights, sensors, locks, and so on but not for running the car. Instead, it relies on an internal combustion engine (ICE) to run the car.
It turns out, ICE cars are highly inefficient. Only 16% to 25% of the power that’s generated actually makes it into the wheels. On the other hand, electric vehicles provide about 90% power to the wheels! Further, EVs also have major and additional advantages when it comes to the environment, repair costs, and so on.
If you are looking from the First Principles, even though virtually most cars that are built even today are gasoline cars, the fundamental truth is that they use an inefficient system.
Now if you look at an electric car, it takes advantage of this inefficiency to build a new type of car. In this case, it simply gets rid of the complex and highly inefficient engine and replaces it with a large battery and a motor to directly spin the wheels.
------------- Now coming to the Databases...
In the traditional architecture, you have a primary database (Postgres, Mongo, etc.) and a secondary database, a.k.a, cache (e.g. Redis or Memcache). The primary DB is used to store all the data and support CRUD operations. The caching DB is used for caching, session storage, rate-limiting, IP-whitelisting, Pub/Sub, queuing, and many other things.
And if you think about it, when there is a cache-hit, we are practically using the secondary DB for part of the CRUD operations, but still not fully utilizing it as a primary database.
Does this remind you of the issue with gasoline cars? Just like they literally carry a battery to power numerous things except moving the car, the traditional architectures use things like Redis for everything else except as the main DB.
Do you see the similarities?
What if we use the First Principles thinking to do what the electric car did? Similar to how EVs got rid of the engine, what if we get rid of the slow and inefficient primary database and simply use the cache DB as the main database?
https://redislabs.com/blog/dbless-architecture-and-why-its-the-future/
- node-bayarea 5y agoHere is the article for your reference: https://redislabs.com/blog/dbless-architecture-and-why-its-the-future/ https://redislabs.com/blog/dbless-architecture-and-why-its-t...
- hardwaresofton 5y agoThey’re different databases that do different things with different features and different ways of laying out data. Redis functions as a cache, not a relational database — it’s not merely about speed of response. Do not use redis as your main database, it will require you to contort very painfully to so things that are normal to most apps. Maintaining Lua scripts instead of SQL queries is a bad idea. If this is an ad for redis labs then it’s a really bad one.
- node-bayarea 5y agoCan you give me a concrete example of were you'd contort if you were to use Redis versus Postgres? BTW, I'm just trying to really find an actual proof as opposed to mere anecdotal knowledge.
- hardwaresofton 5y agoAny sufficiently relational query... Try and generate dynamic reports on data, or an aggregation on an aggregation. The model subtly breaks even on simple questions like "I want to know all users who are currently logged in and the contents of their feed right now, with the last 5 messages they sent". You basically have to do multiple requests, MULTI, or write a lua script to get all this to happen in a transaction (so the state of the world is consistent). Such a request is trivial in relational databases, though performance of the query may not be.
- hardwaresofton 5y agoThey’re different databases that do different things with different features and different ways of laying out data. Redis functions as a cache, not a relational database — it’s not merely about speed of response. Do not use redis as your main database, it will require you to contort very painfully to so things that are normal to most apps. Maintaining Lua scripts instead of SQL queries is a bad idea. If this is an ad for redis labs then it’s a really bad one. If anything you should be going the other way, postgres is rocksolid and you could literally run redis as a postgres extension if you wanted. It is the more flexible, battle proven tool.