tezvyn:

Design a referral feature's lifecycle and races

Source: interviewintermediate

WHAT IT TESTS: modeling a stateful flow with idempotency and concurrency safety. OUTLINE: a referral entity with explicit states, a unique constraint on the invited user, and atomic transactions plus idempotency to prevent double credits.

WHAT IT TESTS: whether you can model a lifecycle and defend it against concurrency and abuse. ANSWER OUTLINE: a referral record links referrer and referee with a state machine such as sent, accepted, qualified, credited. Enforce a unique constraint so a referee can be referred once, preventing duplicate claims. Apply credits inside an atomic transaction, guarded by idempotency keys and conditional updates, so concurrent acceptances cannot double-pay. Add fraud checks for self-referral and fake accounts.

Read the original → interview

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

Design a referral feature's lifecycle and races · Tezvyn