A Go server that fans a realtime event stream out to many WebSocket clients, with a gRPC ingest side and Prometheus instrumentation throughout.
This is the Go fan-out half. The Java pipeline that feeds it (Twitter → Kafka → gRPC)
lives in twitter-kafka-streaming.
producer ──gRPC (Receive)──► notifier gRPC :6565
│ fan-out
▼
subscribers
│
grpc-gateway + wsproxy :8081
▼
WebSocket clients
- gRPC server (
cmd/) — registersTweetServicewith two streams:Receive(ingest) andStream(subscribe). Prometheus stream/unary interceptors and a/metricsendpoint on:9100. - Fan-out core (
internal/notify) —Connectionkeeps a slice of subscriber channels behind a mutex.In()drops each packet on a buffereddatachannel; a pool of ~20notifygoroutines drains it and delivers a copy to every subscriber channel, so one slow client can't block ingest. - Gateway (
gateway/) — grpc-gateway translates the gRPC stream to HTTP, wrapped in a WebSocket proxy so browsers can subscribe overws://. Handlers are wrapped in a Prometheus instrumentation chain (in-flight, count, duration, response size). - The protobuf contract is shared with
twitter-kafka-streaming.
# 1. protobuf stubs (contract shared with twitter-kafka-streaming)
protoc -I proto/ proto/notifier/**/*.proto --go_out=plugins=grpc:grpc
# 2. gRPC server on :6565 (+ metrics on :9100)
go run ./cmd
# 3. gateway on :8081 (HTTP/WebSocket)
go run ./gateway/cmdGo 1.13 · gRPC 1.27 · grpc-gateway · gorilla/websocket · Prometheus client
Built 2020 to learn gRPC streaming, grpc-gateway, and channel-based fan-out in Go. Not maintained.