Pro early access: Flipper Cloud's UI, self-hosted in your Rails app. $1,999/org/yr.

Get early access

Blog

Flipper 1.5.0: Named Instances and Faster Cloud Reads

· John Nunemaker · 8 min read

Dearest feature flagger,

1.5.0 is out, shipped on a Friday because I deploy on Fridays. It's a big one. Two headliners: more than one Flipper in the same app, and Cloud flag checks that don't touch your database at all. Then a pile of smaller things: version expressions, prefixed tables, faster checks, a security pass and Ruby 4.

Named Instances

The Problem

Picture a company with fifteen Rails apps. Each app has its own Flipper Cloud project, its own flags and its own people flipping them. That works great until a flag needs to span all of them.

Say you're rolling out chat in the top bar of every product. You want chat_in_topbar on for the same people in every app, at the same time, from one place. Until now your options were all meh:

  • Create the flag fifteen times and keep fifteen projects in sync by hand.
  • Cram everything into one giant project and give everyone access to everything.
  • Build your own little flag service on the side.

What you actually want is each app's own flags, plus one shared project for the cross-product ones.

The Fix

That's what named instances are. Declare one in your initializer and it gets its own adapter, its own features, its own groups and (optionally) its own Flipper Cloud project. The top-level Flipper doesn't change at all.

# config/initializers/flipper.rb
Flipper.configure do |config|
  config.named(:cross_app) do |cross_app|
    cross_app.adapter { Flipper::Adapters::ActiveRecord.new(table_prefix: "cross_app_") }
    cross_app.cloud(path: "_flipper/cross_app")
  end
end

CrossAppFlipper = Flipper.named(:cross_app)

Then check flags on whichever set they belong to:

Flipper.enabled?(:new_invoices, current_user)           # this app's project
CrossAppFlipper.enabled?(:chat_in_topbar, current_user) # the shared project

Flipper.cross_app and Flipper.named(:cross_app) work too. They're all the same object.

Every app installs the same named instance, points it at the shared project with its own token (FLIPPER_CLOUD_CROSS_APP_TOKEN), and now flipping chat_in_topbar in that one project flips it everywhere. The shared project has its own environments, tokens and audit history, and you can add the folks who manage those flags as project collaborators without giving them every app.

The Details I Sweated

A few things I was picky about, because getting them wrong would bite you in production:

  • Never the default token. A named instance only reads its own credentials. It will never quietly fall back to FLIPPER_CLOUD_TOKEN and mix your app's flags with the shared ones.
  • No token, no problem. In development, CI or assets:precompile, where the named token isn't set, the instance just uses its own adapter and warns once. Same as the default instance without a token.
  • No preload by default. A request that never checks a cross-app flag makes no query for them. Turn on preload per instance if most requests do.
  • Groups are per instance. Register shared groups on the named instance, and keep them (and your flipper_ids) the same in every app that shares the project. A shared gem is a nice home for them.
  • You can tell them apart. Instrumentation payloads include instance: :cross_app, logs read Flipper[cross_app], statsd uses flipper.cross_app.feature.*, and the UI takes a banner_text: so your cross-app UI looks different from the main one.
  • Tests just work. Each named instance gets its own Memory adapter in tests, reset between tests. No tokens, no tables.

What It Costs

If you don't configure any named instances, nothing changes. Default-only pages run at the same speed as before.

A check on a named instance is a hair slower than one on the default instance, about 3.5µs versus 2.4µs. That's about a microsecond, which you won't notice next to a single database query.

The named instances guide covers everything: Active Record tables and generators, groups and actor ids across apps, Cloud credentials and webhooks, mounting the UI, instrumentation and testing.

This one was built for a customer with exactly the setup above, and I put it through its paces in real Rails apps (Cloud outages included) before hitting release. If you've got a pile of apps and a few flags that belong to all of them, give it a spin and let me know how it goes.

Cloud Reads From Memory

This one you get for free.

With Cloud, the source of truth for your flags is Cloud, and Flipper already syncs a full copy of them into your local adapter. But every feature check that wasn't memoized still went to that adapter: a query to your database or a trip to Redis. Kind of silly when the whole set of flags fits in memory.

So now, when Cloud is your default (FLIPPER_CLOUD_TOKEN with the Rails engine or Flipper::Cloud.set_default), feature checks read from one in-memory copy of your flags that every thread in the process shares. No database query per check, no round trip.

Here's a feature check that isn't memoized, measured with 101 flags:

adapter 1.4 1.5
ActiveRecord (SQLite) 69.3µs 3.10µs
Redis 52.3µs 3.08µs

That's with SQLite and Redis on the same machine. A real database across the network saves more, because what's gone is the round trip.

Request preloading is skipped now too. Preloading existed to turn many queries into one, and with reads in memory there are no queries left to save. All it did was copy every flag at the start of every request. Skipping it took a request that checks 10 of those 101 flags from 211µs to 34µs.

A few things didn't change:

  • Cloud down at boot? Memory is filled from your local adapter when the process starts, so your flags are there.
  • Local adapter down? Checks keep working from memory, and the next sync writes your adapter again.
  • Named instances with a Cloud project read the same way, each from its own memory.
  • A Flipper::Cloud.new you build yourself is unchanged and still reads its local adapter.

One thing did change: other processes no longer see a change the moment it hits your database. With webhooks, they pick it up within about 10 seconds, and a change made in your app reaches them through Cloud like any other.

