Skip to main content

Redis

Redis serves multiple roles in Tracera, handling everything from caching to real-time message broadcasting.

Roles

RoleData StructurePurpose
Price CacheString/HashLatest prices for instant reads
Pub/SubChannelsBroadcasting price and volatility updates
Volatility RankingsSorted SetsRanked list of most volatile items
Session StoreStringSCS session data with TTL
Rate LimitingString (counter)Per-IP request counters with TTL
Magic Link TokensStringOne-time-use tokens with 10-minute TTL
Import CooldownStringPer-user portfolio import cooldown

Price Caching

On every ingestion cycle, the latest price for each item is cached in Redis:
Key:   price:latest:{item_id}
Value: {price_json}
TTL:   Refreshed on each ingestion cycle
This enables sub-millisecond price lookups without hitting TimescaleDB.

Pub/Sub Channels

Price and volatility updates are published to Redis channels for real-time delivery:
Channel: prices     — new price data from ingestion
Channel: volatility — recomputed volatility metrics
The WebSocket hub subscribes to these channels and fans out updates to connected clients.

Volatility Rankings

The most volatile items are stored in a Redis sorted set:
Key:    rankings:volatile
Member: {item_id}
Score:  {volatility_score}
Sorted sets enable O(log N) ranked queries — perfect for “most volatile items” leaderboards.

Session Storage

SCS stores session data in Redis with automatic TTL:
Key:   session:{session_id}
Value: {session_data}
TTL:   72 hours (configurable)

Configuration

REDIS_HOST=localhost    # Redis host
REDIS_PORT=6379         # Redis port
REDIS_PASSWORD=         # Optional password
REDIS_DB=0              # Database index (0-15)

Connection Pooling

The backend uses pooled Redis connections shared across cache reads, pub/sub, and session lookups to avoid connection overhead.