Overview
The Flagmint Go SDK maintains a persistent connection to the backend to receive real-time flag updates. Two transport implementations are available:| Transport | Mode constant | Protocol |
|---|---|---|
| WebSocket | TransportWebSocket | wss:// — full-duplex, low overhead |
| HTTP long-polling | TransportLongPolling | https:// — request/response with long timeout |
TransportAuto mode tries WebSocket first and transparently falls
back to HTTP if the connection cannot be established.
Choosing a Transport
When to use WebSocket
- Long-running server processes (API servers, background workers)
- Environments where WebSocket is not blocked
- When you need the lowest possible flag update latency
When to use HTTP long-polling
- Serverless functions (AWS Lambda, Cloud Run) where persistent connections are not maintained between invocations
- Environments behind proxies that strip WebSocket upgrade headers
- Corporate networks that block WebSocket connections
Endpoint Configuration
By default the SDK connects to the Flagmint production endpoints:| Transport | Default endpoint |
|---|---|
| REST / HTTP | https://api.flagmint.com |
| WebSocket | wss://api.flagmint.com |
WithEndpoints or environment variables:
Reconnection Behaviour
Both transports use an exponential back-off strategy with jitter when a connection drops. The back-off is handled by theinternal/backoff package:
- Initial delay: 250 ms
- Maximum delay: 30 s
- Multiplier: 2×
- Jitter: ±20 %
URL Paths
The SDK appends fixed paths to the configured base endpoints:| Transport | Path appended |
|---|---|
| WebSocket | /ws/sdk |
| HTTP | /evaluator/evaluate |
Auto Transport Fallback
TransportAuto (the default) works as follows:
- Attempt a WebSocket connection.
- If the WebSocket connection fails (e.g.,
HTTP 426, proxy rejection), start an HTTP long-polling connection instead. - Subsequent reconnections follow the same precedence.
Ready, BoolFlag, and
Subscribe all behave identically regardless of the active transport.
Flags Received Callback
Internally both transports call anOnFlagsUpdated callback whenever a new
flag payload is received. This triggers updateFlags, which:
- Stores the new values atomically.
- Persists them to cache (if enabled).
- Notifies all
Subscribecallbacks.