TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Can Redis be used as a primary database? [video]

43 pointsby node-bayareaalmost 4 years ago

12 comments

bennyelvalmost 4 years ago
At my company the decision to do this was taken a few years ago. It’s one we regret every day and are expending a large amount of effort digging ourselves out of it.<p>A query engine is a very powerful and useful layer of abstraction that you end up having to recreate in your application code for every scenario where you need some data. It’s complicated, it’s hard to get right and it really slows you down.<p>My recommendation would be: don’t do it.
评论 #28021321 未加载
cbushkoalmost 4 years ago
If you have a datacenter of your own and several VMs, redis would be fine as a persistent store. I wouldn&#x27;t do it but it would be fine.<p>If you are in the cloud and have any hint of using kubernetes then DO NOT USE redis as a persistent store. The problem is that redis&#x27; master&#x2F;slave and replication pattern goes against the load balancing and Service objects of kubernetes. Redis was created in a time when it expected physical nodes to be available 24&#x2F;7 and is not designed for nodes to go away. It can handle it but it isn&#x27;t designed for it. Two different things.<p>Redis as a single pod and a cache works great. I would never use redis as a DB. We have DBs specifically designed to be DBs.
评论 #28019200 未加载
reidjsalmost 4 years ago
You can use an append only text file as a database, but that doesn’t mean it’s a great idea.
评论 #28015493 未加载
评论 #28017598 未加载
maxmcdalmost 4 years ago
My understanding is that Redis is fast because it writes and reads from memory. Postgres is slower because it ensures writes are persisted to disk before responding (among other reasons). So even if you use RDB and AOF with Redis, you can still readily lose data even after the database has confirmed it&#x27;s been written. The database can confirm a write and then crash before that write has been persisted to the AOF and RDB.<p>This is why I thought you wouldn&#x27;t want to run Redis as a primary database.
评论 #28014044 未加载
评论 #28014891 未加载
评论 #28015776 未加载
评论 #28023937 未加载
gunapologist99almost 4 years ago
In production, it may come back and haunt you later. There is very little in the way of real backup and recovery; you should think of the RDB and AOF files as a faster way to pre-populate the cache upon startup&#x2F;reboot&#x2F;migration rather than as a real production database. I&#x27;ve seen it used as a prod db many times, and while it can be made to work, it&#x27;s not really what it&#x27;s designed for.<p>The impedance match between redis and most programming language data structures is just really perfect; Redis supports all of the structures (arrays, maps, etc) that you&#x27;d expect, and a few you wouldn&#x27;t (bloom filters, for example).<p>Also, it has some really odd security choices and just generally a lack of focus on security at all. It didn&#x27;t even have any password at all for the first few years -- anyone could connect to it and just do whatever they wanted (and, in fact, you could even gain access to the OS!) It&#x27;s also pretty hard to start up securely in the cloud (by default, it binds to every interface instead of just localhost, or at least the last time I checked, although you <i>can</i> override this in the config.. just be careful about that, because this lack of emphasis on security seems to run through it.)<p>Again, as a very fast and flexible cache that supports a million different datatypes and has real big-O performance guarantees, it is superb.<p>But these days, if you want a primary production database, you should just default to postgresql, unless you already have a solid reason to choose something else. If you don&#x27;t know SQL, you should learn, but until you&#x27;re really ready to, just use an object relational mapper (ORM) for your programming language and that will turn postgresql basically into MongoDB or similar, but with all the power of SQL behind it.
评论 #28014477 未加载
ihucosalmost 4 years ago
TLDW. But I have counter.dev running with redis as the primary database. It just works. Of course you need consider carefully. One of the advantages I saw is that every query on the database has a documented complexity. I don&#x27;t need to hope for the database to run the query fast enough. It&#x27;s more transparent.
jbverschooralmost 4 years ago
You could also just use postgresql as your key-value store, which seems a much saner approach.
评论 #28024955 未加载
arthurcollealmost 4 years ago
Why would you want to?<p>I remember when I thought it was a great idea to use Elasticsearch as a primary database. The decision was a mistake
评论 #28013982 未加载
Zealotuxalmost 4 years ago
I&#x27;ve been thinking about replacing my Mongo database with persistent Redis but I&#x27;m torn on this, I don&#x27;t know what to expected long-term, what about migrations? It feels like once I&#x27;m going for a structure it&#x27;ll be very difficult to alter it, but maybe I&#x27;m wrong. I&#x27;m developing a real-time application (think Figma), and still cannot choose a solution with confidence.
评论 #28015781 未加载
junonalmost 4 years ago
This was the case at ZEIT (now Vercel). Then we migrated away from that due to a slew of issues I can&#x27;t recall at the moment.<p>We still used redis extensively but not as a persistence layer.
评论 #28017455 未加载
ransom1538almost 4 years ago
&quot;Can Redis be used as a primary database&quot;<p>IMHO, no. Unless! you can ensure your data is less than the size of memory. Redis must fit all the data into memory. If you run out of memory Redis doesn&#x27;t have great options (besides buy more memory). In my mind a primary database handles the complexities&#x2F;speed of pulling data from a disk, manipulating data in memory and scales with more disk. Redis manipulates data in memory only.<p>Redis is rad for specific group of problems.
评论 #28015182 未加载
评论 #28023951 未加载
halifaxbeardalmost 4 years ago
Yes. Should you?<p>It depends, like everything.