Canonical: https://solanashreds.xyz/compare/decoder-in-process-vs-service

# Decode inside the bot or in a separate service?

Solana bot decoder architecture: decode inside the bot process or run a separate decoder service. Diagrams of both and the trade offs of each.

Decode inside the bot while one program reads the stream: there is one process to deploy, nothing extra in the path, and debugging stays simple. Move decoding into its own service once a second consumer needs the same transactions, when a decoder crash must not stop trading, or when the two parts need different release schedules.

Two ways to place the decoder: inside one bot process, with receiver, decoder and strategy together, or as a service that decodes once and publishes transactions to a bus that several bots read.

## Strengths and costs of each shape

### Decoder inside the bot

Strengths: one deployable, no network hop between decoding and decisions, a single log to read when something looks wrong. Costs: every new consumer decodes the same packets again, a decoder bug can crash the strategy, and you cannot upgrade one without restarting the other.

### Decoder as a service

Strengths: decoding happens once, consumers can be written in any language, and a crash stays inside one process. Costs: a bus and a schema to operate, one more hop before a bot sees a transaction, and two release trains to keep compatible.

## The two shapes in detail

In the first shape the receiver thread reads datagrams from the UDP port, hands them to the decoder in the same memory space, and the strategy reads decoded transactions from a queue a few lines of code away. Nothing is serialized twice. This is where almost every project starts, and for a single bot it is often where it should stay. [The Go decoder](https://solanashreds.xyz/docs/decode/go) is a worked example of this shape: one goroutine per stage, joined by bounded channels inside a single process.

In the second shape one process owns the UDP port. It receives, reassembles and decodes, then publishes each transaction as a message. Bots, indexers and alerting jobs subscribe on their own schedules. The published message becomes a contract, so version it from day one; the [message bus scorecard](https://solanashreds.xyz/compare/kafka-vs-nats-vs-redis-streams) covers the transport choices.

A middle option is a sidecar: the decoder runs as a separate process on the same machine as one bot and passes transactions over a local socket. It isolates crashes without adding a network hop, but it does not solve fan-out to other machines.

## Signs it is time to split

- A second consumer, such as an indexer or an alert job, needs the same decoded transactions.
- A decoder fault has stopped the strategy at least once.
- The decoder needs updates when programs change layouts, but trading code should not restart for that.
- The decoding stage and the strategy want different languages; the [language comparison](https://solanashreds.xyz/compare/decoder-languages) explains why that happens.
- You want metrics per stage that you can alert on separately, as the [observability post](https://solanashreds.xyz/blog/observability-for-decoders) describes.

## One destination, many consumers

Each plan delivers to one destination, an IPv4 address and UDP port. That fits the service shape naturally: the decoder service owns the destination and everything else consumes from it. If you would rather fan out raw packets, a single receiver can forward them on your own network to as many of your own machines as you like. Either way, decide where filtering happens; [filtering by program ID](https://solanashreds.xyz/docs/decode/filter-by-program) and [where to filter in a pipeline](https://solanashreds.xyz/blog/filter-early) cover that choice, and the [CPU cost post](https://solanashreds.xyz/blog/what-decoding-costs-in-cpu) helps you size the decoder machine.

## Architecture questions

### Does a decoder service slow my bot down?

It adds a hop and a serialization step between decoding and the strategy. Measure that on your own hardware before deciding it matters; for many workloads it does not.

### Can several processes share one UDP port?

On Linux, sockets can share a port with SO_REUSEPORT, but the kernel picks one socket per source address and port, so a feed from a single sender lands on one socket unless you attach a BPF steering program. It never gives each process every packet.

### Should the decoder do the filtering?

Usually yes, early, so consumers receive only the programs they care about. Keep the unfiltered raw stream available for replay if you can.

## When architecture is not the fix

If packets are lost before any decoder sees them, splitting or merging processes will not bring them back, since a raw feed never resends. Check socket buffers and receiver load first. And if the real constraint is how quickly your strategy decides, moving the decoder will not change that either.

## Plan the next step

If one bot is all you run, keep the decoder inside it and revisit when the list above starts to apply. When the path between our server and yours matters to your strategy, read about [Ultra Low Latency Shreds](https://solanashreds.xyz/ultra-low-latency-shreds), or [compare the two plans](https://solanashreds.xyz/compare/solanashreds-standard-vs-ultra) before you order.
