- Date
A Guide to Mastering PostHog Feature Flags
Andrii Romasiun
PostHog feature flags are an incredibly powerful way to separate deploying your code from releasing a new feature. This simple-sounding concept completely changes how you build and ship software, giving your team precise control over who sees what, and when—all without needing another deployment.
Why PostHog Feature Flags Are Your Secret Weapon
Before we get into the nitty-gritty of setting things up, it's worth taking a moment to appreciate what this shift in mindset really means. By wrapping a new piece of functionality in a feature flag, you can merge your code and deploy it "dark." It's live in production, but no one sees it until you're ready.

This fundamentally de-risks the entire development process, turning what used to be a high-stress event into a controlled, iterative rollout.
Mitigate Risk and Release with Confidence
The most immediate win is reducing risk. Forget the old "big bang" releases where a feature went live for everyone at once, followed by a frantic scramble to fix any surprise bugs. With feature flags, you can orchestrate a much safer, phased rollout.
A typical rollout strategy might look something like this:
- Internal Dogfooding: First, you turn the feature on only for your internal team. This lets you catch obvious bugs and gather feedback in a real production environment.
- Targeted Betas: Next, you can roll it out to a specific cohort of users, like a beta group or power users who love getting early access.
- Percentage Rollouts: Finally, you can slowly open the floodgates. Start by enabling the feature for 1% of your user base, then gradually ramp up to 10%, 50%, and eventually 100%, all while keeping a close eye on performance metrics and user feedback.
This approach turns your feature releases into a non-event. If something goes wrong, you don't need an emergency hotfix or a complex rollback. You just flip the switch and turn the flag off, instantly disabling the feature while your team calmly investigates.
Run Powerful Experiments and Get Answers
Beyond just playing it safe, feature flags are the backbone of data-driven product development. Because PostHog ties flags directly to its analytics suite, you can easily run A/B tests to validate your ideas before committing to a full launch.
Want to know if a new onboarding flow actually improves activation? Or if changing a button's color increases clicks? You can assign users to different flag variants, measure the impact on your key metrics, and get real answers. This combination of remote control and deep user insight is why so many fast-moving teams rely on it.
In fact, an incredible 54% of Y Combinator's Winter 2023 batch use PostHog for exactly this reason. It's one of their most-used tools for a reason—you can see why startups trust PostHog's approach and the data behind this trend for yourself.
To help you visualize how this works in practice, here are some of the most common ways teams use PostHog's feature flags.
PostHog Feature Flag Use Cases at a Glance
| Use Case | Description | Key Benefit |
|---|---|---|
| Phased Rollouts | Gradually release a new feature to an increasing percentage of users. | Minimize the blast radius of bugs and monitor performance under real-world load. |
| A/B/n Experiments | Serve multiple variations of a feature or UI to different user segments. | Make data-driven decisions by measuring which variant performs best against your goals. |
| Beta Programs | Enable features for a specific list of users or a cohort defined by properties. | Get targeted feedback from power users or an early access group before a general release. |
| Kill Switches | Instantly disable a feature in production without a new deployment. | Quickly respond to critical bugs or performance issues, protecting the user experience. |
| Trunk-Based Development | Merge incomplete features into the main branch behind a flag. | Keep development velocity high and avoid complex, long-lived feature branches. |
This table is just the starting point. As your team gets more comfortable with flags, you'll discover they are an essential tool for building better products, faster.
Putting Your First Feature Flag Into Production
Jumping into feature flags with PostHog is a lot faster than you might think. We're not talking about weeks of setup here. You can get your first flag live in just a few minutes, going from a concept to a controlled rollout pretty quickly. The whole process boils down to two main things: getting the right SDK into your project and then wrapping your new feature in a simple 'if' statement.
First things first, you need to add the PostHog library to your codebase. They have a whole suite of SDKs, so you can just grab the one that fits your stack. Whether you're working in a React frontend, a Node.js backend, or even a mobile app, you're covered.
For a typical web app, you'd just run:npm install posthog-js
And if you're working on the server side with Node.js, you'll want this one instead:npm install posthog-node
Once that's installed, you'll need to initialize it. This is a one-time setup that usually lives at the entry point of your application—think App.js or your main server file. You'll need to grab your project API key and your PostHog instance URL, which you can find right in your project settings.
SDK Initialization and Bootstrapping
When you initialize the library, it’s a great idea to "bootstrap" the flags. This is a crucial step that loads all the current flag values right away. Why does this matter? It completely prevents that jarring flicker where a user sees the old UI for a split second before the new feature pops in.
A common pattern is to fetch the flags on the server for a specific user and then pass those values down to your client-side code. Your client then starts up with all the flags already in place, making the user experience feel instant and seamless.
Wrapping Your Feature in Code
With the SDK initialized, you're ready to protect your new feature. This is where the magic happens. You're simply going to ask the PostHog SDK whether a specific flag is turned on for the person using your app.
Let's say you're about to launch a new "AI Assistant" button. The code is surprisingly simple.
import { useFeatureFlagEnabled } from 'posthog-js/react'
function Dashboard() {
const isAiAssistantEnabled = useFeatureFlagEnabled('ai-assistant-button')
return (
Welcome to your Dashboard
{isAiAssistantEnabled && } {/_ Rest of your dashboard components _/}It’s that clean. If the ai-assistant-button flag is active for the user, the AiAssistantButton component renders. If not, it's as if the code doesn't even exist for them. Your feature is deployed, but its visibility is now fully in your hands through the PostHog dashboard. This core principle holds true whether you use a dedicated feature flag service or build something simpler yourself.
Creating the Flag in the PostHog UI
The final piece is to actually create the flag in your PostHog dashboard.
- Head over to the Feature Flags tab in your project.
- Click "New feature flag" and enter a key. This has to be an exact match to the one in your code—in our case,
ai-assistant-button. - Now, define your release conditions. A great way to start is to roll it out to 100% of users but then add a property filter to target only your own user account.
This is a pro-tip for safe, real-world testing. By targeting your own user ID, you can see and interact with the feature on the live production site. Meanwhile, none of your actual users will see a thing. This lets you confirm everything works end-to-end before you even think about a broader rollout.
Executing Advanced Targeting and Phased Rollouts
A simple on/off switch for a feature is fine, but the real magic of PostHog feature flags happens when you move beyond that. A basic flag is great for testing things yourself, but what transforms your release process is the ability to target with precision. It’s no longer about just asking if a feature is on, but who should see it and when.
The most common and powerful strategy here is the percentage-based rollout. Instead of flipping the switch for everyone and hoping for the best, you gradually introduce a new feature to your user base. This is your number one tool for managing risk.
Let's say you're launching a redesigned checkout flow. Pushing that live to 100% of users is a high-stakes gamble; a single bug could tank your revenue. A much smarter approach is to use a percentage-based rollout in PostHog. You can start by enabling the new flow for just 1% of your users. This creates a small, manageable group to watch for errors or any dip in conversion rates.
If the data looks good and no fires erupt, you can dial it up to 10%, then 50%, and finally to 100%. You gain more confidence at every single step.
Targeting Specific User Cohorts
Percentage rollouts are just one piece of the puzzle. True precision comes when you combine them with user properties and cohorts. A cohort is simply a group of users you define based on who they are or what they've done in your product. This is how you create laser-focused segments for your releases.
For instance, you could build a cohort of "Power Users"—people who have triggered a 'Project Created' event more than 20 times in the last month. You can then release a new beta feature only to this group. You know the feedback you get will be top-notch because it's coming from people who live and breathe your product.
Here are a few other ways I’ve seen teams use this effectively:
- Geographic Targeting: Rolling out a new payment option only to users in Germany by filtering on the
countryproperty. - Plan-Based Access: Making an advanced analytics dashboard visible only to users on "Pro" or "Enterprise" plans by checking a custom
plan_typeproperty. - Behavioral Targeting: Displaying a new onboarding tutorial exclusively to users who signed up in the last 7 days but haven't completed a key activation event yet.
This simple diagram breaks down how you go from writing the code to testing it with a specific audience.

You wrap your new functionality in a flag, define who gets to see it in PostHog, and then measure the impact on that targeted group.
Building Your Rollout Strategy
When you start layering these methods, you gain an incredible amount of control. You can stack conditions to create incredibly specific release criteria. For example, you could roll out a new feature to 25% of users who are also on the free plan and are located in the United States.
This completely changes how you think about shipping software. Deployments stop being big, scary, monolithic events. Instead, they become continuous, controlled experiments where every single release is an opportunity to learn something new about your users.
The best part is that PostHog evaluates these complex rules instantly. This lets you build dynamic experiences that adapt to who the user is and what they do—all without cluttering your codebase with complicated if/else logic. This is how you graduate from just shipping features to strategically delivering real value.
Running Experiments with Feature Flags
Feature flags are more than just an on/off switch or a safety net. They're the core engine for running powerful product experiments. By connecting flags directly to PostHog's built-in A/B testing suite, you can finally stop guessing and start making decisions with real statistical confidence.
This is how you close the loop between shipping a feature and actually understanding its impact. You can test new variations, measure how they affect user behavior, and iterate on what you learn—all from one place.
Creating and Measuring a Multivariate Experiment
Let’s walk through a common scenario. Imagine you want to test a couple of new headlines for your pricing page. The goal is simple: find out which one gets more users to sign up.
To do this in PostHog, you’d create a multivariate feature flag—let's call it pricing-page-headline. You would then set up three variants:
control: Your original, existing headline.variant-a: A benefit-driven option, like "Simple Pricing for Fast-Moving Teams."variant-b: An outcome-focused one, such as "Unlock Growth with Our Powerful Plans."
You can then configure the flag to split traffic evenly, sending 33% of your users to each version. In your application's code, you simply check the flag's value to render the correct headline for each user. It's surprisingly straightforward.
Once the flag is live, you head over to PostHog’s Experiments tab. This is where you tell PostHog what success looks like. You can define a primary goal, like a custom event ('user signed up') or even an increase in retention. PostHog then automatically starts tracking how each variant performs against that goal.
PostHog handles all the heavy statistical lifting for you. It crunches the numbers on conversion rates, monitors for statistical significance, and alerts you when a clear winner emerges. This completely removes the need for manual spreadsheet calculations or third-party tools.
If you want to get a rough idea of how long your test might need to run, you can use an A/B test calculator to estimate your required sample size beforehand.
Tying Experiments to Real-World Outcomes
The real magic happens when you tie these experiments to tangible business goals. For example, a startup could use a feature flag to show a new in-app survey only to a specific segment of highly engaged users.
This isn't just a hypothetical. The team at Purple Wave saw their user survey response rates jump from a lackluster 14% to an incredible 25%—a nearly twofold increase. They achieved this by using PostHog flags to deliver surveys with surgical precision. You can read more about how they leveraged precise targeting to get these results.
That example shows how PostHog feature flags evolve from a simple toggle into a strategic growth tool. Whether you're testing a new UI, optimizing a conversion funnel, or gathering feedback, linking experiments to flags gives you a clear, quantitative way to measure what works. This continuous loop—hypothesize, test, learn—is what modern product development is all about.
Managing Flag Performance and Reliability

Let's be honest, when you’re checking hundreds of feature flags on every page load, performance isn't just a feature—it's everything. A slow flag evaluation means a slow app, which leads to frustrated users. This is an area where PostHog’s architecture really delivers, focusing on both speed and resilience right from the start.
One of the smartest things they did was implement local evaluation for their server-side SDKs. Instead of pinging a remote server for every single flag check, the SDKs download the flag rules and evaluate them directly in your server's memory. This completely cuts out network latency, making flag checks almost instantaneous.
Ensuring Speed at Scale
While local evaluation is the gold standard for speed, PostHog didn't stop there. They also put a massive effort into optimizing their remote evaluation service. In a bold move, the team rewrote their entire feature flag service, migrating from Python to Rust—a language famous for its raw performance and memory safety.
This wasn't just some minor refactor. The results were astounding. The new service cut their compute costs by 68% (from $8.8k to $2.8k per month) and handled the same traffic volume with only 32% of the original resources. For you, the end-user, this translates into dramatically lower latency and a much more reliable service. You can read the full story on this impressive engineering feat on their blog.
This commitment to the underlying infrastructure means your app stays snappy, even as you add more and more flags. Of course, you still need to keep an eye on your own app's speed, which is where solid performance monitoring comes into play.
Designing for Reliability and Maintenance
Speed is one thing, but reliability is just as vital. A flagging system that goes down can freeze your application or, even worse, roll back features that users depend on. After their big migration, PostHog’s new architecture proved its stability, hitting zero outages in the first three months.
But what about when your code breaks? That's where the kill switch comes in. Imagine you release a new feature and suddenly your error monitoring goes haywire. Instead of a frantic scramble for a hotfix and a new deployment, you can just flip a switch in the PostHog dashboard. The problematic feature is instantly disabled, and the crisis is averted in seconds.
This instant-off capability is your ultimate safety net. It completely decouples incident response from your deployment cycle, empowering anyone on the team to contain a problem without waiting on an emergency code change.
Finally, we need to talk about technical debt. Flags are not meant to live forever. A good housekeeping process is essential to keep your system clean. Once a feature is fully rolled out and you know it's stable, the flag's job is done.
Cleaning up is straightforward:
- Go into your codebase and remove the conditional logic tied to the flag. The feature is now a permanent part of the code.
- Head over to your PostHog dashboard and archive or delete the flag.
This simple routine prevents your flag list from becoming a cluttered mess that confuses developers and slows down development. It ensures your feature flagging system remains a sharp, powerful tool instead of a source of future headaches.
Common Questions About PostHog Feature Flags
Once you get into the thick of using PostHog feature flags, a few practical questions almost always come up. Here are the answers to the ones I hear most often from teams just getting started.
What's the Difference Between Local and Remote Evaluation?
Understanding this is key to getting the performance you expect. Think of it as a choice between speed and real-time updates.
Local evaluation is the default for most server-side SDKs. Your application downloads the flag rules and keeps a cached copy. When your code needs to check a flag, it happens instantly—no network call needed. This is perfect for performance-sensitive backend logic where you can't afford any latency.
Remote evaluation is what you’ll typically use on the client-side, like in a browser or mobile app. The SDK makes a quick call to PostHog's servers to get the most current flag status for that specific user. While there’s a tiny bit of network latency, it ensures the user sees the correct version of a feature, even if you just changed the rule a second ago.
How Do I Clean Up Old PostHog Feature Flags?
This is a big one. If you don't stay on top of old flags, you'll drown in technical debt. Once a feature has been rolled out to 100% of users and has been running smoothly for a couple of weeks, it's time to retire the flag.
The process is straightforward:
- First, kill the code. Dive into your codebase and rip out the conditional
if/elselogic that checks the flag. Your new feature is now just a permanent part of the application. - Then, archive the flag. Head over to your PostHog dashboard and archive it. This gets it out of your active list, keeping things tidy and preventing anyone from getting confused by old, irrelevant flags.
Don't skip this housekeeping. I've seen teams end up with hundreds of active flags, making the code a nightmare to navigate and creating a real risk of activating an old, broken feature by mistake. A clean flag list is a happy flag list.
Can I Use PostHog Feature Flags Without Product Analytics?
Absolutely. You can use PostHog's feature flags as a standalone tool. But honestly, you’d be missing out on its biggest strength.
The magic happens when flags and analytics work together. When they're connected, PostHog automatically links a feature release to what users are actually doing. You can see, clear as day, if enabling a new checkout flow tanks your conversion rate or if a new onboarding step increases user activation. Without analytics, you're just shipping features and hoping for the best.
Are PostHog Feature Flags Compliant with GDPR?
Yes, and the platform is built with privacy in mind. You have total control over the data you send. This means you can do some pretty sophisticated targeting without ever touching personally identifiable information (PII).
For example, you can target users based on anonymous IDs or general attributes that don't identify a person, like is_premium_user: true. For companies with really strict data residency requirements, PostHog even offers a self-hosted option. This puts you in the driver's seat, giving you full control over your data and infrastructure to meet GDPR and other privacy standards.
At Swetrix, we believe in making data-driven decisions simple and privacy-friendly. Our platform offers everything from web analytics and A/B testing to feature flags, all without compromising user privacy. See how our cookieless analytics can give you the insights you need to grow. Start your free trial today at swetrix.com.