Tech Spotlight: Implementing your first feature flag
copy gray iconlinkedin graytwitter grey

Tech Spotlight: Implementing your first feature flag

November 16, 2022

One of the most popular models for releasing software is the introduction of small iterative changes while safely building towards a more complete product. One of the benefits of this approach is ensuring a tight feedback loop while releasing new features. If the feature isn’t performing as expected, you can quickly course-correct to prevent making costly investments on a feature that won’t provide a meaningful return. A common tool that you may use to help control new feature releases and to monitor the success of that feature is called a feature flag.

With a quick Google search, you’ll find many service options that can help you implement feature flags (GrowthBook, Optimizely, etc). These services can give developers a means to get actionable data into the hands of a product team. That data is used to safely roll out new features, refine ideas quickly, and have confidence in knowing when you’ve done something that works well.

At Pinwheel, we use an experimentation framework called Statsig, which will be used for the examples below. If you’d like to follow along, your first five million Statsig events are free which provides plenty of room to explore the core features and make a determination about whether it makes sense for your team. By the end of this article, you’ll understand a few core concepts of an experiment framework and how to set up your first feature gate.

We ❤️ Python at Pinwheel, so the code snippets below will leverage the Python SDK that Statsig offers, but they currently support client and server SDKs for thirteen languages.

The power of an experiment framework comes from its flexibility. The concept of an “experiment” is very loose, so we’re constantly innovating new ways to derive value from  Statsig across all of our engineering teams. Common examples include:

  • A/B test a UX change to one of our public facing products
  • Gate access to a feature for a subset of customers
  • Controlled rollout for a change to one of our internal services

Before we write any code, we need to cover a couple of important fundamentals and handle some basic configuration inside Statsig’s Feature Gates menu.

Statsig’s product offering for implementing feature flags is called a Feature Gate.

Feature Gates

Feature Gates are one of Statsig’s most fundamental tools that can be used to control which users get exposed to a specific feature, product, service, etc. Feature Gates simply return a boolean value. In the typical feature gate example, you send contextual information at a point in your product flow and the experimentation framework will run that information against rules that you configure to determine which boolean value should be returned back to you.

