Measuring a Premium Plan Launch and Building Fraud Alert Rules
SQL & DataModel answerLast updated
Define launch success for a new paid tier using only transaction and activity tables, then design a rule-based SQL alerting system for suspicious payments.
You work on the analytics team of a consumer finance app. All timestamps are UTC. These tables are available:
users(user_id BIGINT PK, create_date TIMESTAMP, country VARCHAR): signup time and registration country.transactions(transaction_id BIGINT PK, user_id BIGINT, product VARCHAR, amount_gbp DECIMAL(12,2), status VARCHAR, transaction_time TIMESTAMP): one row per transaction.activity(user_id BIGINT, product VARCHAR, event_type VARCHAR, event_time TIMESTAMP, ip_country VARCHAR): one row per product interaction, with the IP country observed at that event.
Answer both scenarios.
Scenario 1: Launch of a new top-tier paid plan
The company has just released a paid plan whose rows carry product = 'ultra'. There is no subscriptions table, so adoption must be inferred from the tables above. Define what a successful first month looks like and describe the SQL analyses you would build. Cover:
- one primary success metric and several supporting metrics,
- denominator choices (all users, active users, new users) and their trade-offs,
- segmentation by country and by account tenure,
- how to compute DAU/WAU/MAU, adoption, penetration, and early retention,
- how to avoid misleading conclusions from seasonality, country-mix shifts, and self-selection.
Scenario 2: Rule-based suspicious activity detection
Together with the financial-crime team, design a rule-based SQL system that flags users or transactions for manual review. Turn "suspicious" into executable rules that use only the tables above. Consider:
- unusually large amounts,
- bursts of transactions in a short window,
- repeated small probing payments,
- a sudden jump in the number of products used,
- registration country differing from the recent IP country.
Define the alert table you would output, example rules with thresholds, how rules combine into a score or review queue, and how you would measure precision, recall, and false positives.
Hints
Hint 1
Start by writing down your proxy for a subscriber (for example, a completed fee transaction with no later refund) and for an engaged user (an activity row). Every later metric builds on those two definitions.
Hint 2
For penetration, restrict both numerator and denominator to eligible countries and to users who were active before launch. For retention, build cohorts by the week of first payment and check activity in weeks 1 to 4.
Hint 3
For fraud rules, use time-ranged window functions for bursts, ROW_NUMBER for the latest IP, and store one row per rule hit so scores can be recomputed and each rule evaluated separately. Plan for recall measurement by sampling alerts below the threshold.
Hint 4
For causal claims, think of holdouts, staggered rollout, difference-in-differences against non-launch markets, and matching on pre-period behavior.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Both parts ask you to turn a fuzzy idea ("success", "suspicious") into explicit definitions, then into queries that are hard to misread. State your assumptions first.
Part 1: Measuring the plan launch
Definitions (proxies)
- Subscriber: a user with a
transactionsrow whereproduct = 'ultra'andstatus = 'completed'(the fee), with no later reversal or refund. - Engaged user on a day: at least one
activityrow withproduct = 'ultra'on that day.
WITH subs AS (
SELECT user_id, MIN(transaction_time) AS first_paid_at
FROM transactions
WHERE product = 'ultra' AND status = 'completed'
GROUP BY user_id
)
SELECT * FROM subs;
Primary metric
Net paid penetration at day 30: net paying subscribers divided by eligible users who were active in the 28 days before launch, within launch countries.
This counts money, not clicks. It is normalized, so countries are comparable. Free-trial taps or page views cannot inflate it.
Supporting metrics
| Area | Metric |
|---|---|
| Funnel | Plan page view → paid conversion |
| Engagement | Plan DAU, WAU, MAU, and stickiness (DAU/MAU) |
| Activation | Share of subscribers using a plan-specific feature within 7 days |
| Early retention | Share of a weekly cohort active in weeks 1 to 4 |
| Quality | Refund rate, support contacts |
| Cannibalization | Share of subscribers who previously paid for a lower tier |
| Revenue | Net fee revenue, ARPU change vs. pre-period |
Guardrails: overall account churn and the fraud rate among new subscribers.
Denominators
- All users: simple, but dormant accounts dilute it, especially in markets with many inactive accounts.
- Active users: best proxy for reachable demand, so use it for the headline. It depends on how "active" is defined, so fix that definition before launch.
- New users: shows whether the plan helps acquisition, but samples are small and intent differs. Report separately.
- Eligible only: always restrict to launch countries and eligible account types, or penetration is mechanically depressed.
Engagement and retention queries
WITH daily AS (
SELECT DATE(event_time) AS d, user_id
FROM activity
WHERE product = 'ultra'
GROUP BY 1, 2
)
SELECT a.d,
COUNT(DISTINCT CASE WHEN b.d = a.d THEN b.user_id END) AS dau,
COUNT(DISTINCT b.user_id) AS wau
FROM (SELECT DISTINCT d FROM daily) a
JOIN daily b ON b.d BETWEEN a.d - INTERVAL '6 day' AND a.d
GROUP BY a.d;
MAU is the same with a 29-day lookback. For retention: assign each subscriber to a cohort by week of first_paid_at, left-join to plan activity, and compute the share active in week k for k = 1 to 4. True renewal cannot be observed in month one, so say so and treat week-4 engagement as the leading indicator.
Segmentation
Join users for country, and bucket tenure at launch (<30d, 30–180d, 180d–1y, 1–3y, 3y+). Report each cell with its count, and add confidence intervals for small cells.
Avoiding misleading conclusions
- Seasonality: compare against the same weeks last year, or use difference-in-differences against non-launch countries.
- Country mix: blended penetration can rise just because high-adoption markets grew. Show per-country rates plus a mix-standardized total with pre-launch weights held fixed.
- Self-selection: adopters are already power users, so "subscribers spend 3x more" is not causal. Use a holdout or staggered rollout, within-user pre/post comparisons, or matching on pre-period spend and tenure.
- Novelty: week-1 engagement is inflated, so judge by the weeks 3 to 4 plateau.
Part 2: Rule-based suspicious activity detection
Alert table
One row per rule hit, so each rule can be audited and evaluated alone.
CREATE TABLE fincrime_alerts (
alert_id BIGINT PRIMARY KEY,
user_id BIGINT NOT NULL,
transaction_id BIGINT NULL, -- NULL for user-level rules
rule_id VARCHAR,
rule_version INT,
rule_score INT,
evidence JSON, -- counts, amounts, window bounds
window_start TIMESTAMP,
window_end TIMESTAMP,
created_at TIMESTAMP,
review_status VARCHAR, -- pending / confirmed / cleared
reviewer_label VARCHAR
);
Example rules (starting thresholds, to be tuned)
| Rule | Logic | Score |
|---|---|---|
| Large amount | amount_gbp >= 5000 or more than 5x the user's trailing 90-day p95 | 30 |
| Burst | 10 or more transactions in any 10-minute window | 25 |
| Probing | 5 or more very small payments (for example under £10) in 24h, especially with failures | 35 |
| Product spread | 4 or more distinct products in 24h when the 30-day baseline is 1 or fewer | 15 |
| Geo mismatch | latest ip_country differs from users.country | 10 |
| New-account boost | account under 7 days old and a large-amount or burst hit | +20 |
-- Burst rule (Postgres 11+)
SELECT transaction_id, user_id, transaction_time, cnt_10m
FROM (
SELECT t.*,
COUNT(*) OVER (
PARTITION BY user_id ORDER BY transaction_time
RANGE BETWEEN INTERVAL '10 minutes' PRECEDING AND CURRENT ROW
) AS cnt_10m
FROM transactions t
) x
WHERE cnt_10m >= 10;
-- Geo mismatch on the latest IP
SELECT u.user_id, u.country, a.ip_country
FROM users u
JOIN (
SELECT user_id, ip_country,
ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY event_time DESC) rn
FROM activity
) a ON a.user_id = u.user_id AND a.rn = 1
WHERE a.ip_country <> u.country;
Geo mismatch alone is weak because of travel and VPNs. Give it a low weight and let it amplify other rules.
From rules to a queue
- Sum scores per user over a rolling 24h window, capping each rule so one noisy rule cannot dominate.
- Add interaction bonuses, for example probing followed by a large payment.
- Tier the result: 60 or more goes to a priority queue, 30 to 59 to a standard queue, and below 30 is logged only.
- Cap daily queue size to analyst capacity and rank by score within the tier.
Evaluation
- Precision: confirmed alerts divided by reviewed alerts, per rule and per tier.
- False-positive rate and alert volume: track alerts per 1,000 active users and analyst hours per confirmed case.
- Recall: harder, because you only see labels for what you flagged. Randomly sample unflagged users for review, and use downstream signals such as chargebacks, customer disputes, and account closures as delayed labels.
- Backtest thresholds on historical windows with known outcomes and plot precision against recall, or use precision@k for the queue size you can handle.
- Feedback loop: feed reviewer labels back to retune thresholds, version rules via
rule_version, and eventually use the hits as features in a model.
Common mistakes
- Using all users as the denominator for penetration.
- Treating correlation between adoption and spend as a causal effect.
- Using fixed thresholds across countries and tenure groups, which floods the queue with false positives for high-spend segments.
- Evaluating only precision and ignoring recall.
- Counting reversed or failed transactions as normal activity without separating them.