#🧱 Building Block: Redis
#Overview
Redis (Remote Dictionary Server) is an open-source, in-memory data structure store, used as a database, cache, and message broker.
#Key Concepts
- In-Memory: All data is stored in RAM, providing sub-millisecond latency.
- Data Structures: Supports strings, hashes, lists, sets, sorted sets, bitmaps, etc.
- Persistence: Supports RDB (snapshots) and AOF (append-only file) for durability.
- Pub/Sub: Built-in messaging capabilities.
#Caching Strategies
- Cache-Aside: Application reads from cache, if miss, reads from DB and updates cache.
- Write-Through: Application writes to cache, and cache updates DB.
- Write-Behind: Application writes to cache, and cache updates DB asynchronously.
#When to Use
- Caching: Storing session data, product metadata, or rate limiting counters.
- Leaderboards: Using Sorted Sets.
- Real-time Messaging: Using Pub/Sub or Streams.
#Trade-offs
- Pros: Blazing fast, versatile data structures.
- Cons: Limited by memory size, data durability depends on configuration.