Pub/sub fan-out across instances

Pub/sub fan-out across instances distributes one published message to every API process with a matching active subscription. Each process independently forwards the message to its own local WebSocket hub, allowing a worker to notify customers without knowing which API instance holds their connections.

Minimal example

go
sub := client.PSubscribe(ctx, "user:*")
for msg := range sub.Channel() {
    userID := strings.TrimPrefix(msg.Channel, "user:")
    hub.SendToUser(userID, []byte(msg.Payload))
}

Learn this concept

Lesson 5.4 · Redis pattern subscriptions

Used in exercises

Exercise 5.5 · Per-user order event bridge Exercise 5.11 · Order location stream Exercise 5.15 · Per-user Redis replay log