Configure Network Settings
Why configure network settings
Section titled “Why configure network settings”The Optimizely SDK communicates with two endpoints: the CDN for datafile downloads and the event API for tracking data. Default settings work for most deployments, but regulated environments, high-traffic applications, and edge deployments require tuning polling intervals, routing through proxies, or self-hosting assets. Misconfigured network settings can cause stale flags, dropped events, or unnecessary bandwidth consumption.
What you will do
Section titled “What you will do”- Configure datafile polling intervals
- Set custom CDN endpoints or proxy URLs
- Configure event dispatch settings
- Set up firewall allowlists
Step 1: Configure polling intervals
Section titled “Step 1: Configure polling intervals”The SDK periodically fetches the datafile to pick up flag changes. The default interval is 5 minutes. Shorten it for faster propagation or lengthen it to reduce bandwidth.
const optimizely = createInstance({
sdkKey: 'YOUR_SDK_KEY',
datafileOptions: {
autoUpdate: true,
updateInterval: 30_000, // 30 seconds (minimum: 1000ms)
},
}); from optimizely.config_manager import PollingConfigManager
config_manager = PollingConfigManager(
sdk_key='YOUR_SDK_KEY',
update_interval=30, # 30 seconds
)
client = optimizely.Optimizely(config_manager=config_manager) var configManager = new HttpProjectConfigManager.Builder()
.WithSdkKey("YOUR_SDK_KEY")
.WithPollingInterval(TimeSpan.FromSeconds(30))
.Build();
var optimizely = new Optimizely(configManager); Polling interval guidelines
Section titled “Polling interval guidelines”| Environment | Recommended interval | Rationale |
|---|---|---|
| Development | 10-30 seconds | Fast iteration while building |
| Production (standard) | 1-5 minutes | Balance freshness with bandwidth |
| Production (high traffic) | 5-15 minutes | Reduce CDN requests at scale |
| Edge / serverless | Disable polling; use webhooks | Functions are short-lived; polling wastes resources |
Step 2: Configure custom endpoints
Section titled “Step 2: Configure custom endpoints”Feature Experimentation: custom datafile URL
Section titled “Feature Experimentation: custom datafile URL”Route datafile downloads through a proxy or internal CDN mirror. Use the urlTemplate option with %s as a placeholder for the SDK key.
const optimizely = createInstance({
sdkKey: 'YOUR_SDK_KEY',
datafileOptions: {
autoUpdate: true,
updateInterval: 60_000,
urlTemplate: 'https://cdn-proxy.internal.example.com/optimizely/%s.json',
},
}); config_manager = PollingConfigManager(
sdk_key='YOUR_SDK_KEY',
update_interval=60,
url_template='https://cdn-proxy.internal.example.com/optimizely/{sdk_key}.json',
)
client = optimizely.Optimizely(config_manager=config_manager) var configManager = new HttpProjectConfigManager.Builder()
.WithSdkKey("YOUR_SDK_KEY")
.WithUrl("https://cdn-proxy.internal.example.com/optimizely/YOUR_SDK_KEY.json")
.WithPollingInterval(TimeSpan.FromSeconds(60))
.Build();
var optimizely = new Optimizely(configManager); Custom event dispatch endpoint
Section titled “Custom event dispatch endpoint”Route events through a proxy if your firewall blocks direct access to the Optimizely event API.
import { createInstance } from '@optimizely/optimizely-sdk';
const optimizely = createInstance({
sdkKey: 'YOUR_SDK_KEY',
eventDispatcher: {
dispatchEvent(event) {
// Route through your proxy
const proxyUrl = event.url.replace(
'https://logx.optimizely.com',
'https://events-proxy.internal.example.com'
);
return fetch(proxyUrl, {
method: event.httpVerb,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(event.params),
});
},
},
}); from optimizely.event_dispatcher import EventDispatcher as BaseDispatcher
import requests
class ProxyEventDispatcher(BaseDispatcher):
def dispatch_event(self, event):
proxy_url = event.url.replace(
'https://logx.optimizely.com',
'https://events-proxy.internal.example.com'
)
requests.post(proxy_url, json=event.params, timeout=10)
client = optimizely.Optimizely(
sdk_key='YOUR_SDK_KEY',
event_dispatcher=ProxyEventDispatcher(),
) // Implement IEventDispatcher to route through a proxy
public class ProxyEventDispatcher : IEventDispatcher
{
private readonly HttpClient _client = new();
public void DispatchEvent(LogEvent logEvent)
{
var proxyUrl = logEvent.Url.Replace(
"https://logx.optimizely.com",
"https://events-proxy.internal.example.com"
);
var content = new StringContent(
JsonSerializer.Serialize(logEvent.Params),
Encoding.UTF8, "application/json"
);
_client.PostAsync(proxyUrl, content).Wait();
}
} Step 3: Configure event batching
Section titled “Step 3: Configure event batching”The SDK batches events to reduce network overhead. Tune batch size and flush interval based on your traffic volume.
const optimizely = createInstance({
sdkKey: 'YOUR_SDK_KEY',
eventBatchSize: 50, // Flush after 50 events
eventFlushInterval: 5000, // Or every 5 seconds, whichever comes first
}); from optimizely.event.event_processor import BatchEventProcessor
event_processor = BatchEventProcessor(
event_dispatcher=optimizely.event_dispatcher.EventDispatcher(),
batch_size=50,
flush_interval=5, # seconds
)
client = optimizely.Optimizely(
sdk_key='YOUR_SDK_KEY',
event_processor=event_processor,
) var eventProcessor = new BatchEventProcessor.Builder()
.WithMaxBatchSize(50)
.WithFlushInterval(TimeSpan.FromSeconds(5))
.Build();
var optimizely = new Optimizely(
configManager,
eventProcessor
); Step 4: Firewall allowlists
Section titled “Step 4: Firewall allowlists”If your infrastructure restricts outbound traffic, allow these endpoints:
| Endpoint | Purpose | Protocol |
|---|---|---|
cdn.optimizely.com | Datafile downloads | HTTPS (443) |
logx.optimizely.com | Event tracking API | HTTPS (443) |
*.optimizely.com | Wildcard (simplest rule) | HTTPS (443) |
Troubleshooting
Section titled “Troubleshooting”| Issue | Cause | Fix |
|---|---|---|
| Datafile never updates | Firewall blocking CDN | Add cdn.optimizely.com to allowlist |
| Events not delivered | Proxy rejecting POST requests | Verify proxy passes POST with JSON body |
| High bandwidth usage | Polling interval too short | Increase to 5+ minutes for production |
| Stale flag values | Polling disabled or webhook not configured | Enable autoUpdate or set up webhook triggers |