What is Redis and how is it used in Node.js applications?
Why Interviewers Ask This
This question targets practical, hands-on experience with Node.js. Interviewers want to see if you've worked with these concepts in real projects, not just read about them. Strong answers include concrete examples.
Answer
Redis (Remote Dictionary Server) is an in-memory data structure store used as a database, cache, message broker, and session store. It is extremely fast (microsecond latency) because all data lives in RAM. Common Node.js use cases: (1) Caching: store expensive database query results with TTL — await client.setEx("users:list", 3600, JSON.stringify(users));; (2) Session storage: use connect-redis with express-session for distributed sessions; (3) Rate limiting: atomic increment operations make Redis ideal for counting requests per window; (4) Pub/Sub: real-time messaging between services; (5) Job queues: BullMQ uses Redis for reliable background job processing; (6) Leaderboards: sorted sets for real-time rankings. Node.js clients: ioredis (feature-rich, supports clusters and Sentinel) and redis (official client). Always set expiry (TTL) on cached keys to avoid stale data accumulation.
Common Mistake
Many candidates answer correctly but can't explain the 'why'. Always be prepared to justify your answer with a concrete example or use case from your Node.js experience.
Previous
What is the difference between SQL and NoSQL databases and when to use each with Node.js?
Next
What is GraphQL and how does it differ from REST in Node.js?