Redis
Redis provides lowest latency for high-throughput scenarios where some durability trade-offs are acceptable.
Why Redis
Section titled “Why Redis”| Strength | Benefit |
|---|---|
| Sub-millisecond latency | Fastest event writes |
| Horizontal scaling | Redis Cluster for partitioning |
| Memory-first | No disk I/O on hot path |
| Pub/Sub native | Can double as event bus |
Trade-offs
Section titled “Trade-offs”| Concern | Consideration |
|---|---|
| Durability | Configurable (AOF, RDB, none) |
| Memory cost | Events live in RAM until evicted |
| Complexity | Cluster mode adds operational overhead |
Configuration
Section titled “Configuration”[storage]backend = "redis"
[storage.redis]url = "redis://localhost:6379"# For cluster mode# urls = ["redis://node1:6379", "redis://node2:6379"]Environment Variables
Section titled “Environment Variables”export REDIS_URL="redis://localhost:6379"export STORAGE_BACKEND="redis"Data Model
Section titled “Data Model”Redis stores events in sorted sets keyed by aggregate:
events:{domain}:{edition}:{root} └── ZADD with sequence as score └── Member: serialized event
positions:{handler}:{domain}:{edition}:{root} └── String: sequence number
snapshots:{domain}:{edition}:{root} └── Hash: { sequence, state }Durability Options
Section titled “Durability Options”AOF (Append-Only File)
Section titled “AOF (Append-Only File)”appendonly yesappendfsync everysec # fsync every second (default)# appendfsync always # fsync every write (slower, safest)RDB Snapshots
Section titled “RDB Snapshots”save 900 1 # Save if 1 key changed in 900 secondssave 300 10 # Save if 10 keys changed in 300 secondssave 60 10000 # Save if 10000 keys changed in 60 secondsProduction Recommendation
Section titled “Production Recommendation”Use both AOF and RDB for durability with fast recovery:
appendonly yesappendfsync everysecsave 900 1Helm Deployment
Section titled “Helm Deployment”storage: backend: redis
redis: enabled: true host: redis.cache.svc.cluster.local port: 6379 credentials: secretName: redis-credentials passwordKey: passwordTesting
Section titled “Testing”# Run Redis tests (requires testcontainers)cargo test --test storage_redis --features redis
# Requires podman socketsystemctl --user start podman.socketWhen to Use Redis
Section titled “When to Use Redis”- Gaming/real-time — Latency-critical applications
- Ephemeral data — Acceptable to lose on crash
- Caching layer — In front of durable storage
- Development — Fast iteration without disk I/O
Next Steps
Section titled “Next Steps”- PostgreSQL — Durable alternative
- Testcontainers — Container-based testing