Configuration and feature flags¶
Your apps can keep their runtime settings and feature toggles in ObjectsGrid, with history, rollback and access control: an AppConfiguration per application and environment, and a FeatureFlag per feature. For any other JSON document of your own, use a JSONObject.
Configuration¶
One AppConfiguration per application and environment, under an id you choose, <application>_<environment>. The
environment is yours (development, staging, production), not ObjectsGrid's.
curl -X POST https://apis.objectsgrid.com/appconfigurations \
-H 'X-ObjectsGrid-AccessPoint: EU' -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
-d '{"id": "web-shop_production", "application": "web-shop", "environment": "production",
"settings": {"apiBaseUrl": "https://api.example.com", "pageSize": 20, "banner": {"enabled": false}}}'
settingsis any JSON object, at most 256 KB. A second configuration with the same id is refused with409.- Every change is a version.
GET /appconfigurations/web-shop_production?version=<n>reads an earlier one, and a rollback is aPUTof it.meta.lastUpdatedBysays who changed it. - Not for secrets. Settings are returned to every caller your policy lets read them, and reach search and webhooks. Keep keys and passwords in a secret store, and let a setting name where to find them.
Read and poll¶
Read the configuration at start, then poll with the ETag of the version you hold. While nothing changed, the answer
is 304 Not Modified, with no body, and isn't billed:
curl -i https://apis.objectsgrid.com/appconfigurations/web-shop_production \
-H 'X-ObjectsGrid-AccessPoint: EU' -H "Authorization: Bearer $TOKEN" \
-H 'If-None-Match: "1764233402419837"'
# HTTP/2 304
Every object answers 304 this way. Poll every 60 seconds, or let a server subscribe to the
webhook events AppConfigurationUpdated, AppConfigurationPatched, FeatureFlagUpdated and
FeatureFlagPatched instead. Read an application's flags with one list:
GET /featureflags?where={"application": {"equals": "web-shop"}}.
Feature flags¶
A FeatureFlag's id is its key, which you choose (new-checkout). Per environment it is enabled or not, for a
percentage of users or for everyone, and always for the user keys in allow:
{"id": "new-checkout", "application": "web-shop", "owner": "checkout team", "expires": "2027-06-30",
"environments": {"staging": {"enabled": true},
"production": {"enabled": true, "rolloutPercentage": 10, "allow": ["user-1"]}}}
Evaluate a flag¶
Evaluate flags in your app, for the environment it runs in and a user key: a stable id of your user, such as their user id. Every client that follows this rule gives a user the same answer:
- The flag doesn't name the environment:
defaultEnabled(false when not given). - Not
enabled: off. - The user key is in
allow: on. - No
rolloutPercentage, or 100: on. - Otherwise, take SHA-256 of
<flag key>:<user key>. The first 4 bytes, read as an unsigned big-endian number, modulo 100, give the user's bucket. The flag is on when the bucket is belowrolloutPercentage.
Raising the percentage keeps everyone who had the feature and adds more.
async function bucket(flagKey, userKey) {
const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(flagKey + ':' + userKey));
return new DataView(digest).getUint32(0) % 100;
}
async function isEnabled(flag, environment, userKey) {
const rule = flag.environments?.[environment];
if (!rule) return flag.defaultEnabled === true;
if (!rule.enabled) return false;
if (rule.allow?.includes(userKey)) return true;
const percentage = rule.rolloutPercentage ?? 100;
return percentage >= 100 || (await bucket(flag.id, userKey)) < percentage;
}
func bucket(flagKey, userKey string) int {
sum := sha256.Sum256([]byte(flagKey + ":" + userKey))
return int(binary.BigEndian.Uint32(sum[:4]) % 100)
}
Check your version against these buckets:
| Flag key | User key | Bucket |
|---|---|---|
new-checkout |
user-1 |
83 |
new-checkout |
user-2 |
61 |
new-checkout |
user-3 |
40 |
dark-mode |
alice |
88 |
dark-mode |
bob |
35 |
Or let GraphQL evaluate them, with the same rule:
query {
featureFlagsFor(application: "web-shop", environment: "production", userKey: "user-1") { key enabled }
}
Flags are read from search, seconds behind a change.
Access¶
Your access policy decides who reads and changes configurations and flags, as for any object.
A rule on environment keeps production in a few hands:
deny if {
input.objectType == "AppConfiguration"
input.action in {"create", "update", "patch", "delete"}
input.newObject.environment == "production"
not has_role("release-manager")
}
For a browser or mobile app with a public API key, the default policy of a new
Organization Account lets anonymous callers read the AppConfigurations and FeatureFlags tagged visibility = public,
and nothing else of them: a server's configuration stays private unless you tag it. A FeatureFlag names its
environments inside one object, so a rule on environment applies to AppConfigurations; for flags, use tags.