Redis › Streams

How would you design a robust event sourcing system using Redis Streams as the primary event log?

Advanced

Answer

You would use a single stream, or several streams organized by event category, as the authoritative append only log of every event that has occurred, use consumer groups to let different services independently process events relevant to them, ensure consumers handle messages idempotently in case of redelivery, and consider periodically trimming very old entries once they are no longer needed for replay purposes.
XADD events '*' type 'OrderCreated' orderId '1001'
XGROUP CREATE events analytics_service '$'
XGROUP CREATE events email_service '$'
Real-world example An e-commerce platform uses a single events stream as its source of truth for everything that happens, with separate consumer groups for their analytics service and their email notification service, each independently processing the exact same underlying events at their own pace.

Common follow-ups: How do you decide when it is safe to trim old entries from an event sourcing stream?;What idempotency strategies help handle the rare case of a message being processed more than once?