Featurevisor

Use cases

Offline feature flag evaluation

An SDK evaluates the datafile it holds, without the network. Give it a datafile at startup, refresh it when the network allows, and an outage only delays changes. Featurevisor has no service of its own to go down, so the only network dependency is the static host you publish datafiles to.

Start with a known configuration

Ship a built datafile with your application, copied from your latest published build when the application is built. In Node.js, load it from disk:

import { readFileSync } from 'node:fs'
import { createFeaturevisor } from '@featurevisor/sdk'
const bundledDatafile = JSON.parse(
readFileSync(new URL('./datafile.json', import.meta.url), 'utf8'),
)
const f = createFeaturevisor({ datafile: bundledDatafile })
const context = {
userId: 'user-4',
country: 'nl',
}
f.isEnabled('checkout', context)
f.getVariable('supportEmail', context)

A feature missing from the bundled copy reads as disabled, and a missing variable as null. Give the call a default value where that matters.

Refresh when the network is available

Fetch newer datafiles in the background, never while evaluating. A failed fetch must leave the current datafile in place:

async function refresh() {
try {
const response = await fetch(DATAFILE_URL)
if (!response.ok) throw new Error(`HTTP ${response.status}`)
const datafile = await response.json()
f.setDatafile(datafile, true)
} catch (error) {
reportRefreshFailure(error)
}
}

Define DATAFILE_URL and reportRefreshFailure in your application, and send diagnostics to your monitoring, so a datafile the SDK rejects is noticed. Never replace the instance with an empty one after a failure.

The SDK does not fetch, retry or store datafiles itself. The refresh helper from the Node.js guide avoids overlapping requests, which could otherwise apply an older response after a newer one, and the browser guide adds a cached copy.

The static host is out of reach, and the application keeps evaluating the datafile it holds for every user.

Plan for restarts and stale configuration

A datafile in memory lasts as long as the process. Starting during an outage needs the bundled copy, or one your application stored.

Record the revision in use with f.getRevision(), and alert on failed refreshes. An old copy can keep a retired flag on until a refresh succeeds, so never rely on a flag where the current authorization matters, and check on the server instead.

Previous
Loading datafiles on demand