Why Not Use PostgreSQL As A Cache?
Why not simplify backend - remove the need for memcache / redis - and instead use SQL table as a cache
What I'm Trying to Figure Out
Why not just use PostgreSQL or another SQL server as cache instead of adding a Redis or Memcached sever? Removing the extra database would be one less thing to configure, one less thing that could cause errors, one less I/O connection to establish, and I think using a Hash Index on a column would provide an O(1) lookup time - just like a dedicated cache server, so why not just use an SQL database as cache?
Notes
Source of notes is reading peoples' opinions online + Why Your SQL Server Needs Redis, Roshan Kumar - which can be found on the Redis website
- Redis will decrease the load on your server.
- Redis can help scale applications with limited effort and cost
- Redis is extremely lightweight - it can perform many more operations per second (100-1000 times more) with fewer computational resources when compared to SQL server
- Redis allows you to store data in whatever format you require (I can't think of any format that I would need that I can't store in SQL)
- Look into Redis Geospatial Indices
Redis Use Cases
- Caching
- By storing common, repeatedly read objects in Redis, applications can retrieve data quickly and reduce load on the server. Use if:
- You have frequent reads and infrequent writes
- Data is shared between user sessions
- Session Stores
- Redis takes session stores to the next level by enhancing the user experience with very low latency
- A single cluster on Redis
decently sized servers
with sufficient RAM can manage thousands, if not millions, of sessions. Use if: - You have frequent reads and writes
- Your data is isolated between sessions
- Counting and Gamification
- Leaderboards, dashboards, polls, messages, counters, and other real time aggregators require constant processing and communication with end users. Redis can easily support real time gamification platforms:
- Use if you need to count millions of simultaneous activities or objects - e.g., social media, customer support, e-commerce
- Metering and Rate-Limiting Calls to Legacy Severs
- Other Use Cases
- Message Broker
- Data Structure Store
- Temporary Data Store
Summary
Essentially, Redis enables you to get your data closer and faster to your end user. If you flip this around, Redis also helps you collect data more quickly from your end users. With RAM’s increasing affordability and the persistence features of Redis, more and more developers are using Redis as a primary database for both transactions and analytics.
What I Figured Out
- It's probably fine to keep Redis as it is now
- It's utility as a session store is the main thing that keeps me wanting to continue using Redis and not try to create a cache-like table in PostgreSQL
- I interact with the session data too much to continue touching the database I think
- It is cheap for what it gets you
The main reason I was considering this idea was that there was frustration with one Redis storage that I can't figure out why key-value pairs continue to be deleted.
Comments
There are currently no comments to show for this article.