I'm currently diving into Kubernetes and my lecturer mentioned using Redis as an in-memory database and PostgreSQL for persistent storage. I'm curious about why we can't just use one database for both functions? I feel like there's something I might be missing, as I've been grasping the core concepts pretty well so far!
3 Answers
You definitely can use PostgreSQL for everything, especially if you're just starting out. It's a solid general-purpose database that can handle most of your needs until your app scales up. At that point, you'd want Redis to cache frequent queries and manage user sessions since it retrieves data much faster from memory than disk.
The choice between Redis and PostgreSQL isn't about Kubernetes; it's more about the differences between the two databases. Redis is essentially a cache, designed for quick access—it stores data in memory, which can speed things up significantly. This means it can take the load off your disk I/O operations.
And just to add, Redis is a NoSQL key/value store while PostgreSQL is a relational database, which explains their different uses.
Got it! That helps clarify things a lot, thanks!
While Redis and PostgreSQL can technically replace each other, there are trade-offs. Redis is built for speed with in-memory data handling, but if it crashes, your data is lost. PostgreSQL, being more traditional, flushes data to disk, so you won’t lose it after a restart. Plus, Redis is often used for caching heavy database queries, which is useful as your app grows. Just bear in mind that a robust setup usually involves using both databases together, each serving its specific purpose.
Makes total sense! I think I was overthinking the performance aspect in my lecture.