Go is a strong fit for real-time applications such as chat, live dashboards, multiplayer game backends and streaming pipelines. Goroutines make it cheap to hold tens of thousands of concurrent connections, channels coordinate them safely, and the standard library handles TCP, HTTP, TLS and timers. Go is not a hard real-time language, though: its garbage collector and scheduler give low and predictable latency, not guaranteed deadlines.
This article explains why Go suits "soft" real-time workloads, shows a working broadcast hub using WebSockets, and lists the pitfalls to avoid.
In backend work, real-time usually means soft real-time: updates reach users within milliseconds to a few hundred milliseconds. Missing a deadline degrades the experience but does not cause a failure.
Hard real-time systems, such as flight controllers or motor control, need guaranteed worst-case latency. Go's concurrent garbage collector keeps pauses short, but it cannot promise a bound, so use C, C++ or Rust with a real-time operating system for those.
A goroutine starts with a small stack that grows on demand, and the runtime multiplexes goroutines onto operating system threads. A common design is one goroutine to read from each connection and one to write to it. Blocking I/O in Go is multiplexed through the runtime's network poller, so you write simple sequential code while the runtime avoids one thread per connection.
Always check the errors from Listen and Accept, and close connections you no longer need so goroutines do not leak.
Channels give you a safe way to share state. The classic real-time pattern is a hub goroutine that owns the set of clients and receives register, unregister and broadcast events through channels, so no mutex is needed.
The non-blocking select with a default case is important. Without it, one slow client would stall the broadcast loop for everybody.
Browsers need a long-lived channel for push updates. You have two common options:
| Option | Direction | Notes |
|---|---|---|
| WebSocket | Both ways | Chat, games, collaborative editing |
| Server-Sent Events (SSE) | Server to client | Notifications, live feeds, simple dashboards |
The standard library has no WebSocket server, so use a maintained library such as github.com/coder/websocket (formerly nhooyr.io/websocket) or github.com/gorilla/websocket. SSE needs only net/http:
The handler exits when the client disconnects because r.Context() is cancelled.
context.Context everywhere and set deadlines on outbound calls.sync.Pool, avoid needless conversions) to give the garbage collector less work.GOMAXPROCS only if you run in containers with CPU limits; recent Go versions detect cgroup limits by default, but verify on your version.pprof, go tool trace and go test -race before guessing at optimisations.One Go process can hold a very large number of connections, but real systems also need fan-out across machines. A message broker or pub/sub system such as NATS, Redis Pub/Sub or Kafka lets each server publish events and relay them to its own connected clients. For sticky state, such as a game room, route all players of a room to the same instance.
Not in the hard real-time sense. It suits soft real-time systems where low average and tail latency matter, but it gives no guaranteed worst-case deadlines.
Tens or hundreds of thousands per machine are realistic when each connection is mostly idle, limited by memory, file descriptors and your per-message work. Raise the file descriptor limit and load-test your own workload.
Use SSE when only the server pushes data, because it works over plain HTTP and reconnects automatically. Use WebSockets when clients also send frequent messages.
A blocking send to one slow client usually stalls the loop. Use buffered channels and drop or disconnect clients whose buffer is full.
Go suits soft real-time systems thanks to cheap goroutines, channels and a capable networking stack. Use a hub goroutine to own shared state, never block on slow clients, cancel work through context, and add a broker when you scale past one process. For hard real-time guarantees, choose a different tool.