When to use PostgreSQL, when to use Redis, and when to use both together.
They solve different problems. Here's my decision framework.
1. ACID transactions - when data consistency is critical
2. Complex queries with JOINs
3. Long-term storage
4. Relational data with foreign keys
1. Caching frequently accessed data
2. Session storage
3. Real-time leaderboards and counters
4. Pub/sub for real-time features
We use both: PostgreSQL stores the canonical draft state. Redis caches active drafts and handles pub/sub for real-time updates. On reconnect, we reconcile Redis state with PostgreSQL.