To setup your first feature gate, go to the “Feature Gates” menu which should be located in the left side panel from your account dashboard and click “+ Create” to see this form:

    • Name is what you want the feature gate to be called. It’s a good idea to find a common naming convention for your team.
    • Tags give you a way to group a collection of feature gates together for easier filtering. We will leave it blank for now.
    • ID Type is the type of ID you’d like Statsig to use as a way of identifying a unique user in your product flow. We’ll use the default User ID type for now.

    After clicking “Create”, you’ll find yourself on the fg-demo-gate feature gate’s dashboard. From here, you can edit settings, view diagnostics/results, and configure rules for the feature gate.

    Rules

    Rules are the basic building blocks for a feature gate. Rules are essentially boolean expression chains that give you granular control over the traffic you’d like to have pass or fail your feature gate.

    You’ll notice an “All Rules” section that currently only has a default “ELSE” rule which is set to “always return false”. In other words, without any rules configured, all checks of this feature gate will fail. To fix that, click the “Add New Rule” button above the default rule. You’ll see a menu that looks something like this:

    • Criteria is the targeting criteria you’d like to use for this rule. We’ll leave it set to the default value of User ID.
    • Operator gives you options for matching the Criteria like Any of, None of, and Is null. We’ll use Any of to allow us to match this rule against any user-uuid that is sent through this gate.
    • Name is the name of the rule for identification against other rules.
    • Pass Percentage is exactly what it sounds like. We’ll set it to 100% pass for this demo.

    After you click “Add Rule”, you’ll see it appear in the list of rules you have configured for this feature gate. Once you’ve initialized the Statsig client in your application, it will poll for rule updates every ten seconds by default, so you can expect any changes to take effect almost immediately. Rules will be evaluated from top-to-bottom and are mutually exclusive, so you’ll want to make sure to keep ordering in mind as you organize them. With our feature gate and first rule configured, we are ready to write some code!

    Setting up the Statsig SDK

    You can get up and running quickly by installing the SDK with the package manager of your preferred language and writing a few lines of boilerplate code. From your terminal:

    After the package has been installed, you can initialize the SDK from inside your text editor:

    The sdk-api-key is something you’ll find in your “Project Settings” under “API Keys”. At this point, the Statsig client will fetch updates from Statsig in the background. You’re ready to use this client to check your new feature gate, but we have one more important Statsig concept to cover first!

    StatsigUser

    When working with an experiment framework like Statsig, it’s important to have consistent results for a user across all of your products and services. In other words, you’d like a user to always either pass or fail a feature gate each time it’s checked. This makes the out-of-the-box analytics even more powerful because it can now tie that user to multiple points throughout your product flow, giving you a richer visualization of their experience and ensuring that you’re presenting the user with congruent options.

    To manage tracking users, Statsig has the concept of a StatsigUser. The StatsigUser schema looks like this for the Python SDK:

    As you can see, there is flexibility in how you determine what makes a user unique for your feature gates, but you’ll typically only provide one or two values. With that out of the way, let’s finally test the feature gate!

    Testing the Feature Gate

    To check a StatsigUser against the fg-demo-gate feature gate, you may do something like this inside your application code:

    And for every follow-up gate check for the StatsigUser with an id of 1, as long as the target criteria matches one of the defined rules in this feature gate, you’ll get consistent results from the Statsig SDK. Following the gate check, you may choose to execute some code differently based on the result:

    And that’s all there is to it! You’ve now successfully setup and run a check against your first feature flag! We’ve only touched on the most basic concepts of an experiment framework like Statsig with a feature gate example, but most of these services offer even more powerful tools to conduct and monitor experiments across your organization. Some examples from Statsig include Events, Segments, Dynamic Configs, and Experiments.

    In the time that we have been using an experiment framework at Pinwheel, we’ve found it to be an invaluable asset in helping us in our mission to become the leader in payroll data connectivity.  If your team is looking for ways to expand your capabilities to run robust product experiments, maybe give one a try!

    Check out our related content down below to see other tech spotlights!

    Always stay up to date

    Thank you! Your submission has been received!
    Oops! Something went wrong while submitting the form.
    View our Privacy Policy   ➔

    Up next

    How alternative credit data can benefit lenders

    How alternative credit data can benefit lenders

    Read more  ➔
    Tech Spotlight: Implementing your first feature flag

    Tech Spotlight: Implementing your first feature flag

    Read more  ➔
    Pinwheel Welcomes New Advisor, Ethan Yeh, to Advance Pinwheel’s Data Science Strategy

    Pinwheel Welcomes New Advisor, Ethan Yeh, to Advance Pinwheel’s Data Science Strategy

    Read more  ➔
    Tech spotlight: Securing access control across internal services

    Tech spotlight: Securing access control across internal services

    Read more  ➔
    The anatomy and potential of payroll data: Transforming complex data into insights

    The anatomy and potential of payroll data: Transforming complex data into insights

    Read more  ➔
    Beyond the credit score: Propelling consumer finance into the future with income data

    Beyond the credit score: Propelling consumer finance into the future with income data

    Read more  ➔
    Ayokunle (Ayo) Omojola joins Pinwheel’s Board of Directors

    Ayokunle (Ayo) Omojola joins Pinwheel’s Board of Directors

    Read more  ➔
    Conquering conversion: Engineering practices developed to help customers

    Conquering conversion: Engineering practices developed to help customers

    Read more  ➔
    Driving Customer Delight: From implementation and beyond

    Driving Customer Delight: From implementation and beyond

    Read more  ➔
    Pinwheel Supports Open Finance Data Security Standard

    Pinwheel Supports Open Finance Data Security Standard

    Read more  ➔
    How we design Pinwheel to solve real customer problems

    How we design Pinwheel to solve real customer problems

    Read more  ➔
    What is consumer-permissioned data and what are its benefits?

    What is consumer-permissioned data and what are its benefits?

    Read more  ➔
    How payroll data connectivity can help financial service providers in tumultuous market conditions

    How payroll data connectivity can help financial service providers in tumultuous market conditions

    Read more  ➔
    Pinwheel now supports document uploads to supplement payroll data

    Pinwheel now supports document uploads to supplement payroll data

    Read more  ➔
    Brian Karimi-Pashaki joins Pinwheel as Partnerships Lead

    Brian Karimi-Pashaki joins Pinwheel as Partnerships Lead

    Read more  ➔
    Optimizing for conversion with smarter employer mappings

    Optimizing for conversion with smarter employer mappings

    Read more  ➔
    What are super apps and how will they impact financial services?

    What are super apps and how will they impact financial services?

    Read more  ➔
    Increase conversions and maximize share of wallet with Pinwheel's new UX update

    Increase conversions and maximize share of wallet with Pinwheel's new UX update

    Read more  ➔
    Pinwheel announces support for taxes

    Pinwheel announces support for taxes

    Read more  ➔
    Ryan Nier Joins Pinwheel as the Company’s first General Counsel

    Ryan Nier Joins Pinwheel as the Company’s first General Counsel

    Read more  ➔
    The future of enabling earned wage access

    The future of enabling earned wage access

    Read more  ➔
    Deliver earned wage access faster with Pinwheel Earnings Stream

    Deliver earned wage access faster with Pinwheel Earnings Stream

    Pinwheel Earnings Stream provides the necessary data and intelligence to reliably offer earned wage access (EWA) at scale.

    Read more  ➔
    Digital transformation in banking in 2022: What it means, trends & examples

    Digital transformation in banking in 2022: What it means, trends & examples

    Read more  ➔
    June product release: Expanded connectivity to employers, a custom experience with Link API and more

    June product release: Expanded connectivity to employers, a custom experience with Link API and more

    Read more  ➔
    Pinwheelie Spotlight: LaRena Iocco, Software Engineer

    Pinwheelie Spotlight: LaRena Iocco, Software Engineer

    Read more  ➔
    Build fully custom experiences with Pinwheel’s Link API

    Build fully custom experiences with Pinwheel’s Link API

    Read more  ➔
    Pinwheel expands connectivity to 1.5M employers

    Pinwheel expands connectivity to 1.5M employers

    Read more  ➔
    Robert Reynolds joins Pinwheel as Head of Product

    Robert Reynolds joins Pinwheel as Head of Product

    Read more  ➔
    Pinwheel obtains highest security certification in the industry

    Pinwheel obtains highest security certification in the industry

    Read more  ➔
    Lauren Crossett becomes Pinwheel’s first Chief Revenue Officer

    Lauren Crossett becomes Pinwheel’s first Chief Revenue Officer

    Read more  ➔
    Everything you should know about the role of APIs in banking

    Everything you should know about the role of APIs in banking

    Read more  ➔
    Open finance: What is it and how does it impact financial services?

    Open finance: What is it and how does it impact financial services?

    Read more  ➔
    How automated direct deposit switching benefits traditional banks

    How automated direct deposit switching benefits traditional banks

    Read more  ➔
    Pinwheel Secure: Authentication optimized for market-leading conversion

    Pinwheel Secure: Authentication optimized for market-leading conversion

    Read more  ➔
    Pinwheelie Spotlight: Elena Churilova, Software Engineer, Integrations

    Pinwheelie Spotlight: Elena Churilova, Software Engineer, Integrations

    Read more  ➔
    May product release: Localization and downloadable pay stubs

    May product release: Localization and downloadable pay stubs

    Read more  ➔
    How a payroll API can level up lenders and renters

    How a payroll API can level up lenders and renters

    Read more  ➔
    The power of payroll APIs in consumer finance

    The power of payroll APIs in consumer finance

    Read more  ➔
    Data Talks: Pinwheel’s Fortune 1000 coverage and top employer trends

    Data Talks: Pinwheel’s Fortune 1000 coverage and top employer trends

    Read more  ➔
    April product release: Enabling connectivity to time and attendance data for 25M US workers

    April product release: Enabling connectivity to time and attendance data for 25M US workers

    Read more  ➔
    Tech spotlight: Increasing engineering momentum at a systems level

    Tech spotlight: Increasing engineering momentum at a systems level

    Read more  ➔
    How crypto exchanges can turn direct deposits into a fiat onramp

    How crypto exchanges can turn direct deposits into a fiat onramp

    Read more  ➔
    March product release: Time and attendance coverage and Pinwheel's new online home

    March product release: Time and attendance coverage and Pinwheel's new online home

    Read more  ➔
    Pinwheelie spotlight: Arianna Gelwicks, Tech Recruiting

    Pinwheelie spotlight: Arianna Gelwicks, Tech Recruiting

    Read more  ➔
    What is payroll data and how it benefits proptech companies

    What is payroll data and how it benefits proptech companies

    Read more  ➔
    Earned wage access: What is it and why does it matter?

    Earned wage access: What is it and why does it matter?

    Read more  ➔
    How fintech APIs are transforming financial services

    How fintech APIs are transforming financial services

    Read more  ➔
    Webinar: Unleash growth with income and payroll APIs

    Webinar: Unleash growth with income and payroll APIs

    Read more  ➔
    February product release: Updated Link UX and data quality

    February product release: Updated Link UX and data quality

    Read more  ➔
    Why a direct deposit switching API is a must-have for banks and neobanks

    Why a direct deposit switching API is a must-have for banks and neobanks

    Read more  ➔
    Tech spotlight: Floating footer with React functional components

    Tech spotlight: Floating footer with React functional components

    Read more  ➔
    Pinwheelie spotlight: Hale Ahangi, People Operations Lead

    Pinwheelie spotlight: Hale Ahangi, People Operations Lead

    Read more  ➔
    Shift from a vicious to virtuous cycle: The foundation for a fairer financial system

    Shift from a vicious to virtuous cycle: The foundation for a fairer financial system

    Read more  ➔
    January product release: Recurring access to income & employment

    January product release: Recurring access to income & employment

    Read more  ➔
    Pinwheel’s Series B and our path towards a fairer financial future

    Pinwheel’s Series B and our path towards a fairer financial future

    We're excited to share that we have raised a $50M Series B funding round led by GGV Capital with participation from many others.

    Read more  ➔
    Pinwheelie spotlight: Devin DeCaro-Brown, Product Manager

    Pinwheelie spotlight: Devin DeCaro-Brown, Product Manager

    Read more  ➔
    Tech spotlight: How to implement async requests in your Python code

    Tech spotlight: How to implement async requests in your Python code

    Read more  ➔
    2021 recap and product update: An amazing year for Pinwheel

    2021 recap and product update: An amazing year for Pinwheel

    Read more  ➔
    Charles Tsang joins Pinwheel as Head of Marketing

    Charles Tsang joins Pinwheel as Head of Marketing

    Read more  ➔
    Pinwheelie spotlight: Octavio Roscioli, Senior Software Engineer

    Pinwheelie spotlight: Octavio Roscioli, Senior Software Engineer

    Read more  ➔
    November product release: Beta launch of income & employment monitoring

    November product release: Beta launch of income & employment monitoring

    Read more  ➔
    How can payroll data help with one’s financial picture?

    How can payroll data help with one’s financial picture?

    Read more  ➔
    Pinwheelie spotlight: Caroline Lo, Software Engineer

    Pinwheelie spotlight: Caroline Lo, Software Engineer

    Read more  ➔
    2021 company onsite: Bringing Pinwheelies together

    2021 company onsite: Bringing Pinwheelies together

    Read more  ➔
    October product release: Beta launch of direct deposit allocation monitoring

    October product release: Beta launch of direct deposit allocation monitoring

    Read more  ➔
    Why payroll data access is inevitable on your product roadmap

    Why payroll data access is inevitable on your product roadmap

    Read more  ➔
    Security spotlight: SOC 2 compliance

    Security spotlight: SOC 2 compliance

    Read more  ➔
    Jeff Hudesman joins Pinwheel as Chief Information Security Officer

    Jeff Hudesman joins Pinwheel as Chief Information Security Officer

    Read more  ➔
    Welcoming John Whitfield, VP of Engineering

    Welcoming John Whitfield, VP of Engineering

    Read more  ➔
    Announcing Pinwheel’s FCRA Compliance

    Announcing Pinwheel’s FCRA Compliance

    Read more  ➔
    Pinwheel's statement on Section 1033

    Pinwheel's statement on Section 1033

    Read more  ➔
    Pinwheel raises $20M Series A

    Pinwheel raises $20M Series A

    Read more  ➔
    If I were a fintech founder

    If I were a fintech founder

    Read more  ➔
    Pinwheelie spotlight: Phil Jen, Director of Product

    Pinwheelie spotlight: Phil Jen, Director of Product

    Read more  ➔
    Celebrating women's history month with Sasha Pilch

    Celebrating women's history month with Sasha Pilch

    Read more  ➔
    Tech spotlight: How we re-launched our API docs

    Tech spotlight: How we re-launched our API docs

    Read more  ➔
    Why I chose Pinwheel: Payroll APIs as the next frontier

    Why I chose Pinwheel: Payroll APIs as the next frontier

    Read more  ➔
    Lunch and learn with Nik Milanović

    Lunch and learn with Nik Milanović

    Read more  ➔
    Pinwheelie spotlight: David Daudelin, Senior Front End Engineer

    Pinwheelie spotlight: David Daudelin, Senior Front End Engineer

    Read more  ➔
    The missing link

    The missing link

    Read more  ➔
    Introducing Pinwheel, the API for payroll

    Introducing Pinwheel, the API for payroll

    Read more  ➔