How to manage feature flags without making performance worse

Adam McKerlie

Sarah Guthals

The Problem

Using libraries like Flagr to help maintain feature flags had a negative performance impact; it was taking 900ms to only check 50 flags.

Flagr took 900ms to check 50 flags, 500ms specifically on evaluation

Using Sentry performance monitoring, we discovered the majority of the time was spent deserializing the Flagr response.

The Solution

Digging into the client, we noticed that deserialization was turning the entire JSON blob (i.e. the flag results) into a Python object. While deserializing JSON is convenient from a development perspective, because we were only using a few JSON fields, the cost just wasn’t worth it.

After removing caching and patching our own deserializer with a simple json.loads(response.data) we saw a huge improvement in speed — so much so that other areas began to look slow by comparison:

Flagr is now only taking 200ms

Further Reading

Get Started With Sentry

Get actionable, code-level insights to resolve Python performance bottlenecks and errors.

  1. Create a free Sentry account

  2. Create a Python project and note your DSN

  3. Grab the Sentry Python SDK

pip install --upgrade sentry-sdk
  1. Configure your DSN
import sentry_sdk sentry_sdk.init( "https://<key>@sentry.io/<project>", # Set traces_sample_rate to 1.0 to capture 100% # of transactions for performance monitoring. # We recommend adjusting this value in production. traces_sample_rate=1.0, )

Loved by over 4 million developers and more than 90,000 organizations worldwide, Sentry provides code-level observability to many of the world’s best-known companies like Disney, Peloton, Cloudflare, Eventbrite, Slack, Supercell, and Rockstar Games. Each month we process billions of exceptions from the most popular products on the internet.

Share on Twitter
Bookmark this page
Ask a questionJoin the discussion

Related Answers

A better experience for your users. An easier life for your developers.

    TwitterGitHubDribbbleLinkedinDiscord
© 2024 • Sentry is a registered Trademark
of Functional Software, Inc.