My post on Redis blew up. And the replies were flooded with devs all saying the same thing:
Stop telling people to cache slow queries. Fix your database itself.
They are 100% correct.
Let's be crystal clear, because this is the golden rule:
Your database is the one place your data must be right. That's it. Your top priority is, and always will be, a healthy database.
Before you ever type SET in Redis, you run your database's query analyzer.
You fix your inefficient queries. You add your indexes. You optimize your queries.
A 3-second query is not a caching problem. It's an indexing problem. Full stop.
So, the real question is:
My database is now fast. My queries are 50ms. Why do I even need Redis?
This is the real conversation.
You don't use Redis to fix a slow database. You use Redis to protect a healthy one.
Here are the real pro use cases, assuming your DB is already in good shape:
1- Caching for Frequency, Not Slowness
- Your 50ms query is fast. But your homepage gets 1,000 requests per second.
- That's 1,000 hits to your DB every second for the exact same data.
- This isn't a speed problem. It's a load problem.
- You cache this result in Redis for 10 seconds. You just turned 10,000 database hits into 1.
- You're not hiding a slow query. You're protecting your DB from repetitive, unnecessary work.
2- Doing the Jobs Your SQL Database Hates
- Your SQL database is a fortress. It's built for durability and transactions.
- It is terrible at certain high-speed, volatile jobs.
- You use Redis for those jobs.
- Want a real-time Top 10 leaderboard?
- Don't run ORDER BY score DESC on your (example => 20-million-row users table) . That's insane.
- Use a Redis Sorted Set. It's instant.
- Want a background job queue for sending emails?
- Don't use your jobs table as a queue. Locking rows for dequeuing is slow and complex.
- Use a Redis List. It's a perfect, atomic queue (LPUSH / BRPOP).
- Want a real-time chat or notification system?
- Don't poll your database.
- Use Redis Pub/Sub. It's a lightweight, high-speed message broker.
- Want to store temporary user sessions?
- Don't hammer your users table with UPDATE last_seen_at.
- Use a Redis Hash with a 24-hour expiration.
The rule is simple.
Fix your database first. Always.
Then, use Redis to do all the high-speed jobs your database was never built to do.
A huge thanks to everyone in the replies and quotes who called this out.
@gimbakakanda The interesting thing is that, those pontificating about the North are akin to Europeans asking Africans if they have electricity. How many have been to the North?
@legend_082@redcap_blondie It is disheartening to think that the only thing you seem to be concerned about is voting for APC when they come back, based on your beliefs. It's troubling to consider how someone can remain unmoved in the face of such a critical issue.
@legend_082@redcap_blondie It is evident that those who have watched the video have a basic understanding of what is occurring and what is being requested, despite the fact that the individuals were speaking in Hausa rather than English. However, we must not lose sight of the larger issue at hand.
@redcap_blondie It is evident that those who have watched the video have a basic understanding of what is occurring and what is being requested, despite the fact that the individuals were speaking in Hausa rather than English. However, we must not lose sight of the larger issue at hand.
Whether you're a food vendor, clothes vendor, or cruise vendor. At some point in your business, you'd need to get a business website! It's all part of growth. Join this webinar to learn how‼️
link: https://t.co/kuiDEtkTya
please retweet!