Redis Stream Coordinator
Design docs

Coordinator Architecture

Overview

Redis Stream Coordinator separates the control plane from the data plane. The coordinator decides which member should own each Redis Stream shard. Consumer applications still perform message reads, business handling, retry, DLQ, and acknowledgement.

Responsibilities

Coordinator Server

Consumer Module

Producer Module

Redis Metadata Store

Control-Plane Flow

sequenceDiagram
    participant M as Consumer Member
    participant C as Coordinator
    participant S as State Store
    participant R as Redis Stream

    M->>C: Heartbeat(memberId, ownedShards, revokingShards, capacity)
    C->>S: Acquire Redis mutex
    C->>S: Read latest group metadata hash
    C->>C: Validate ownership report
    C->>C: Expire stale members if needed
    C->>C: Recalculate target assignment if metadata changed
    C->>S: Save with storeRevision check
    C->>S: Release Redis mutex
    C-->>M: HeartbeatResponse(assignment, epochs, fencing status)
    M->>R: Start/stop reads according to assigned shards

Event Loop

The coordinator event loop runs periodically and performs operational reconciliation:

The event loop uses the same Redis mutex and store revision boundary as heartbeat and admin requests. If another coordinator instance updates the same group first, the losing instance reloads or skips that group and the next tick continues reconciliation.

State Serialization

Metadata state changes are serialized by the Redis mutex and store revision CAS for the group. Users should not need to perfectly enforce replicas=1, Kubernetes Recreate, or blue/green active-passive behavior before trying the project.

State-changing requests follow this order:

  1. acquire Redis mutex,
  2. read the latest group metadata hash,
  3. validate and process the request,
  4. save with store revision compare-and-set,
  5. release mutex,
  6. return a response derived from the written metadata.

Store revision checks remain as a final stale-write guard.

Rebalance Model

Rebalance is target-assignment driven:

  1. Coordinator computes the desired owner for each shard.
  2. Members receive target assignment through heartbeat responses.
  3. Members stop work for shards that are no longer assigned.
  4. Members report revoke acknowledgement.
  5. Coordinator makes the shard assignable to the next target member.
  6. The next member starts work and reports ownership.

This avoids a global stop-the-world barrier and keeps unaffected members consuming.

Failure Handling

Failure Coordinator Behavior Member Behavior
Member heartbeat timeout Mark member EXPIRED, fence its ownership, recalculate assignment Rejoin with full heartbeat if it comes back
Stale ownership report Reject or fence the member depending on severity Stop reads and rejoin
Coordinator restart Reload state from the Redis metadata key and continue from stored epochs Continue heartbeating
Redis metadata outage Fail control-plane writes and report degraded health Keep local policy or stop based on application risk policy
Resharding provisioning failure Keep migration in failed/preparing state and expose it through monitoring Continue reading existing readable shard set

Consistency Boundaries

Deployment Shape

The recommended deployment is: