cmd-stream-go is a high-performance, modular client–server library for Go, based on the Command Pattern. It's designed for efficient, low-latency communication over TCP/TLS, with support for streaming and observability.
Want to learn how the Command Pattern applies to network communication? Check out this series of posts.
It delivers high-performance and resource efficiency, helping reduce infrastructure costs and scale more effectively.
- Works over TCP, TLS or mutual TLS.
- Has an asynchronous client that uses only one connection for both sending Commands and receiving Results.
- Supports the server streaming, i.e. a Command can send back multiple Results.
- Provides reconnect and keepalive features.
- Supports the Circuit Breaker pattern.
- Has OpenTelemetry integration.
- Can work with various serialization formats.
- Follows a modular design.
The main cmd-stream-go
module contains basic integration tests, while each
submodule (see Architecture) has approximately 90% code
coverage.
See go-client-server-benchmarks for performance comparisons.
Getting started is easy:
- Implement the Command Pattern.
- Generate the serialization code.
For more details, explore the following resources:
Built on Go’s standard net
package, cmd-stream-go
supports
connection-oriented protocols, such as TCP, TLS, and mutual TLS (for client
authentication).
The client operates asynchronously, sending Commands to the server. On the server side, the Invoker executes the Commands, while the Receiver provides the underlying server functionality.
To maximize performance between services:
- Use N parallel connections. More connections typically improve throughput, until a saturation point.
- Pre-establish all connections instead of opening them on-demand.
- Keep connections alive to avoid the overhead from reconnections.
These practices, implemented via the ClientGroup, can significantly enhance throughput and reduce latency between your services.
Already using RPC? You can use cmd-stream-go
as a faster transport layer. See
the RPC example.
cmd-stream-go
is split into the following submodules:
- core-go: The core module that includes client and server definitions.
- delegate-go: The client delegates all communication-related tasks to its delegate, the server follows the same approach. The connection is also initialized at this level.
- handler-go: The server delegate uses a handler to receive and process Commands.
- transport-go: Responsible for Commands/Results delivery.
cmd-stream-go was designed in such a way that you can easily replace any part of it.