Canonical: https://nitride.xyz/blog/one-destination-many-bots

# One destination, many bots: fanning shreds out inside your network

One receiver takes the feed and copies every datagram to each internal consumer; here is a tested forwarder and why SO_REUSEPORT is the wrong tool for it.

Run one receiver on the address the feed is delivered to and have it copy every datagram to each internal consumer with a plain unicast send. SO_REUSEPORT will not do this job: it spreads datagrams across sockets instead of copying them. Multicast on your own LAN also works, at the price of switch configuration.

## The shape that works

If you run more than one program that wants the feed, you are in good company. A quoting engine, an arbitrage bot, a logger that writes everything to disk, a research box that someone is always restarting. The feed arrives at exactly one place: a plan covers one IPv4 address and one UDP port, as [your destination IP and port](https://nitride.xyz/docs/delivery/destination) explains. So the question is how to fan out UDP shreds once they land. If the packets themselves are new to you, [Solana shreds, explained](https://nitride.xyz/learn/solana-shreds) covers what each one carries.

The answer we keep coming back to is the dullest one. One process owns the socket on the destination port. It does nothing but receive each datagram and send a copy to a short list of internal addresses, either `127.0.0.1` ports on the same machine or `10.0.0.x` hosts on the private network. Every consumer then sees the full stream, byte for byte, and owns its own parsing, its own decoding and its own idea of which shreds it cares about.

Three rules keep this shape healthy:

- **The forwarder holds no logic.** No parsing, no dedup, no reordering. Every feature you add there is a feature that can stall all your bots at once.
- **Consumers never share a socket.** Each one binds its own port and has its own receive buffer, so a slow consumer only hurts itself.
- **The bot that pays for every microsecond reads the destination socket directly**, if it can. Everything else hangs off the forwarder.

That last rule is a choice, not a law. Some teams prefer that every consumer, including the fast one, sits behind the forwarder so all of them see identical input. That is fine too; just make the trade knowingly.

## SO_REUSEPORT spreads datagrams, it does not copy them

The first idea many people have is to let several programs bind the same port with `SO_REUSEPORT`. The socket(7) man page describes what that option is for: better distribution of incoming UDP datagrams across processes or threads. Distribution means each datagram goes to one socket. It is a load balancer, and a shred consumer that receives a random subset of the stream is broken.

It is worse than random for a feed. The kernel picks the socket by hashing the packet's addresses and ports, and a feed arrives from one source address and port. This short test binds two sockets to port 19200 with `SO_REUSEPORT` and sends 50 datagrams, first from a single sender, then from 50 senders with one datagram each:

```text file="output"
one sender, 50 datagrams: [0, 50]
50 senders, 1 datagram each: [22, 28]
```

With one sender, one socket received everything and the other received nothing. With many senders the datagrams were split between the two. Neither case gives you a copy per consumer. `SO_REUSEPORT` has real uses for a receiver, such as spreading work across threads when traffic comes from many sources, but copying is not one of them.

## A forwarder you can read in one sitting

This is the forwarder we tested. It takes the listening port and a list of targets, and copies every datagram to each target:

```python file="fanout.py"
# fanout.py: receive shreds on one UDP port and copy each datagram to every target.
# usage: python3 fanout.py 9000 127.0.0.1:9101 10.0.0.12:9000
import socket
import sys
import time

listen_port = int(sys.argv[1])
targets = []
for arg in sys.argv[2:]:
    host, port = arg.rsplit(":", 1)
    targets.append((host, int(port)))

rx = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
rx.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 8 << 20)  # capped by net.core.rmem_max
rx.bind(("0.0.0.0", listen_port))

tx = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
tx.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 8 << 20)  # capped by net.core.wmem_max
tx.setblocking(False)  # a stuck target must never stall the receive loop

buf = bytearray(2048)
view = memoryview(buf)
received = 0
sent = [0] * len(targets)
dropped = [0] * len(targets)
next_report = time.monotonic() + 10

while True:
    n = rx.recv_into(buf)
    received += 1
    for i, target in enumerate(targets):
        try:
            tx.sendto(view[:n], target)
            sent[i] += 1
        except OSError:  # send buffer full, no route, or an ICMP error
            dropped[i] += 1
    if time.monotonic() >= next_report:
        print(f"in={received} sent={sent} dropped={dropped}", file=sys.stderr, flush=True)
        next_report += 10
```

To test it, we ran it on port 19100 with two consumers on `127.0.0.1:19101` and `127.0.0.1:19102`, and sent 20,000 datagrams of 1,228 bytes, each numbered and filled with random bytes. Each consumer hashed what it received:

```text file="output"
sent 20000 3decbfaf2db2905a
19101 20000 3decbfaf2db2905a
19102 20000 3decbfaf2db2905a
```

Both consumers got all 20,000 datagrams with a hash identical to the sender's. A second run pointed one target at a port with nothing listening. The forwarder kept going and reported `dropped=[0, 0]`: on an unconnected UDP socket, a send to a dead port on loopback still succeeds. That is the lesson we would underline. **The forwarder's counters tell you what it sent, not what anyone received.** Each consumer has to watch its own socket drops, with the counters described in [Linux sockets and buffers](https://nitride.xyz/docs/receiver/linux-sockets#drops).

Two details in the code matter more than they look. The send socket is non-blocking, so one target with a full send buffer costs a counted drop instead of freezing the loop for everyone. And the receive buffer request is silently capped by `net.core.rmem_max`, so raise that first, on the host, as the sockets page shows.

Python makes the logic easy to read, but it pays one system call per datagram per target. Measure it against your own traffic before trusting it. If it falls behind, the same design in C or Rust can read batches with `recvmmsg` and send them with `sendmmsg`, which has been in Linux since 3.0.

## Multicast on your own LAN

If you have many consumers on many hosts, multicast lets the network do the copying. The forwarder sends each datagram once to a group address, and every host that joined the group with `IP_ADD_MEMBERSHIP` gets a copy. RFC 2365 sets aside `239.0.0.0/8` for administratively scoped groups, with `239.192.0.0/14` as the organization-local scope, so a group such as `239.192.10.1` stays yours.

It is a good tool with real costs:

- **Switches.** A switch that does not snoop IGMP forwards multicast out of every port in the segment. RFC 4541 describes exactly that: packets flooded into segments where no node wants them. If you go this way, confirm IGMP snooping and a querier on the switch.
- **Reach.** The default multicast TTL is 1, so groups stay on the local network unless you raise it and route it. Many virtual networks in hosted environments do not carry multicast at all; ask your provider before you design around it.
- **Debugging.** When one host stops receiving, the cause can be the group join, the switch, the firewall or the reverse path check. Unicast to a list of addresses has fewer places to hide.

As a starting point: for two to five consumers, unicast copies from a forwarder are simpler and easy to reason about. Multicast starts to pay when the consumer list is long and changes often, and someone on the team already runs the switches.

## What the extra hop costs

Fanning out is not free, and pretending it is leads to bad comparisons later.

- **A hop.** Every consumer behind the forwarder sees a datagram only after the forwarder has woken up, read it and sent it. That adds scheduling delay and jitter, and it grows when the forwarder shares a busy CPU. Pin it to a core of its own if you can.
- **A copy per consumer.** Each target costs a send and a kernel copy, and on a LAN it multiplies the feed's bandwidth by the number of remote consumers. Check the internal links, not just the uplink.
- **A second place to lose packets.** The forwarder's socket can drop, and so can each consumer's. [What causes packet loss and jitter](https://nitride.xyz/learn/packet-loss-and-jitter) walks through where loss hides, and the same counters apply at both stages.
- **A dependency.** If the forwarder dies, every consumer goes quiet. Run it under a supervisor that restarts it, and alert on its input counter going flat.

None of this argues against the forwarder. It argues for measuring arrival at the consumer, not at the destination socket, when you compare setups. The difference between the two is the cost of your fan-out.

If the receiver runs in a container, the hop count can grow without you noticing. [Running a shred receiver in Docker](https://nitride.xyz/blog/shred-receiver-in-docker) covers the NAT path and the userland proxy, which add their own copies.

## When a consumer lives outside your network

Fan-out is for your own machines on your own network. A server in another data center, or a second network path you want for resilience, is a different case: it needs its own feed, at its own address. Each extra destination is a separate purchase, at its plan's price, for 30 days. If the far consumer is less sensitive to timing, it can run on Standard while the main box runs on Ultra; [Ultra vs Standard](https://nitride.xyz/compare/ultra-vs-standard-shreds) lays out the one difference between them, which is the delivery path.

Forwarding across the public internet also gives up what you paid for. The stream would take a longer, less predictable path and arrive later and with more loss than a direct feed to that server. [Why serious Solana feeds still use plain UDP](https://nitride.xyz/blog/why-plain-udp) explains why nothing upstream will resend what gets lost on the way.

You can pass the stream on to any number of your own machines; sending it to anyone else needs a written agreement with us. Our [acceptable use policy](https://nitride.xyz/acceptable-use) states the rule in full. For a team running several strategies, such as the setups in [shreds for market makers](https://nitride.xyz/use-cases/market-making), one destination and a small forwarder usually cover everything on one site.

Each plan has a free 2-hour trial, once per person. Email support@nitride.xyz with the IPv4 address and UDP port you want to test. We verify you receive on that address, then your 2 hours start.
