# Feature Flag Adoption

> How widely adopted are the flags?

Canonical URL: <https://datadriven.io/problems/feature_flag_adoption>

Domain: SQL · Difficulty: medium · Seniority: L3

## Problem

Before the next major rollout, release engineering needs a quick inventory of how the feature flag system stands. Count how many flags are currently enabled versus disabled.

## Worked solution and explanation

### What this is really asking

`feat_flags.enabled` is a boolean across 700 rows. The result is two rows (one for true, one for false) with a count each, not a single ratio or pivoted true/false columns.

---

### Break down the requirements

#### Step 1: Group by the boolean

`GROUP BY enabled` splits the 700 flags into the true and false buckets. If `enabled` is nullable, a third NULL row appears.

#### Step 2: Count each group

`COUNT(*)` counts every row in the partition. No DISTINCT, no filter; every flag is tallied once.

---

### The solution

**FLAG STATE INVENTORY**

```sql
SELECT enabled, COUNT(*) AS flag_count
FROM feat_flags
GROUP BY enabled
```

> **Cost Analysis**
>
> 700 rows, full scan is trivial. The planner reads the table once and hashes by `enabled` (cardinality 2 or 3). No index pays off here.

> **Interviewers Watch For**
>
> Whether you account for nullable `enabled`, whether you reach for a pivoted single-row shape when the prompt did not ask for one, and whether you alias the count column with something readable like `flag_count`.

> **Common Pitfall**
>
> Filtering `WHERE enabled IS TRUE` and returning only the on count. The prompt says 'enabled versus disabled', so both rows belong in the same result set.

> **The False Start**
>
> First instinct is two `SUM(CASE WHEN enabled ...)` expressions for a single pivoted row. It works but hides NULLs. Pivot to a plain `GROUP BY enabled`; two rows answer it directly.

---

### COMMON FOLLOW-UP QUESTIONS

## Common follow-up questions

- What if release engineering wants the result as a single row with two columns? _(Wrap in conditional aggregates: `SUM(CASE WHEN enabled THEN 1 ELSE 0 END) AS on_count, SUM(CASE WHEN NOT enabled THEN 1 ELSE 0 END) AS off_count`.)_
- How do you compute the percentage enabled? _(`AVG(CASE WHEN enabled THEN 1.0 ELSE 0.0 END)` over the whole table, or divide the enabled count by the total in a CTE.)_
- How would you scope the count to flags owned by a specific team? _(Add `WHERE owner = 'release-eng'` before the GROUP BY.)_

## Related

- [All practice problems](https://datadriven.io/problems)
- [Mock interview mode](https://datadriven.io/interview/feature_flag_adoption)
- [SQL Interview Questions](https://datadriven.io/sql-interview-questions)
- [Data Engineering Interview Prep Guide](https://datadriven.io/data-engineer-interview-prep)
- [Daily Challenge](https://datadriven.io/daily)

---

Source: DataDriven (https://datadriven.io). 100% free data engineering interview prep. Live code execution against Postgres 16, Python 3.11, and Spark sandboxes. No paywall, no premium tier, no signup gate.