Real-time cohorts
To try real-time cohorts, join the beta. Behavior and limits on this page can change before general availability.
What is a real-time cohort?
A dynamic cohort is a list of people that PostHog rebuilds for you on a schedule. A real-time cohort is a dynamic cohort that PostHog also keeps up to date as events arrive, instead of waiting for the next rebuild.
It solves one problem. You can target a feature flag at a cohort built from events.
Cohorts built from person properties, like "email ends with @acme.com", have always worked in feature flags, because PostHog can check a person property while it evaluates the flag. Cohorts built from events, like "completed signed up in the last 30 days", have not. Answering "has this person done that?" means reading their event history, which is too slow to do on every flag request.
A real-time cohort answers the question in advance. PostHog keeps a record of who is in the cohort and updates it as events come in, so a flag only has to look it up.
What changes, and what doesn't
Real-time cohorts change feature flag targeting. Experiments and surveys pick their audience through feature flags, so they can target real-time cohorts too.
Insights, dashboards, and the person list and count on the cohort page don't change. They still come from the standard cohort calculation, on its normal schedule.
Real-time cohorts are evaluated on PostHog's servers. A server-side SDK can't evaluate a flag that targets one locally. Checks of that flag fall back to a /flags request, and return no value if you have told the SDK to evaluate only locally.
Join the beta
- Open your feature previews and turn on real-time cohorts.
- PostHog sets up the project you're in. This takes about a minute. While it runs, the cohorts page says "Setting up realtime cohorts for this project", and when it finishes, PostHog shows "Realtime cohorts are on for this project."
Feature previews usually change PostHog for you alone. This one works per project. When you opt in, the project you're in joins the beta, and so does each project you open while you stay opted in. Once a project joins, every member sees real-time cohorts, whether or not they opted in themselves. Any member who can view the project's cohorts can opt the project in.
If you joined the waitlist before the beta opened, you're already opted in. Your projects join the next time you open them in PostHog.
Joining doesn't turn real-time on for any cohort. Every cohort in the project starts with real-time off, so your flags, cohorts, and insights work as before until you turn real-time on for a cohort.
A project can't leave the beta. If you turn the feature preview off, your other projects stop joining, but a project that has joined keeps real-time cohorts. To stop using them, turn real-time off for each cohort.
If the project doesn't join, the cohorts page says why:
- "Realtime cohorts aren't open to new projects yet" means PostHog isn't taking new projects at the moment. You don't need to do anything. Once joining opens, the project joins the next time a member who opted in opens it.
- "Realtime cohorts couldn't be turned on for this project automatically" means PostHog can't add the project by itself. Contact support.
- "Setting up realtime cohorts for this project didn't finish" means the setup failed. PostHog tries again the next time a member who opted in opens the project, an hour or more later.
Which cohorts qualify
PostHog works out from the criteria you choose whether a cohort can be real-time. A cohort with event criteria that qualifies still needs real-time turned on before a feature flag can target it. A cohort with only person property criteria needs nothing, because flags read those properties from the person as they evaluate.
A cohort qualifies when every one of its criteria is one of these:
| Criteria | Example |
|---|---|
| Any person property criteria | email does not end with "@gmail.com" |
| Completed an event | Completed signed up in the last 30 days |
| Did not complete an event | Did not complete signed up in the last 30 days |
| Completed an event multiple times | Completed watched video at least 5 times in the last 2 weeks |
| Another cohort, if that cohort also qualifies | In cohort "Power users" |
You can narrow the event criteria by event property, such as completed purchase where plan equals "pro".
Three criteria negate: "Did not complete event", "Do not have the property", and "Not in cohort". Each one needs a criterion that isn't negated to bound it, either in the same group or in another group joined with "all". The cohort builder refuses to save a cohort that leaves a negation unbounded, or that puts one under "any", with the error "'Did not complete event' is a negative cohort criteria. Negation criteria can only be used when matching all criteria (AND), and must be accompanied by at least one positive matching criteria." Create the same cohort through the API and the save goes through, cohort_type still reads "realtime", but PostHog never builds its membership record, so a flag that targets it matches nobody.
What stops a cohort qualifying
A single criterion from this list makes the whole cohort fall back to the standard calculation, and a feature flag can't use it:
- Sequences. Both "Completed a sequence of events" and "Did not complete a sequence of events".
- Lifecycle criteria. Every option under the "Lifecycle" heading in the cohort builder: completed an event for the first time, completed an event regularly, stopped doing an event, and started doing an event again.
- Actions. Event criteria have to name an event. Pointing the same criterion at an action isn't supported yet.
- The "First seen" person criterion, which reads when PostHog first saw the person rather than a person property.
- Event criteria that look back more than 400 days, such as "in the last 2 years", or a date range that starts more than 400 days ago.
- "Filter out internal and test users" turned on for the cohort.
- More than 20 million people in the cohort.
Static cohorts are never real-time. They don't change on their own, and they already work in feature flags.
Turn real-time on for a cohort
In a project that has joined the beta, each cohort with event criteria that qualifies has its own real-time switch, and it starts off. While it's off, PostHog doesn't keep the cohort's membership up to date, and feature flags can't target it.
A cohort with only person property criteria doesn't need the switch, and its page usually doesn't show one. Feature flags can always target it.
To turn it on, open the cohort and click Turn on realtime next to Flag targeting. When you create a cohort with event criteria, you can check Turn on realtime before you save it instead.
PostHog then works through the cohort's past events to find out who is in it now. The app calls this preparing the cohort. However small the cohort, it takes about 20 minutes at the earliest, and longer for cohorts that look a long way back or match a lot of events. The Flag targeting row on the cohort page shows the progress, and reads Available once flags can target the cohort.
Turning real-time on for a cohort also turns it on for the real-time cohorts it includes, and PostHog prepares those too. You need edit access to each of them.
What the cohort page and the tags tell you
The Flag targeting row on the cohort page, and the tag next to the cohort in the cohort list and the feature flag cohort picker, say whether a flag can target the cohort now:
| Flag targeting row | Tag | What it means |
|---|---|---|
| Available, with a lightning bolt | Realtime | Real-time is on and the cohort is ready. Flags can target it. |
| Preparing | Realtime · preparing | PostHog is working through the cohort's past events. Flags can target it once this finishes. |
| Off | Realtime off | The cohort qualifies, but real-time is off. Click Turn on realtime. |
| Unavailable | Realtime · unavailable | Real-time is on, but nothing is preparing the cohort. Hover the info icon for the reason, and contact support. |
| Unavailable | No flag targeting | The cohort doesn't qualify, so only the standard calculation runs for it. |
| Available, without a bolt | No tag | The cohort has only person property criteria. Flags read those from the person as they evaluate, so they can always target it. |
Turn real-time off
Click Turn off realtime on the cohort's page. PostHog stops keeping the cohort up to date. If the cohort has event criteria, flags can't target it anymore. Flags keep targeting a cohort with only person property criteria. If you turn real-time on again later, PostHog prepares the cohort from its past events again.
PostHog refuses to turn real-time off while something still reads the cohort's real-time membership:
- A feature flag that targets the cohort, even a disabled one, when the cohort has event criteria. Remove the cohort from the flag, or archive the flag.
- An active workflow that uses the cohort.
- Another cohort with real-time on that includes the cohort.
Using a real-time cohort in a feature flag
- Create the cohort, or edit its criteria, as you normally would.
- If the cohort has event criteria, turn real-time on for it, and wait until the Flag targeting row reads Available. A cohort with only person property criteria skips this step.
- Add the cohort to a feature flag release condition.
PostHog saves the flag only once the cohort is ready. If the flag won't save, the error tells you what's missing:
- "Realtime is off for cohort 'X'. Turn it on from the cohort's page, and feature flags can target the cohort once it's ready." means real-time isn't on for the cohort yet.
- "Cohort 'X' isn't ready for feature flags yet" means PostHog is still preparing the cohort. Open the cohort to check its progress, and save again once it reads Available. If it reads Unavailable, contact support.
- "Cohort 'X' has an event-based condition ... and cannot be used in feature flags" means either the cohort doesn't qualify, or the project hasn't joined the beta. Compare its criteria against the list above first.
Editing a cohort a flag uses
While an active feature flag uses a cohort that has event criteria, you can't change that cohort's criteria at all, not even the person property ones. The save fails with "Behavioral filters cannot be added to cohorts used in feature flags."
This is on purpose. New criteria make the existing record wrong, and PostHog has to prepare the cohort again before a flag can trust it. To make the change:
- Remove the cohort from every active flag that uses it.
- Edit and save the cohort.
- Wait until the Flag targeting row reads Available again, then add the cohort back to the flags.
The same error blocks a rename from the cohort page, because saving there sends the criteria too. To rename a cohort a flag is using, PATCH only the name field through the cohorts API.
How up to date is it?
- People join and leave as their events arrive. Expect the change to reach feature flags in a minute or two.
- Time ranges expire on their own. Someone who matched "completed
signed upin the last 30 days" drops out once their last matching event is older than 30 days, even if they send nothing new. - The person count and person list on the cohort page are not real-time. They come from the standard calculation.
Pricing
Real-time cohorts are part of Feature Flags, and they cost nothing extra during the beta. A flag that targets a real-time cohort is billed like any other flag, per /flags request.
Local evaluation can't resolve a flag that targets a real-time cohort. If you use it, each check of that flag still makes a /flags request, and PostHog bills that request. See cutting feature flag costs for how requests are counted.
Before general availability, plans will get limits on how many cohorts can have real-time on and on how far back their criteria can look.
FAQ
How do I tell whether a cohort is real-time?
Open the cohort and read the Flag targeting row, or check its tag in the cohort list. The table above explains each one.
Through the cohorts API, read realtime.state. It is ready when flags can target the cohort. realtime_enabled says whether real-time is on, and cohort_type reads "realtime" when the criteria qualify. realtime is null in a project that hasn't joined the beta, and for a cohort with neither event nor person property criteria, such as one that only includes another cohort.
Can I turn real-time on through the API?
Yes, for a project that has joined. Send "realtime_enabled": true when you create a cohort. If PostHog can't turn real-time on for it, the cohort still saves, and realtime_enabled comes back false. For an existing cohort, POST {"enabled": true} to /api/projects/:project_id/cohorts/:id/realtime/, or {"enabled": false} to turn it off. A refused turn-on or turn-off returns an error that says why.
To join the beta, opt in from the PostHog app. API keys can't join a project.
Do I still need the static cohort workaround?
Only for cohorts that don't qualify, such as ones with sequence or lifecycle criteria, and in projects that haven't joined the beta. There, duplicating a dynamic cohort as a static one is still the way to target people who completed an event.
Why did my cohort stop qualifying?
Either a criterion changed to one on the list above, or the cohort grew past 20 million people. Both send it back to the standard calculation. If this happens to a cohort a feature flag is already using, tell us so we can check the flag with you.





