How to add feature flags to a small SaaS
To add feature flags to a small SaaS, wrap the new code in an if that reads a flag value, store that value somewhere you can change without deploying (a database table is enough), and choose a safe default for when the lookup fails. Move to a flag service such as PostHog, GrowthBook or Unleash when you need percentage rollouts, targeting by user, or a dashboard someone else can use.
This guide shows the steps, a minimal version you can build in an hour, what three popular services offer, and the rules that keep flags from piling up. Vendor details were read on 23 November 2026.
What a flag is for
OpenFeature's introduction puts it simply: a feature flag is an if/else statement that can be controlled at runtime, so behavior changes without deploying new code. For a small team that means three things: ship unfinished work behind a switch, turn a bad change off in seconds, and show a feature to a few users before everyone.
Step by step
- List the flags you need today. Often it is one or two: "new checkout" and "beta dashboard". Do not build a platform for them.
- Create a
feature_flagstable withkey,enabled,rollout_percentandupdated_at. Add an optionalallow_listof user IDs if you want specific testers. - Write one function,
isEnabled(key, user), that every code path calls. Keep the check in one place so removing the flag later is a one-line change. - Pick a default for each flag when the lookup fails or the flag does not exist. For a risky new feature the default is off; for a kill switch on something stable, it may be on.
- Make percentage rollouts stable: hash the user ID and the flag key, and compare the result to the percentage, so a user stays in the same bucket across requests.
- Cache the table for 30 to 60 seconds in memory, so you do not query the database on every request.
- Add a date and an owner to each flag in a comment or a column, which you will need in the cleanup step.
This is enough for a solo founder. It has no audit log and no targeting UI, which is the point at which a service earns its place.
When to use a service instead
| Option | Free allowance or license | Worth knowing |
|---|---|---|
| PostHog | 1M feature flag requests per month, free tier resets monthly | On the free plan, extra requests are dropped and flags return a default quota-limited response; set per-flag defaults |
| GrowthBook | Free cloud accounts include up to 1M CDN requests per month | Open source; its docs say SDKs evaluate locally with no network requests |
| Unleash | Open source under AGPL-3.0 to self-host | Hosted Enterprise is priced per seat; check what you need before choosing |
If you already use PostHog for analytics, its flags add no new vendor; how to set up product analytics events for a new SaaS covers that side. If you want to avoid lock-in, OpenFeature is a vendor-neutral API with providers for many tools, so your code calls one interface and you can change the backend later.
Make evaluation reliable
PostHog's best practices are useful for any tool:
- Evaluate on the server when the data you need is there. The docs call server-side local evaluation the recommended default.
- Treat "not evaluated yet" differently from "off". In the client SDK a flag is
undefinedbefore flags load, which is not the same asfalse. - Evaluate once per request and reuse the result instead of asking repeatedly.
- Wrap a flag in one function if you use it in several places.
With local evaluation, the docs note a cold start of up to one polling interval, 30 seconds by default, during which flags return undefined. Use flag ?? "control" style defaults so users see something sensible.
Clean up flags
Flags become debt. A flag at 100% of users with no targeting has finished its job, and PostHog's guidance is to remove it and hardcode the winning path, or at least archive it. Stale flags are the most common cause of unnecessary billable requests there.
A routine that works for a small team:
- Review the flag table on the first of each month.
- Delete flags that have been at 100% for two weeks.
- Delete flags nobody remembers owning after asking once.
- Remove the dead code branch in the same pull request.
Test both paths
Every flag doubles the states your app can be in. Test with the flag on and off in the same test file, and keep the staging environment's flags the same as production unless you are testing a change. How to set up a staging environment for a small SaaS covers the environment side. For flags that protect an expensive or abusable endpoint, pair them with rate limiting.
Who should pick what
- One or two flags, one developer: a database table and one function.
- Already on PostHog for analytics: use its flags and set a default for every flag.
- Want open source and self-hosting: GrowthBook or Unleash, and plan for running a service.
- Worried about vendor lock-in: put OpenFeature between your code and the provider.
Frequently asked questions
Are feature flags the same as environment variables?
Environment variables change only when you redeploy or restart. A flag is read at runtime, so you can change it without shipping code and can vary it by user.
How many flags are too many?
There is no fixed number. The warning sign is flags you cannot explain, so review them monthly and remove the ones that are finished.
Do feature flags slow down my app?
A cached database lookup adds almost nothing. Network calls to a flag service on every request can, which is why local evaluation and caching are recommended.
Can I use flags for pricing plans?
You can gate features by plan with flags, but plan limits belong in your billing data. Use flags for rollout and entitlements from your billing system for what customers paid for.