engineering
Scaling Your SaaS with Redis
How to use Redis for sessions, rate limiting, job queues, and real-time features
Redis is the Swiss Army knife of SaaS infrastructure. AtendePraMim uses it for four distinct purposes.
Session Storage#
Iron-session encrypts the session into the cookie itself, so Redis isn't needed for session data. But we use Redis to track active sessions for revocation.
If you need to force-logout a user (password change, security incident), you need a server-side session store.
Rate Limiting#
Sliding window rate limiting with INCR and PEXPIRE. Each endpoint has its own key prefix and limits.
Job Queues#
BullMQ uses Redis as its backend. Emails, webhook deliveries, and scheduled tasks all go through the queue.
If Redis runs out of memory, BullMQ jobs stop processing. Monitor Redis memory in production.
SSE Real-Time#
Server-Sent Events use Redis pub/sub. When a notification is created, the server publishes to a channel, and all connected SSE clients receive the update.
Conclusion#
Redis handles four different use cases in our stack, each leveraging different Redis data structures. Keep an eye on memory usage and you'll have a reliable foundation for scale.