Redis & Queues
Redis 7 serves as the backbone for BullMQ job queues, rate limiting counters, and optional caching in UniPulse.
Redis Roles
| Role | Description |
|---|---|
| BullMQ job store | Persists all 27 queue jobs, states, and metadata |
| Rate limiting | Stores request counters for authLimiter and aiLimiter |
| Token refresh tracking | Tracks which social tokens are being refreshed to prevent duplicates |
| Session caching | Optional session data caching |
Connection
// apps/api/src/lib/redis.ts
import Redis from 'ioredis';
export const redis = new Redis(process.env.REDIS_URL, {
maxRetriesPerRequest: null, // Required by BullMQ
enableReadyCheck: false,
});
| Environment | Default URL |
|---|---|
| Development | redis://localhost:6379 |
| Production | redis://redis:6379 (Docker service name) |
BullMQ Queue Configuration
Standard Queue Pattern
// apps/api/src/queues/publish.queue.ts
import { Queue } from 'bullmq';
import { redis } from '../lib/redis';
export const publishQueue = new Queue('publish', {
connection: redis,
defaultJobOptions: {
attempts: 3,
backoff: { type: 'exponential', delay: 5000 },
removeOnComplete: 100, // Keep last 100 completed
removeOnFail: 500, // Keep last 500 failed
},
});
Default Job Options
| Option | Value | Purpose |
|---|---|---|
attempts | 3 | Number of retry attempts |
backoff.type | exponential | Exponential backoff between retries |
backoff.delay | 5000 | Base delay in ms (5s, 10s, 20s) |
removeOnComplete | 100 | Keep last N completed jobs for monitoring |
removeOnFail | 500 | Keep last N failed jobs for debugging |
Queue-Specific Overrides
| Queue | Attempts | Backoff Delay | Notes |
|---|---|---|---|
publish | 3 | 5000ms | Critical path -- must succeed |
token-refresh | 5 | 10000ms | More retries for token refresh |
analytics-sync | 3 | 5000ms | Standard |
ice-process | 3 | 3000ms | Lower delay for conversation responsiveness |
ab-test-eval | 1 | - | One-shot evaluation |
ice-experiment-eval | 1 | - | One-shot evaluation |
All 27 Queues
| Queue Name | Worker Concurrency | Job Type |
|---|---|---|
ab-test-eval | 2 | One-shot |
ad-sync | 3 | Periodic |
ai-suggestions | 5 | Background |
analytics-sync | 5 | Periodic + on-demand |
audience-sync | 3 | Event-driven |
benchmark-compute | 2 | Periodic |
calendar-generate | 3 | On-demand |
competitor-scan | 2 | Periodic |
ecommerce-sync | 3 | Webhook + periodic |
ice-escalation | 5 | Event-driven |
ice-experiment-eval | 2 | One-shot |
ice-process | 10 | Real-time (high priority) |
order-sync | 3 | Webhook + periodic |
payment-webhook | 5 | Webhook |
post-classify | 5 | After post creation |
prediction-eval | 3 | After analytics sync |
publish | 5 | On-demand |
revenue-attribution | 3 | After order sync |
schedule | 5 | Cron-driven |
segment-eval | 3 | After audience update |
token-refresh | 3 | Proactive (before expiry) |
trend-scan | 2 | Periodic |
webhook-process | 5 | Webhook |
workflow-engine | 5 | Event-driven |
workspace-classify | 2 | Periodic |
Redis Memory Management
Key Patterns in Redis
| Pattern | Purpose |
|---|---|
bull:{queue}:* | BullMQ queue data |
bull:{queue}:id | Job counter |
bull:{queue}:waiting | Waiting job list |
bull:{queue}:active | Active jobs |
bull:{queue}:completed | Completed jobs |
bull:{queue}:failed | Failed jobs |
rate:{limiter}:{key} | Rate limiting counters |
Memory Monitoring
# Check Redis memory usage
redis-cli INFO memory
# Monitor real-time commands
redis-cli MONITOR
# List all queue keys
redis-cli KEYS "bull:*" | head -20
# Check specific queue size
redis-cli LLEN "bull:publish:waiting"
Redis Persistence
In production, ensure Redis has persistence configured (RDB snapshots or AOF logging) so that queued jobs survive Redis restarts. The redis:7-alpine image has RDB persistence enabled by default.
Monitoring
| Method | Description |
|---|---|
| Admin API endpoints | Queue job counts (waiting, active, completed, failed) |
| Control Center dashboard | Visual queue health monitoring |
| Redis CLI | Direct inspection of queue data |
| BullMQ events | Worker event handlers for logging |
Cross-Reference
- Queue System -- complete queue reference with code patterns
- Docker -- Redis container configuration
- Backend Local Setup -- Redis in development
- Environment Variables -- REDIS_URL