Redis usage patterns for the restaurant platform — Pub/Sub channels, Streams with consumer groups, outbox pattern, rate limiting, token blacklist, and caching strategies. Trigger: When working on Redis integration, Pub/Sub, Streams, outbox events, rate limiting, token blacklist, or cache invalidation.
| Channel Pattern | Purpose |
|---|---|
branch:{id}:waiters | All waiters in a branch |
branch:{id}:kitchen | Kitchen staff in a branch |
branch:{id}:admin | Admins in a branch |
session:{id}:diners | Diners in a dining session |
sector:{id}:waiters | Waiters assigned to a sector |
Message format (JSON):
{
"type": "EVENT_TYPE",
"tenant_id": "uuid",
"branch_id": "uuid",
"payload": {},
"timestamp": "ISO-8601"
}
| Parameter | Value |
|---|---|
| Delivery guarantee | At-least-once |
| Max retries | 3 → then DLQ |
| Pending claim threshold | 30s (covers crashed consumers) |
| On restart | Process pending messages first |
Table: outbox_events
| Column | Type | Notes |
|---|---|---|
id | UUID | PK |
tenant_id | UUID | Tenant scope |
event_type | string | Event discriminator |
payload | JSONB | Event data |
status | enum | PENDING → PROCESSING → PUBLISHED |
created_at | timestamp | Insertion time |
processed_at | timestamp | Nullable, set on publish |
attempts | int | Max 5 |
Flow:
PENDING, sets PROCESSINGPUBLISHED on success| Parameter | Value |
|---|---|
| Algorithm | Sliding window |
| Key pattern | rate_limit:{connection_id} |
| Max tracked connections | 2,000 |
| Eviction | Oldest 10% at limit |
| Parameter | Value |
|---|---|
| Key pattern | blacklist:{token_jti} |
| TTL | Token's remaining lifetime |
| Fail mode | Fail-closed — Redis unreachable → ALL tokens rejected |
| Cache | TTL | Max Entries | Invalidation |
|---|---|---|---|
| Sector cache | 60s | 1,000 | TTL expiry |
| Menu cache | 5min | — | On product/category change |
| Cross-reaction cache | 5min | — | TTL expiry |