Relay pattern reduces N-squared delivery to 2N in federation
A relay instance acts as a hub that redistributes activities, reducing the delivery cost from Nร(N-1) direct connections to 2N.
In a [[federated]] network, if every instance sends updates to every other instance, the delivery cost is N ร (N-1). For 100 instances, that is 9,900 deliveries per update cycle. For 1,000 instances, it is 999,000.
A relay reduces this to 2N: each instance sends one update to the relay, and the relay forwards it to all other subscribers.
How It Works
A relay is a special instance with no content of its own. Its sole job is to receive activities and redistribute them. It uses the standard [[ActivityPub]] Follow/Accept flow:
- An instance follows the relay; the relay auto-accepts
- When an instance sends an activity to the relay’s inbox, the relay re-announces it to all other subscribers (excluding the original sender)
- The relay wraps the original activity in a new
Announcewith itself as actor
In ActivityPub, the relay is typically an actor of type Group โ which has the specific semantic of redistributing received content to its followers.
When to Use Relays
- Small networks (< 20 instances): direct federation is fine, N-squared overhead is manageable
- Medium networks (20โ200): one relay significantly reduces traffic
- Large networks (200+): multiple regional or topic-based relays
The relay introduces a single point of throughput concern (all traffic routes through it) but not a single point of failure โ if the relay goes down, instances can fall back to direct delivery.
Related Concepts
- [[Federation]] โ the network architecture where the relay pattern applies
- [[ActivityPub]] โ the protocol that defines the Group actor type used for relays
- [[Circuit breaker pattern]] โ essential for relay implementations that must handle delivery failures to many endpoints