Skip to content

Commit d700af2

Browse files
authored
feat: add remote materialization store for Go (#203)
1 parent 0f2ef79 commit d700af2

File tree

9 files changed

+1610
-141
lines changed

9 files changed

+1610
-141
lines changed

openfeature-provider/go/README.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ if err != nil {
140140
Configure the provider behavior using environment variables:
141141

142142
- `CONFIDENCE_RESOLVER_POLL_INTERVAL_SECONDS`: How often to poll Confidence to get updates (default: `30` seconds)
143+
- `CONFIDENCE_MATERIALIZATION_READ_TIMEOUT_SECONDS`: Timeout for remote materialization store read operations (default: `2` seconds)
144+
- `CONFIDENCE_MATERIALIZATION_WRITE_TIMEOUT_SECONDS`: Timeout for remote materialization store write operations (default: `5` seconds)
143145

144146
### ProviderConfig
145147

@@ -153,8 +155,12 @@ The `ProviderConfig` struct contains all configuration options for the provider:
153155

154156
- `Logger` (*slog.Logger): Custom logger for provider operations. If not provided, a default text logger is created. See [Logging](#logging) for details.
155157
- `TransportHooks` (TransportHooks): Custom transport hooks for advanced use cases (e.g., custom gRPC interceptors, HTTP transport wrapping, TLS configuration)
156-
- `MaterializationStore` (MaterializationStore): Custom storage for sticky variant assignments and materialized segments. If not provided, the provider will
157-
fall back to default values for flags with rules that require materializations. See [Materialization Stores](#materialization-stores) for details.
158+
- `MaterializationStore` (MaterializationStore): Storage for sticky variant assignments and materialized segments. Options include:
159+
- `nil` (default): Falls back to default values for flags requiring materializations
160+
- `NewRemoteMaterializationStore()`: Uses remote gRPC storage (recommended for getting started)
161+
- Custom implementation: Your own storage (Redis, DynamoDB, etc.) for optimal performance
162+
163+
See [Materialization Stores](#materialization-stores) for details.
158164

159165
#### Advanced: Testing with Custom State Provider
160166

@@ -186,6 +192,46 @@ Materialization stores provide persistent storage for sticky variant assignments
186192

187193
⚠️ Warning: If your flags rely on sticky assignments or materialized segments, the default SDK behaviour will prevent those rules from being applied and your evaluations will fall back to default values. For production workloads that need sticky behavior or segment lookups, implement and configure a real `MaterializationStore` (e.g., Redis, Bigtable, DynamoDB) to avoid unexpected fallbacks and ensure consistent variant assignment. ✅
188194

195+
### Remote Materialization Store
196+
197+
For quick setup without managing your own storage infrastructure, enable the built-in remote materialization store. This implementation stores materialization data via gRPC to the Confidence service.
198+
199+
**When to use**:
200+
- You need sticky assignments or materialized segments but don't want to manage storage infrastructure
201+
- Quick prototyping or getting started
202+
- Lower-volume applications where network latency is acceptable
203+
204+
**Trade-offs**:
205+
- Additional network calls during flag resolution (adds latency)
206+
- Lower performance compared to local storage implementations (Redis, DynamoDB, etc.)
207+
208+
```go
209+
import (
210+
"context"
211+
212+
"github.com/open-feature/go-sdk/openfeature"
213+
"github.com/spotify/confidence-resolver/openfeature-provider/go/confidence"
214+
)
215+
216+
func main() {
217+
ctx := context.Background()
218+
219+
// Enable remote materialization store
220+
provider, err := confidence.NewProvider(ctx, confidence.ProviderConfig{
221+
ClientSecret: "your-client-secret",
222+
UseRemoteMaterializationStore: true,
223+
})
224+
if err != nil {
225+
log.Fatalf("Failed to create provider: %v", err)
226+
}
227+
228+
openfeature.SetProviderAndWait(provider)
229+
// ...
230+
}
231+
```
232+
233+
The remote store is created automatically by the provider with the correct gRPC connection and authentication.
234+
189235
### Custom Implementations
190236

191237
For improved latency and reduced network calls, you can implement your own `MaterializationStore` interface to store materialization data in your infrastructure (Redis, DynamoDB, etc.):

0 commit comments

Comments
 (0)