Skip to content

FEAT: Issue #5 — Redis Pub/Sub Integration for Real-Time Broadcasting - #11

Merged
Verifieddanny merged 1 commit into
mainfrom
dev
Jun 9, 2026
Merged

Verifieddanny merged 1 commit into
mainfrom
dev

Conversation

@Verifieddanny

Copy link
Copy Markdown
Contributor

Overview:
Connects Redis pub/sub to WebSocket hub for multi-instance broadcasting. Enables horizontal scaling and real-time leaderboard updates across all backend replicas.

Implementation:

  • internal/ws/pubsub.go: Redis pub/sub client layer

    • NewPubSub(): connects to Redis with fallback
    • Publish(): sends message to Redis channel
    • PublishLeaderboardUpdate(): broadcasts to all instances
    • Subscribe(): listens and forwards to local WebSocket hub
  • Updated handlers: all broadcasts now dual-channel

    • CreateProposal: publishes to intent:{id} channel
    • SelectWinner: publishes winner selection
    • SettleExecution: publishes settlement
  • Updated server initialization

    • Server.New() initializes Redis pub/sub on startup
    • Server.Shutdown() closes Redis connection gracefully

Architecture:
Agent submits proposal
├→ h.hub.Broadcast() (local WebSocket clients)
└→ h.pubsub.Publish() (Redis pub/sub channel)
↓
Other backend instances receive & forward
to their local WebSocket subscribers

Result: All dApp users see real-time updates

Scaling:

  • Multiple backend replicas share single Redis instance
  • No message loss (Redis is source of truth)
  • No data inconsistency (all clients get same update)
  • Ready for horizontal deployment (K8s, docker-compose)

Testing:
✓ Server starts with Redis connection
✓ Proposals broadcast to local + Redis
✓ Build successful (no compilation errors)

Next:

close #5

**Overview:**
Connects Redis pub/sub to WebSocket hub for multi-instance broadcasting.
Enables horizontal scaling and real-time leaderboard updates across all backend replicas.

**Implementation:**
- internal/ws/pubsub.go: Redis pub/sub client layer
  - NewPubSub(): connects to Redis with fallback
  - Publish(): sends message to Redis channel
  - PublishLeaderboardUpdate(): broadcasts to all instances
  - Subscribe(): listens and forwards to local WebSocket hub

- Updated handlers: all broadcasts now dual-channel
  - CreateProposal: publishes to intent:{id} channel
  - SelectWinner: publishes winner selection
  - SettleExecution: publishes settlement

- Updated server initialization
  - Server.New() initializes Redis pub/sub on startup
  - Server.Shutdown() closes Redis connection gracefully

**Architecture:**
Agent submits proposal
  ├→ h.hub.Broadcast()        (local WebSocket clients)
  └→ h.pubsub.Publish()       (Redis pub/sub channel)
       ↓
  Other backend instances receive & forward
  to their local WebSocket subscribers

Result: All dApp users see real-time updates

**Scaling:**
- Multiple backend replicas share single Redis instance
- No message loss (Redis is source of truth)
- No data inconsistency (all clients get same update)
- Ready for horizontal deployment (K8s, docker-compose)

**Testing:**
✓ Server starts with Redis connection
✓ Proposals broadcast to local + Redis
✓ Build successful (no compilation errors)

**Next:**
- Issue #6: Scoring engine (deterministic proposal selection)
- Issue #7: Execution validation (constraint enforcement)
- Issue #8: Circle integration (wallet + USDC settlement)
@Verifieddanny
Verifieddanny merged commit 5ac4738 into main Jun 9, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding Redis Cache

1 participant