Feature Flag Adoption

An easy SQL interview practice problem on DataDriven. Write the query and run it against a real database, with instant feedback.

Domain
SQL
Difficulty
easy
Seniority
L3
Asked in
Airbnb

Problem

Count how many flags are enabled and how many are disabled for each feature, so we can see where every feature stands before the next major rollout. Each feature is gated by several flags in feat_flags, one row per flag, all carrying the feature's flag_name.

How widely adopted are the flags?

Tables

feat_flags

Columns: flag_id INTEGER, flag_name TEXT, enabled INTEGER, rollout REAL, owner TEXT, created TEXT, updated TEXT

feat_flags: 10 of 200 rows
flag_idflag_nameenabledrolloutownercreatedupdated
131new_checkout0NULLengineering2025-02-022026-02-02
162beta_search0NULLgrowth2025-03-032026-03-03
193ai_recs139platform2025-04-042026-04-04
224live_chat0NULLmobile2025-05-052026-05-05
255video_upload0NULLdata2025-06-062026-06-06
286two_factor178product2025-07-072026-07-07
317bulk_export0NULLengineering2025-08-082026-08-08
348new_dashboard0NULLgrowth2025-09-092026-09-09
379mobile_v2117platform2025-10-102026-01-10
410dark_mode0NULLmobile2025-11-112026-02-11

Expected output

First 5 of 20 rows
flag_nameenabledflag_count
ai_recs012
ai_recs18
beta_search014
beta_search16
bulk_export014

Worked solution and explanation

What this is really asking

This is a two-key count dressed up as a rollout inventory. Everyone reads 'enabled versus disabled' and splits on enabled. That returns two rows, 134 off and 66 on, and tells you nothing about which feature is dark. The detail that separates candidates is in the data: flag_name is not unique, and each of the ten features is gated by 20 flags. The grain the inventory needs is feature and state together. Miss it and either the features disappear into two totals, or the disabled side disappears into a per-feature on-count.

Build it

Step 1: Find the grain in the data

flag_id is unique but flag_name repeats on 20 rows per name. A feature's standing is the mix of its flags, so the output needs one row per (flag_name, enabled) pair.

Step 2: Split on both keys

GROUP BY flag_name, enabled creates a group for each pair. Every feature on the seed has flags in both states, so ten features give 20 rows.

Step 3: Count rows, not values

COUNT(*) counts the flags in each group. enabled is 0 or 1 with no NULLs, so there is no third group to guard against. Summing enabled instead would turn every off group into 0.

Flag state per feature
SELECT flag_name, enabled, COUNT(*) AS flag_count
FROM feat_flags
GROUP BY flag_name, enabled
State only: the two-total trap
SELECT enabled, COUNT(*) AS flag_count
FROM feat_flags
GROUP BY enabled

Returns 134 off and 66 on, and no feature is visible.

Follow-ups

Common follow-up questions