Go gives you several ways to communicate between parts of a system. Channels connect goroutines inside one process, os/exec with pipes and Unix domain sockets connect processes on one machine, and RPC frameworks such as gRPC (or JSON over HTTP) connect services across a network. Pick the narrowest tool that fits the boundary you are crossing.
This article compares the options and shows working code for each, using current Go and the maintained gRPC client API.
| Boundary | Typical tool | Notes |
|---|---|---|
| Goroutines in one process | Channels, sync primitives | Fastest, no serialization |
| Parent and child process | os/exec with stdin/stdout pipes | Text or JSON lines |
| Processes on one host | Unix domain sockets, named pipes | Works with net package |
| Services across machines | gRPC, net/http with JSON | Needs a schema and timeouts |
| Legacy Go-only services | net/rpc | Frozen, not recommended for new code |
Channels are not inter-process communication. They only work between goroutines of the same program, so the original idea of using them for IPC applies to concurrency inside one binary.
An unbuffered channel hands a value from sender to receiver and blocks until both are ready. A buffered channel lets the sender continue until the buffer is full.
The select with a context deadline prevents the receiver from blocking forever if the sender never runs.
os/exec starts an external program and connects its standard streams. Use exec.CommandContext so the child is killed when the context ends.
For long-running children, use StdinPipe and StdoutPipe and exchange newline-delimited JSON. Always call cmd.Wait so the process is reaped.
For two independent processes on one machine, a Unix socket is fast and permission-controlled by the file system.
net/rpc lets a Go client call exported methods of a Go server using encoding/gob. It works, but the standard library documents the package as frozen and not accepting new features, and it only supports Go clients. Treat it as legacy and use gRPC or HTTP APIs for new services.
The method must be exported, take two exported-type arguments (the second a pointer) and return error.
gRPC uses Protocol Buffers for the schema and HTTP/2 for transport. You write a .proto file, generate Go code with protoc (plus the protoc-gen-go and protoc-gen-go-grpc plugins), then implement the generated server interface.
grpc.NewClient replaces the older grpc.Dial and grpc.WithInsecure, which are deprecated. insecure.NewCredentials() (from google.golang.org/grpc/credentials/insecure) is for local development only; use TLS or mTLS in production. Always pass a context deadline on calls.
.proto files by adding fields, never renumbering them.No. Channels exist only inside one process. Between programs use pipes, sockets, files, a message broker or RPC.
It is frozen: the standard library keeps it working but accepts no new features. Prefer gRPC or HTTP with JSON for new work.
grpc.NewClient is the recommended constructor in current grpc-go. Unlike Dial, it does not connect immediately; the connection is made on the first call.
Choose HTTP and JSON when browsers or third parties consume the API or when you want simple debugging with curl. Choose gRPC for internal services that benefit from schemas and streaming.
Use channels inside a process, pipes or Unix sockets between local processes, and gRPC or HTTP across machines. Avoid net/rpc for new code, use grpc.NewClient with TLS in production, and always set deadlines so slow peers cannot hang your program.