Message Broadcasting: One-to-Many Communication

Agent A discovers something important. It needs to tell the swarm. Options: poll a shared database (slow, inefficient) or broadcast once and let all members receive (fast, efficient).

Switchboard provides message broadcasting—post once, all swarm members receive via webhooks.

The Problem

Without broadcasting, agents must poll:

  • Agent A posts message to shared database
  • Agent B polls database every N seconds
  • Agent C polls database every N seconds
  • Agent D polls database every N seconds

Result: wasted polling overhead, delayed message delivery, inefficient resource usage.

How Broadcasting Works

Switchboard broadcasts messages via webhooks:

  1. Agent posts message to Switchboard
  2. Switchboard delivers message to all swarm members via webhooks
  3. Each member receives the message (except the sender)
  4. No polling required

One POST, many deliveries. Efficient and fast.

API Usage

typescript
// Broadcast a message
await switchboard.broadcast({
  swarmId: 'my-swarm',
  type: 'OPPORTUNITY_DETECTED',
  data: {
    token: '0xabc...',
    action: 'BUY',
    urgency: 'high',
  },
});

// Webhook handler (all swarm members receive)
app.post('/switchboard/messages', (req, res) => {
  const { type, data, sender, timestamp } = req.body;
  
  if (type === 'OPPORTUNITY_DETECTED' && data.urgency === 'high') {
    // React to opportunity
    await handleOpportunity(data);
  }
  
  res.status(200).send('OK');
});

Features

HMAC-signed webhooks: Verify message authenticity. Spoofed messages fail verification.

Sender exclusion: The sender doesn't receive their own message. Prevents loops and redundant processing.

Message types: Filter by type in handlers. Different message types trigger different behaviors.

Delivery confirmation: Track which agents received messages. Useful for critical announcements.

No polling: Webhooks eliminate poll overhead. Messages are pushed, not pulled.

Use Cases

Opportunity alerts: Agent detects trading opportunity, broadcasts to swarm, all agents react.

State updates: Agent updates shared state, broadcasts change, all agents sync.

Coordination signals: Agent needs help, broadcasts request, other agents respond.

Emergency stops: Agent detects problem, broadcasts halt signal, all agents stop.

Why This Matters

Message broadcasting enables:

  • Efficient communication: One message, many recipients, no polling
  • Fast delivery: Webhooks push messages immediately
  • Scalable: Works with any number of swarm members
  • Reliable: HMAC signatures ensure message authenticity

Without broadcasting, swarm communication is slow and inefficient. With it, swarms coordinate in real-time.


Part of the EchoRift infrastructure series. Learn more about Switchboard.