If you need that back, set FLIPPER_CLOUD_MEMORY_READS=false and restart. Every check reads your local adapter again, exactly like 1.4. No code change, no downgrade. More in how Cloud reads work.

Version Expressions

Gate a feature on app version with the new SemVer expression #1099. Comparing versions as strings gets it wrong ("2.10.0" < "2.9.0"), so SemVer orders them by Semantic Versioning rules, prereleases included. Handy for mobile apps where old builds hang around for months:

Flipper.enable :new_onboarding,
  Flipper.semver(Flipper.property(:app_version)).gte(Flipper.semver("2.3.1"))

More in the version expressions docs. It's in the Cloud expression builder too.

Prefixed Tables

The Active Record adapter takes a table_prefix: now #1037, #1138, #1139, so you can keep several sets of Flipper tables in one database without writing your own model classes. The flipper:active_record and flipper:update generators take --table-prefix to match. Named instances lean on this, but it works on its own too.

Flags Never Go Backward

Cloud sends a version number with every poll and webhook, and the number goes up on every change. Flipper now skips any sync older than the one it already has #1098, #1131, #1133. So a stale cached response can't flip your flags back, and a process that missed an update can't write old flags over newer ones in a shared database. That made it safe to poll in webhook mode again: every 5 minutes, as a backstop for any webhook that goes missing.

Faster Checks

Connor Shea and Clément Joubert went after the hot path. Gate checks bail out early instead of checking every gate type #1029, enabled? wraps actors in one pass #1030, Active Record builds gate results in one pass #1031, API requests stop walking the feature set over and over #1039, and sharing gate instances cuts about a third of per-request allocations #1064, #1065. Thank you both!

A Security Pass

I went through the gem with a fine-tooth comb. The Cloud url has to be https #1016. Webhook signatures expire after five minutes #1022, and empty sync secrets are rejected #1041. HTTP debug output redacts tokens #1015, and feature keys are escaped in HTTP adapter requests #1009. The API parses its params much more strictly #1045, #1047, imports have a size cap #1014, and UI tooltips are escaped #1006. None of these were being exploited that I know of. They're just the sharp edges you file down.

Ruby 4 and Rails 8.1

CI now runs Ruby 3.4 and 4.0, Rails 8.1 and Rack 3 #1087, #1088, #1089. On Ruby 4, logger and pstore aren't default gems anymore, so Flipper declares them and loads without Rails.

Smaller Changes

  • The UI shows expressions. A feature that's on through an expression says so instead of looking off #1078.
  • Feature#add works with the Strict adapter #1126.
  • Feature names lose invisible characters like zero-width spaces, and the UI normalizes new names #1027, #1033, #1043, #1135.
  • An expression with the wrong type of value fails just that expression, and an unknown expression leaves its gate closed, instead of enabled? raising #1017, #1084, #1091, #1123.
  • Preloaded flags reload after local changes #1100, and a full preload stops reading the adapter for flags that don't exist #1104.
  • Read-only adapters stay read-only when cached or wrapped, and imports through them are blocked #1040, #1083, #1102, #1103.
  • The CLI has flipper --version #1090, runs without bundle exec #1071, prints help without loading your app #1093, #1094, prints usage errors instead of backtraces #1063, #1085, #1136, and asks for a token when flipper cloud push has none #1067.
  • The API answers 405 for methods it doesn't support, the UI answers HEAD requests, and both handle requests with no body #1107, #1115, #1116, #1117, #1118.
  • The UI shows the actor limit as a form error #1110 and can remove an unregistered group #1112 or an actor id with a comma in it #1113.
  • The UI sheds 8,795 lines of unused jQuery #1111, and its Cloud logo goes from 170 KB to 14 KB #1114.
  • The Redis and Mongo adapters refuse a feature named flipper_features #1066.
  • flipper-redis supports redis-rb older than 7 #1052, Redis cache entries can skip expiry #1125, and race_condition_ttl works in the ActiveSupport cache adapter #1018.
  • Pollers and memory adapters are fork-safe #1038, and concurrent memoization is fixed #1012.
  • The Active Record adapter waits for Active Record to load #999, #1092 and works with Rails main #1003.
  • Rollout imports bring over its :all group #1121.
  • The "Migrate to Flipper Cloud" UI section can be turned off #1005.
  • feature_operation instrumentation includes the feature #998, and the statsd subscriber stopped printing sync and telemetry events #1077.
  • The gems package only the files they need at runtime #1070, #1073.

The full list is in the 1.4.2 to 1.5.0 compare.

Thank You

Big thanks to everyone who sent a pull request this release: Benedikt Deicke, Kyle Keesling, Stuart Campbell, Kristján Oddsson, Connor Shea, Lucas Arantes, Daniel Pepper and Clément Joubert.

Sincerely,
Nunes

Ready to try it out?

Get audit history, rollbacks, advanced permissions, analytics, and all of your projects in one place.


Prefer our Cloudless option?

You can choose from several tiers to sponsor Flipper on GitHub and get some great benefits!

The Friday Deploy

News and open source releases for all things Flipper. Unsubscribe anytime.

Have questions? Need help?

Email us any time or head on over to our documentation or status page for the latest on the app or API.

Ready to take Flipper for a swim?

No credit card required. 14-day free trial. And customer support directly from the developers.