TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Looking for a technical debate: Why MOT use Redis as a primary DB?

5 点作者 node-bayarea将近 4 年前
I&#x27;m looking for technical debate and I know what MySQL&#x2F;PG and Redis are capable of. What I&#x27;m looking for is a debate where you *disagree* that following. I want to start with an analogy.<p>Gasoline cars vs. Electric cars We all know that you can use an electric battery to run a car.<p>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&#x2F;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.<p>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.<p>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.<p>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.<p>------------- Now coming to the Databases...<p>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&#x2F;Sub, queuing, and many other things.<p>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.<p>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.<p>Do you see the similarities?<p>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?<p>https:&#x2F;&#x2F;redislabs.com&#x2F;blog&#x2F;dbless-architecture-and-why-its-the-future&#x2F;

7 条评论

al2o3cr将近 4 年前
One word: rollbacks<p>That&#x27;s not really much of a &quot;debate&quot;, but then again neither is &quot;you totally don&#x27;t need that feature we don&#x27;t implement&quot; from the marketing department :P<p><a href="https:&#x2F;&#x2F;redislabs.com&#x2F;blog&#x2F;you-dont-need-transaction-rollbacks-in-redis&#x2F;" rel="nofollow">https:&#x2F;&#x2F;redislabs.com&#x2F;blog&#x2F;you-dont-need-transaction-rollbac...</a>
评论 #27789307 未加载
评论 #27785911 未加载
injb将近 4 年前
Generally the idea of caches is that they contain a small subset of all your data in a type of storage that&#x27;s more expensive, but faster. The extra complexity of primary databases is largely down to the fact that they have to use disk storage.<p>BTW, you&#x27;re way off the mark with the numbers in your car analogy! I know the precise numbers are not the point, but it&#x27;s really not 90% vs 25% efficiency. The oft-quoted figure of 25% efficiency refers to <i>thermal</i> efficiency. It&#x27;s a measure not of how much power is wasted by the car, but how much of the <i>energy</i> in the fuel is turned into useful work. To compare electric cars, you have to consider how the electricity is generated. It&#x27;s mostly generated by burning fossil fuels. It&#x27;s more efficient than petrol cars because it&#x27;s done at such a large scale, but it&#x27;s not 90%. It&#x27;s more like 40-50% afaik.
评论 #27789978 未加载
softwaredoug将近 4 年前
What you&#x27;re describing sounds a lot of why NoSQL databases came into being. A cache is usually very fast at a very narrow data problem. Caches are almost always flat bits of data with no structure. They&#x27;re also eventually consistent. They are purpose built data structures for a very small piece of the problem done over and over.<p>An RDMS is a centralized, consistent source of truth, with more normalized data, that can answer most questions with reasonable performance.<p>When you remove the RDMS, what happens?<p>- You lose the ability to answer ad-hoc relational questions (what stuff does the user own? And in those things, which of them is located in Chicago?). This means building a new feature means building a new &quot;cache&quot; aka a brand new data structure _just for this one use case_ that might be a one-off<p>- You lose a centralized PoV on your data consistency. One view of the cache says the user&#x27;s item is in Chicago. Another says its en route to LA from Chicago. How do you resolve these conflicts? Are you going to build your own consistency systems? Based on what exactly? Now you&#x27;ve essentially built a new kind of distributed database.<p>- Much of the time we don&#x27;t need caches. If you always have to bust your cache, the cost of constantly rebuilding a cache, just to throw it away, can greatly exceed any value from that cache. Most people can just read from the RDMS and get what they need for 90% of the use cases in most apps.<p>BTW I used Redis as a primary DB for a few years for Quepid. You can read the full story here<p><a href="https:&#x2F;&#x2F;www.slideshare.net&#x2F;AllThingsOpen&#x2F;stop-worrying-love-the-sql-a-case-study" rel="nofollow">https:&#x2F;&#x2F;www.slideshare.net&#x2F;AllThingsOpen&#x2F;stop-worrying-love-...</a><p>Long story short, it was fine, but Redis didn&#x27;t allow for much structure. There was a lot of &quot;logical&quot; relational data modeled very awkwardly. It made it hard to extend beyond the original data model.
node-bayarea将近 4 年前
<a href="https:&#x2F;&#x2F;redislabs.com&#x2F;blog&#x2F;dbless-architecture-and-why-its-the-future&#x2F;" rel="nofollow">https:&#x2F;&#x2F;redislabs.com&#x2F;blog&#x2F;dbless-architecture-and-why-its-t...</a>
altdataseller将近 4 年前
Redis, at least the early versions (haven&#x27;t upgraded since 2018) don&#x27;t deal with bloat very well. Which means if you keep adding&#x2F;deleting items, the amount of memory it will use up could easily be twice what it actually would be if you just dumped everything to a file.
评论 #27785936 未加载
billconan将近 4 年前
can you fit all data in memory?
评论 #27785731 未加载
yuppie_scum将近 4 年前
You probably want Clickhouse