Skip to content

t1k:nakama:grpc-client

FieldValue
Modulebase
Version1.11.11
Effortlow
Tools—

Keywords: backoff, grpc, grpc client, health check, microservice, reconnection

/t1k:nakama:grpc-client

The gRPC client in internal/grpcclient/ manages the connection to the Gameplay microservice with automatic reconnection using Fibonacci-backoff delays.

client, err := grpcclient.NewGameplayClient(ctx, logger, addr, apiKey)
  • Fibonacci backoff: Retry delays follow 1, 1, 2, 3, 5, 8… seconds
  • Health check: Verifies server is responding after connection
  • State monitoring: Watches connectivity.State changes, auto-reconnects on failure
  • IsConnected(): Check before every RPC call
  • GAMEPLAY_GRPC_ADDR — target address (default: gameplay:9550)
  • GAMEPLAY_API_KEY — service-to-service auth key sent as metadata
if !client.IsConnected() {
return "", runtime.NewError("gameplay service unavailable", 14)
}
resp, err := client.Method(ctx, req)
if err != nil {
return "", mapGRPCError(err)
}
  • API key is sent as gRPC metadata on every call — not as TLS client cert
  • TLS cert validation: In production, always validate server certificates. Skip only in dev with explicit flag.
  • Client created in InitModule with correct address and API key
  • IsConnected() checked before every gRPC call
  • gRPC errors mapped via mapGRPCError() to Nakama error codes
  • Connection timeout is reasonable for the deployment environment
  • Health check endpoint exists on the Gameplay service