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

Date Created:
Last Edited:
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

  1. Caching
    1. By storing common, repeatedly read objects in Redis, applications can retrieve data quickly and reduce load on the server. Use if:
      1. You have frequent reads and infrequent writes
      2. Data is shared between user sessions
  2. Session Stores
    1. Redis takes session stores to the next level by enhancing the user experience with very low latency
    2. A single cluster on Redis decently sized servers with sufficient RAM can manage thousands, if not millions, of sessions. Use if:
      1. You have frequent reads and writes
      2. Your data is isolated between sessions
  3. Counting and Gamification
    1. 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:
      1. Use if you need to count millions of simultaneous activities or objects - e.g., social media, customer support, e-commerce
  4. Metering and Rate-Limiting Calls to Legacy Severs
    1. See Redis Enterprise for Metering
  5. Other Use Cases
    1. Message Broker
    2. Data Structure Store
    3. 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

You must be logged in to post a comment!

Insert Math Markup

ESC
About Inserting Math Content
Display Style:

Embed News Content

ESC
About Embedding News Content

Embed Youtube Video

ESC
Embedding Youtube Videos

Embed TikTok Video

ESC
Embedding TikTok Videos

Embed X Post

ESC
Embedding X Posts

Embed Instagram Post

ESC
Embedding Instagram Posts

Insert Details Element

ESC

Example Output:

Summary Title
You will be able to insert content here after confirming the title of the <details> element.

Insert Table

ESC
Customization
Align:
Preview:

Insert Horizontal Rule

#000000

Preview:


Insert Chart

ESC

View Content At Different Sizes

ESC

Edit Style of Block Nodes

ESC

Edit the background color, default text color, margin, padding, and border of block nodes. Editable block nodes include paragraphs, headers, and lists.

#ffffff
#000000

Edit Selected Cells

Change the background color, vertical align, and borders of the cells in the current selection.

#ffffff
Vertical Align:
Border
#000000
Border Style:

Edit Table

ESC
Customization:
Align:

Upload Lexical State

ESC

Upload a .lexical file. If the file type matches the type of the current editor, then a preview will be shown below the file input.

Upload 3D Object

ESC

Upload Jupyter Notebook

ESC

Upload a Jupyter notebook and embed the resulting HTML in the text editor.

Insert Custom HTML

ESC

Edit Image Background Color

ESC
#ffffff

Insert Columns Layout

ESC
Column Type:

Select Code Language

ESC
Select Coding Language