I understand Redis can be used for caching, but I haven't used it before. If my database handles repeated queries fine at low traffic, when would Redis actually become useful?
How do you know when a web app needs Redis?
Answers
Start with a specific slow or overloaded part of the app, not a traffic number. If the database is keeping up, you can leave Redis out and check your queries and indexes first. Databases also have their own caches.
Redis starts looking useful when the same expensive query, API call, or computed result is requested repeatedly. You can store the result under a key, give it an expiration time, and reuse it instead of doing the work on every request. Think through how stale that result can be and what should happen when the cached value expires.
Reply to this answer
One web server? A small in-memory cache in the app might be enough. With several servers, each local cache is separate, so Redis can give them a shared place to reuse results.
For example, a summary assembled from several tables might be expensive to rebuild. If multiple servers need the same summary, a shared cached version can save each of them from repeating that work.
Reply to this answer
Caching isn't the only reason to use it. Shared login sessions and rate limit counters are other common uses, especially when requests can land on different servers. Expiring keys are handy when those values should disappear after a set time.
Reply to this answer
It can also back a simple queue for background jobs, or help with scheduling work across an app running on multiple servers. That's a different problem from making database reads faster, so evaluate it based on what the jobs need.
Keep an eye on memory and clean up finished tasks. Redis isn't a free bucket for an unlimited amount of job data.
Reply to this answer
There's no need to wait for a production problem before learning it. Try a small cache with an expiration time and see how reads behave when the value is present versus missing. Then decide whether the extra service solves a real problem in your app.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Ruvnexo-4t:
So the useful signal is repeated expensive work, not just having a lot of visitors?