Circuit Breaker Pattern for OTP Services
Why and how to wrap OTP API calls in a circuit breaker. Failure thresholds, half-open probing, fallback voice OTP, and reference implementations.
StartMessaging Team
Engineering
OTP API outages cost you logins. A circuit breaker lets you fail fast and route to a fallback rather than queueing requests behind a slow upstream.
Why Circuit Breakers Matter for OTP
- OTP send is on the user critical path.
- Slow upstream = piled-up sessions.
- Fast failure + fallback > slow success.
Closed → Open → Half-Open
- Closed: normal traffic.
- Open: skip calls, fail fast or fallback for N seconds.
- Half-Open: probe with a small fraction; if probe succeeds, close.
Thresholds
- Trip on > 50% failure rate over 30s window with at least 20 requests.
- Open for 60s before half-open probe.
- Half-open probe: 5 requests, < 50% failure to close.
Fallback Strategy
- Voice OTP fallback.
- Secondary provider.
- Graceful degradation: queue with user-visible message.
Reference Implementation
import CircuitBreaker from 'opossum';
const breaker = new CircuitBreaker(callOtpApi, {
errorThresholdPercentage: 50,
resetTimeout: 60_000,
rollingCountTimeout: 30_000,
rollingCountBuckets: 10,
volumeThreshold: 20,
});
breaker.fallback(() => callVoiceOtpFallback(phone));FAQ
Combine with multi-region failover for a complete resilience story.
Related Articles
Multi-region OTP architecture: provider redundancy, regional health checks, DNS failover, and the cost-vs-resilience trade-off for India-first apps.
Define SLOs for OTP send and verify paths and monitor TRAI-compliant transactional SMS health—not just API uptime—for Indian peak traffic.
OTP delivery delays in India: typical causes, P50/P95 benchmarks, route troubleshooting, provider failover, and concrete fixes that drop latency from minutes to seconds.
Ready to Send OTPs?
Integrate StartMessaging in 5 minutes. No DLT registration required.