CachedFeatureFlag shape.
Why
If you already run PostHog for analytics, feature flags can share the same API key and ingestion host. The backend evaluates flags server-side with user and organization context attached as person properties.Setup
- Add
tooling-feature-flags-posthogtoapps/backend/package.json(already present in the template). - Run
make deps-install. - Configure production:
- Set
POSTHOG_API_KEY(and optionalPOSTHOG_HOST) in the deployment environment.
Evaluation context
FeatureFlagContext maps to PostHog person properties:
userId→ distinct id (falls back toanonymous)organizationId,environment, andattributes→ person properties
Gotchas
- Multivariate flag values are exposed through
getVariant()withenabled: true. - Boolean
falseflags remain in the normalized cache withenabled: false. - Shared cache TTL is controlled by
cacheMs; request caching is always on for HTTP traffic.
