India-scale design · mid
OTP service at scale
An OTP service is a secure code store plus a fast, separate delivery path with provider routing. Abuse limits and delivery measurement matter as much as the code itself.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Generate codes with a secure random source. Store only a hash, with an expiry (about 5 minutes), an attempt counter and a purpose (login or payment), keyed by (phone, purpose) in Redis with a TTL. One active code per purpose; delete on success.
- Send asynchronously through a high-priority queue kept apart from marketing. Workers call SMS aggregators and route by each provider live delivery rate and speed, per telecom operator. Retries resend the same code, not a new one.
- Delivery receipts feed each provider health score. Alert when the delivery rate or p95 time-to-deliver drops. Sent only means the aggregator accepted it; measure delivered.
- Abuse (SMS pumping): limits per phone, IP, device and account; growing cooldowns between resends; CAPTCHA after a few tries; blocked number ranges; alerts on spend.
- Guessing: 3 to 5 attempts, then lock. The code is tied to the session that asked for it.
- India: DLT registration of the business, sender header and message template; the variable parts must fit the template.
- OTPs late during a sale: the campaign shared the queue and the provider throughput limit with OTPs, the provider throttled us and one operator route was congested. Fix: a separate OTP queue and provider account, routing by live rate and latency, marketing throttled away from peak.
- Right now: move the affected operator to the healthier provider, offer voice or WhatsApp OTP, extend expiry a little, pause marketing SMS. Prevent: alerts per provider and operator, a synthetic OTP to test numbers every minute.
The red pen
Common traps: mistake → fix
Mistake: Resend more OTPs when they are slow
Fix: the queue grows and the user gets many codes.
Mistake: Measure sent
Fix: measure delivered and time to deliver.
Mistake: Store the OTP in plain text
Fix: store a hash.
Mistake: A new code on every retry
Fix: the user gets three codes; resend the same one.
Easy to hard
Questions interviewers ask, easy to hard
- Design an OTP service at scale.
- How do you stop SMS pumping abuse?
- OTPs arrive late during a sale. What do you do?
- How do you pick an SMS provider per message?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.