Video

Redis in 30 Seconds: Caching and Background Jobs

Is your Rails app slowing down under heavy traffic? Redis is usually the first
thing teams reach for — and it solves two different problems.

WHAT REDIS IS
An in-memory data store. Data lives in RAM, so reads come back in
milliseconds. It's a key-value store, not just a cache.

1) CACHING
Your app checks Redis first. On a miss, it queries the database and writes the
result into Redis. The next request reads straight from memory — no database
round trip. Fewer repeated queries, faster responses.

2) BACKGROUND JOBS
A user submits a form. Instead of blocking the request while an email sends,
the app pushes a job into a Redis queue and responds immediately. A Sidekiq
worker pulls the job from Redis and runs it separately.

Worth being precise about: Redis stores and coordinates the jobs. Sidekiq
is what actually executes them. Redis is the queue, not the worker.

And it isn't automatic — caching needs expiry strategy, and a cache that
serves stale data is worse than one more query.


Watch on YouTube

Back to videos