Problem Statement
The SessionRegistry (xstreamroll-processing/src/session-registry.ts) is a per-process Map<string, StreamSession>. If multiple worker instances run, each has its own independent registry. The same stream could have active sessions across multiple workers, leading to duplicate event processing.
Evidence
// xstreamroll-processing/src/session-registry.ts:26
private readonly sessions = new Map<string, StreamSession>()
Impact
Duplicate event processing across workers. No distributed coordination for session ownership. Cannot horizontally scale the worker without data duplication.
Proposed Solution
- Use a distributed lock (Redis Redlock, PostgreSQL advisory lock) to claim stream ownership
- Before creating a session, acquire a lock on the stream ID
- Release the lock when the session is stopped/errored
- Other workers skip polls for locked streams
- Implement lock TTL with heartbeat renewal
Acceptance Criteria
File Map
xstreamroll-processing/src/session-registry.ts — add distributed locking
xstreamroll-processing/src/leader-election.ts — new coordination module
Labels: feature, infrastructure
Priority: Medium | Difficulty: Expert | Estimated Effort: 5d
Labels: feature,infrastructure
Priority: Medium | Difficulty: Expert | Estimated Effort: 5d
Backlog ID: REPO-033
Problem Statement
The SessionRegistry (
xstreamroll-processing/src/session-registry.ts) is a per-processMap<string, StreamSession>. If multiple worker instances run, each has its own independent registry. The same stream could have active sessions across multiple workers, leading to duplicate event processing.Evidence
Impact
Duplicate event processing across workers. No distributed coordination for session ownership. Cannot horizontally scale the worker without data duplication.
Proposed Solution
Acceptance Criteria
File Map
xstreamroll-processing/src/session-registry.ts— add distributed lockingxstreamroll-processing/src/leader-election.ts— new coordination moduleLabels: feature, infrastructure
Priority: Medium | Difficulty: Expert | Estimated Effort: 5d
Labels: feature,infrastructure
Priority: Medium | Difficulty: Expert | Estimated Effort: 5d
Backlog ID: REPO-033