Context best practises
- Each Context should map to a single, well-defined business object in your application. E.g., a User, a Session, a Team, a Project, and so on: each of these should have a single Context.
- If your application has unique identifiers, reuse them to identify contexts.
If your application's identifiers are not guaranteed to be unique across different types of object, prefix them with the type when creating keys in featuresd.
For example,
user_1andteam_1.
Patterns
There are a variety of common ways you may want to structure your Contexts.
Default-only
This is an extremely simple way to get started with feature flagging.
Instead of creating any Contexts representing business objects, you assign all Feature values to the default Context.
This means that all value changes will globally affect all users.
This does not offer enough granularity to, for example, enable certain features for developers only in production. It does, however, allow you to enable different features across different deployments of featuresd.
For example, you could set a flag value new_ui=yes in your locally-hosted development environment, but leave it set to no in production until you decide to ship the feature.
This allows you to perform continuous deployment, but not to perform any testing in your production environment with a subset of users.
Context per user
- each user has a Context
- set feature values for specific users
- can allow access to only a few people, yay
- might be annoying to set access for a whole team, or for all developers, boo
User categories
- use a prototype to give each user one or more categories
- set feature values on categories
Context per device
- if app has stable session IDs (e.g. session cookies in browser) or device IDs (e.g. remember cookies) this may be usable
- backend should automatically set feature values based on session info; sessions usually change too much to manage this manually
- good use-case for Segments, which don't exist yet :'(
Multiple environments
If you deploy a single instance of featuresd across multiple environments, you should add top-level Contexts for each environment.