SYSTEM DESIGN · INTERACTIVE DEEP DIVE

How OTP Delivery
Actually Works

Enter your number, pick a channel, and watch the full async pipeline unfold — from API layer to your SIM.

LIVE SIMULATION
PHONE NUMBER
🇮🇳 +91
Enter 10-digit mobile number
DELIVERY CHANNEL
SMS delayed — auto-retrying via WhatsApp (fallback channel)
Verify OTP
Waiting for OTP to be sent…
Resend OTP
📡 SMSC Congestion40%
📬 Queue Depth3 tasks
🔄 Retry Attempts0
API Server
Redis Cache
Rate Limiter
Message Queue
Worker
SMS Gateway
SMSC
WhatsApp API
DELIVERY PIPELINE
📱 SMS · Telecom Path Async ~10s
0.0s
BACKEND TRACE LOG
backend-trace.log · real-time event stream
TECHNICAL ARCHITECTURE
🗺️
HASH MAP · O(1)
OTP Store
Core data structure. Maps phone number → hashed OTP + expiry. Used in Redis for instant O(1) lookup during verification.
KEY: "otp:+919876543210"
VAL: {
hash: "sha256:a3f...",
ttl: 300, // 5 min
attempts: 0
}
📬
FIFO QUEUE
Task Queue
Message queue (RabbitMQ/SQS) holds OTP delivery jobs. First-In-First-Out ensures order. Workers consume at their own rate — decouples API from delivery.
Task {
phone: "+91...",
otp_hash: "...",
channel: "sms",
created_at: timestamp
}
🪣
TOKEN BUCKET
Rate Limiter
Prevents OTP spam. Each phone number gets a bucket of N tokens (requests). Tokens refill at a fixed rate. No tokens = request rejected.
Bucket {
tokens: 3, // max
refill: "1/min",
blocked_until: null
}
📋
SET · CACHE
Blocked Users
Redis Set tracks failed attempts per number. After 5 wrong OTPs, the number is added to a blocked set with a cooldown TTL.
SET: blocked_numbers
"+919876543210" → EX 3600

HASH: fail_count
"+91..." → 3
🔑
IDEMPOTENCY KEY
Dedup Store
Prevents duplicate OTPs from concurrent requests. If same phone requests OTP within 30s, returns the existing one — no new queue task.
KEY: "idem:+91...:
req_id_abc123"
VAL: "already_sent"
TTL: 30 seconds
📊
SLIDING WINDOW
Delivery Tracker
Circular buffer tracks delivery events (SENT / DELIVERED / FAILED) per provider per time window. Feeds the circuit breaker.
Window(60s) {
success: 982,
failed: 18,
failure_rate: 1.8%
}
MENTAL MODEL
🍕 Think of it like Swiggy order — the restaurant never makes you wait at the counter
📱YOU
place order
⚙️APP
accepts instantly
📬QUEUE
kitchen ticket
👨‍🍳WORKER
chef cooks
🛵GATEWAY
delivery agent
🏠YOU
OTP arrives!
HTTP 202 = "order accepted" · The delay is in the delivery, not the kitchen · SMSC = traffic on the road