Feature entitlements

In B2B SaaS, a typical use case is to manage feature access based on the customer’s subscription level. This means enforcing feature access at the company level, not the user level.

This is how Bucket is used to manage feature entitlements.

Why use flags for this use case?

There are multiple ways to control feature access: You can hard-code it, use a dedicated billing service, or use feature flags.

If you have a complex billing structure, adding a dedicated service to your stack likely makes the most sense.

If your billing is relatively straightforward, you can use flags for it. This keeps the number of services to a minimum and lets you roll out new features and manage access from one interface.

However, not all flagging services are the same. Most are focused on end-users rather than company accounts.

Bucket's feature flagging is purpose-built for B2B with native support for gating features at the company subscription level.

Gate a feature based on subscription plan

Step 1: Initialize Bucket

Choose an SDK to get started, if you haven't already. Bucket needs to know who the authenticated user is and which company they belong to. We attched attributes metadata, like what subscription plan the company is currently on.

// identify user
bucket.user(userId1356, {
    name: “Rasmus Makwarth”,
});

// associate user with company
bucket.company(companyId51, {
    name: “Acme Inc.”,
    plan: “business”,
});

Bucket now understands that Rasmus works for Acme Inc. and Acme Inc. is on the Business subscription plan.

You can send company attributes as part of the user sign in event, via a nightly job, or use updateCompany() when the attribute value changes.

Step 2: Group companies by plan

Next, we need to group companies on the "Business" subscription plan.

We do this using segments. Segments let you group company accounts based on various filters, including company attributes like subscription plans.

In Bucket, segments are automatically aggregated at the company level. This means creating a segment for "Business" plan customers is as simple as:

Company attribute "plan" equals "business"

You can do this for all plans. For example:

  • Starter

  • Business

  • Enterprise

Step 3: Gate the feature

Let’s say you have an export feature that's only available to customers on the "Business" or "Enterprise" plans. To gate this feature with Bucket, you create a new feature called “Export to CSV”. A feature can be as small as a button or as big as a product area.

Each feature comes with a feature key, like export-to-csv, which you wrap your feature in inside your codebase.

In React, it’d look like this:

const { isEnabled } = useFeature("export-to-csv");

if(isEnabled) { 

      // access to csv export!

}

With the feature code in, you can now manage access to this feature via the Bucket UI.

In this case, we’ll set the feature targeting access rules to be:

Companies in the segment Business or Enterprise

Here’s what that looks like in the Bucket UI:

That’s it!

Every time a company enters either of these segments, they’ll automatically get access to the "Export to CSV" feature. Similarly, if they downgrade, they lose access.

Grant individual companies access

If you need to grant individual companies access to a feature when they don't have the required subscription plan, you can add them manually.

Simply add a new rule and use the "any of" operator.

How to handle usage-based gating

This use case isn't natively supported by Bucket yet, but Bucket is flexible enough to handle it in some cases.

If your features are restricted by plan and usage, like only allowing 10,000 API requests/mo on the Business plan, you can do the following:

Step 1: Let Bucket know of the current usage

Send usage metrics to Bucket using company attributes.

For example, you can send the company's current usage metric to Bucket at an hourly or daily interval.

bucket.companyUpdate(companyId51, {
    apiRequestsCurrentMonth: 7930
});

Step 2: Gate using usage attribute

Then, add this custom attribute metric to your targeting rules.

Last updated