Video in progress
The system depends on several external providers (payments, SMS, maps, KYC). How do you design it so their failures, limits and prices don't stop the business?
Each provider sits behind our own interface (an adapter), the business code doesn't know the provider, and swapping becomes a configuration matter. Each adapter has a timeout, a circuit breaker, shared quota management and cost metrics; in critical places a backup provider or a queue, and when the state is unclear, a status query and reconciliation.
📖 Answer
A third-party API is the weakest link in your SLO, and fixing it isn't in your hands. On one project the SMS provider was down for 40 minutes: OTPs didn't arrive and new users couldn't sign up. The cause was at the provider, but the incident was ours.
-
An anti-corruption layer.
SmsSender,PaymentGateway,GeoCoderare interfaces in our own domain. The provider's status codes and models become our types inside the adapter. Without this, replacing a provider touches 30 services. -
Protection. A short timeout based on the provider's p99, a circuit breaker, and retry only on idempotent operations or when the provider supports idempotency keys. Bulkhead: a slow maps API must not tie up the payment threads.
-
Quota. The provider's limit is one for the whole company (say, 100 requests per second), while there are many services. If each hits the limit without knowing about the others, 429s hit everyone. The fix is to make the adapter a single shared service, or to split the quota by priority with a distributed token bucket (OTP before marketing).
-
A backup provider. Where you can swap (SMS, email), have a second provider and route by health and price. For payments this is harder, so there you degrade: offer another payment method.
-
Asynchrony. Calls whose response isn't needed right away (KYC, invoices) go through a queue: if the provider is down for an hour, the work piles up and is done later, and the user sees "being verified".
-
Unclear state. A timeout doesn't mean "failed". For payments you need to query the operation's status later and reconcile daily.
-
Observability and money. Latency, error rate, quota usage and cost per provider. Looking at the SMS bill at the end of the month is too late.
The contract is part of the architecture too: the provider's SLA, status page, sandbox, and policy for retiring API versions. Contract tests catch a change in the provider's response before it reaches prod.
Sign up to mark studied questions and save your progress.