Design a referral system for a sports betting application that enables existing users to invite new users through unique referral codes or links. When a referred user signs up and completes their first deposit, the referrer receives a ten-dollar reward credited to their in-app balance. The system must integrate with the existing signup and payments infrastructure without disrupting those critical paths.
The core engineering challenges are reliable attribution across platforms (web, iOS, Android), exactly-once reward distribution despite retries and concurrent events, fraud prevention against self-referrals and bot farming, and financial auditability for every reward issued. The referral flow spans multiple services and can take days between code share and qualifying deposit, requiring durable state tracking and asynchronous event processing.
Based on real interview experiences, these are the areas interviewers probe most deeply:
Linking a new signup to the correct referrer is harder than it appears. Users share links via SMS that open in different browsers, install the app days later, or switch devices before signing up. Interviewers want to see how you handle these attribution gaps.
Hints to consider:
Deposit events may be delivered multiple times due to retries, and concurrent processing could trigger duplicate payouts. Interviewers expect idempotent, transactional reward issuance.
Hints to consider:
Simple referral systems attract exploitation through self-referrals, VPN-based account farming, and shared payment methods across fake accounts. Interviewers look for defense in depth.
Hints to consider:
The qualifying deposit may happen days after signup, requiring durable event handling across service boundaries. Interviewers want to see decoupled, resilient processing.
Hints to consider:
Confirm what constitutes a qualifying action -- is it any first deposit above a threshold, or does the deposit amount matter? Ask about reward tiers versus a flat rate. Clarify the attribution window duration. Understand whether the referral system needs to support concurrent promotional campaigns with different reward structures. Verify regulatory requirements around promotional rewards in the sports betting jurisdictions.
Sketch core components: Referral Service (generates codes, stores referral records, manages attribution), Event Stream (Kafka for capturing signup, deposit, and reward events), Reward Engine (consumes qualifying events, validates eligibility, credits accounts with idempotency guarantees), Fraud Detection Service (scores referrals in real time using device, IP, and payment signals), User Account Service (existing service managing balances and transaction history), and Analytics Pipeline (aggregates referral funnel metrics for marketing dashboards). Show the flow: referrer generates code, referee clicks link and signs up with attribution token, referee makes first deposit, deposit event triggers reward evaluation, reward engine credits referrer.
Walk through the critical path from deposit to reward. The payments service commits the deposit transaction and writes a "DepositCompleted" event to an outbox table. A Kafka Connect connector publishes the outbox event to a Kafka topic partitioned by user ID. The Reward Engine consumes the event and looks up the referral record for this user. It verifies the referral is still within the attribution window, the referee has not already triggered a reward, and the deposit meets the minimum threshold. The engine then executes a database transaction: insert a reward record with status ISSUED, update the referrer's balance, and mark the referral as completed. A unique constraint on (referral_id, reward_type) prevents double-crediting on retry. On success, a "RewardGranted" event is published for notification delivery and analytics. If fraud signals are present, the reward enters a HELD state for manual review.
Cover analytics: referral events feed a data warehouse for funnel analysis (shares, clicks, signups, deposits, rewards). Discuss campaign management using a configuration-driven rule engine where marketers can adjust reward amounts, qualifying criteria, and duration without code changes. Address monitoring by tracking conversion rates, time-to-conversion, fraud flag rates, and system latency. Explain how to handle reward reversals if a qualifying deposit is later refunded or charged back, using compensating transactions to debit the referrer's balance and mark the referral as reversed. Touch on internationalization for multi-currency support and localized notification messaging.