Overview
The Agones SDK provides a gRPC interface for game servers to communicate with the Agones sidecar. This API enables game servers to:- Manage their lifecycle states
- Update metadata dynamically
- Track player connections
- Manage counters and lists for capacity tracking
- Report health status
Architecture
The SDK runs as a sidecar container alongside your game server container in the same Kubernetes Pod. Communication happens over localhost using gRPC, with both binary protocol buffer and HTTP/JSON interfaces available.SDK Stability Stages
The SDK is organized into three stability stages:Stable (GA)
The core SDK service (agones.dev.sdk.SDK) provides production-ready lifecycle and metadata management. These features are stable and recommended for all deployments.
Key capabilities:
- Lifecycle state transitions (Ready, Shutdown, Allocate)
- Health reporting
- Metadata updates (labels, annotations)
- Game server state queries
- Reservation system
Alpha Features
Alpha SDK features (agones.dev.sdk.alpha.SDK) provide player tracking capabilities. These require the PlayerTracking feature gate to be enabled.
Key capabilities:
- Player connection/disconnection tracking
- Player capacity management
- Player ID queries
Beta Features
Beta SDK features (agones.dev.sdk.beta.SDK) provide Counters and Lists for advanced capacity management. These require the CountsAndLists feature gate to be enabled.
Key capabilities:
- Counter get/update operations
- List get/update operations
- List value add/remove operations
Beta features are more stable than alpha but may still evolve. APIs are unlikely to change significantly, but minor adjustments may occur based on feedback.
Service Endpoints
The SDK sidecar exposes services onlocalhost:9357 by default:
- Core SDK:
/(root path) - Alpha SDK:
/alpha/*paths - Beta SDK:
/v1beta1/*paths
Client Libraries
Official SDK client libraries are available for multiple languages:- Go:
agones.dev/agones/pkg/sdk - C#: Agones Unity SDK
- C++: Native gRPC client
- Node.js: gRPC-node client
- Rust: Agones Rust SDK
- REST: HTTP/JSON gateway for any language
Common Workflows
Basic Game Server Lifecycle
- Startup: Game server container starts
- Initialization: Game server completes loading assets and configuration
- Ready: Call
SDK.Ready()to signal readiness for allocation - Allocated: Agones allocates the server (or call
SDK.Allocate()for self-allocation) - Match: Players connect and play
- Shutdown: Call
SDK.Shutdown()when match ends
Health Monitoring
If health checking is enabled (default), send health pings:- Open a streaming connection with
SDK.Health() - Send
Emptymessages at regular intervals (default: every 5 seconds) - If health pings stop, Agones marks the server as unhealthy
Dynamic Metadata
Update game server metadata during runtime:- Call
SDK.SetLabel()to add/update labels - Call
SDK.SetAnnotation()to add/update annotations - Use for dynamic tagging (game mode, map, version, etc.)
Player Tracking (Alpha)
Track connected players with the Alpha SDK:- Call
PlayerConnect()when a player joins - Call
PlayerDisconnect()when a player leaves - Query player counts with
GetPlayerCount() - Check specific player connections with
IsPlayerConnected()
Capacity Management (Beta)
Manage complex capacity with Counters and Lists:- Use Counters for numeric capacity (e.g., current players, match count)
- Use Lists for string-based tracking (e.g., player IDs, room names)
- Update values during gameplay with increment/decrement operations
- Query current state for allocation decisions
Protocol Details
- Protocol: gRPC with Protocol Buffers (proto3)
- Packages:
agones.dev.sdk(stable)agones.dev.sdk.alpha(alpha)agones.dev.sdk.beta(beta)
- Transport: HTTP/2 over localhost
- Default Port: 9357
- HTTP Gateway: REST endpoints via gRPC-Gateway
Error Handling
The SDK uses standard gRPC status codes:OK(0): SuccessNOT_FOUND(5): Resource doesn’t exist (e.g., counter, list)ALREADY_EXISTS(6): Value already present (e.g., duplicate player ID)OUT_OF_RANGE(11): Capacity exceeded or invalid countINVALID_ARGUMENT(3): Invalid field or parameter
Best Practices
Call Ready() Promptly
CallSDK.Ready() as soon as your game server can accept player connections. Delaying this call wastes resources and increases allocation latency.
Implement Health Checks
Always implement health checking unless you have a specific reason to disable it. Health checks ensure Agones can detect and recover from server failures.Clean Shutdown
Always callSDK.Shutdown() when your match ends to release resources promptly. Don’t rely on pod termination timeouts.
Minimize Metadata Updates
While metadata updates are fast, avoid excessive calls. Batch updates when possible and only update when values actually change.Use Reservations for Matchmaking
UseSDK.Reserve() to temporarily hold a game server during matchmaking without fully allocating it. This prevents allocation by other systems while you finalize player matching.
Next Steps
Lifecycle Methods
Core SDK methods for managing game server lifecycle
Metadata Methods
Methods for updating labels and annotations
Alpha SDK
Player tracking features (alpha stage)
Beta SDK
Counters and Lists for capacity management (beta stage)
