All posts

API integration failures under load: causes and fixes

Made Right Software builds MVPs and custom software for founders and small business owners, and audits or rescues code that already exists. Fixed price. Delivered in 4 to 10 weeks.

Your API integration works in development, where response times look good and the test suite passes. When traffic climbs, the integration starts failing and the failure spreads through the rest of the system. Knowing the failure modes lets you audit your own integrations before one of them becomes an incident. This article walks through ten common failure modes.

These failures are ordinary production problems with well-understood causes. Each fix can be measured in a load test. Teams usually find these problems only after production traffic exposes them.

How rate limits cause cascade failures

A rate limit becomes a problem when an integration ignores the 429 “Too Many Requests” response or retries it at once. The provider sends that signal to slow down. An integration that keeps sending requests turns one rejected call into many.

Each provider publishes its own limits. GitHub’s rate limit documentation lists 60 requests an hour without authentication and 5,000 an hour with an authenticated token. Stripe’s rate limit guide lists a global limit of 100 requests per second in live mode.

The usual fix is exponential backoff with jitter. A retry might wait one second, then two, then four. Randomizing each wait spreads the requests. In a simulation of 100 contending clients, AWS’s Architecture Blog reports that jitter cut the number of calls by more than half.

Jitter keeps clients from retrying in step. Suppose 1,000 clients all fail and all retry after one second. Their retries reach the provider together. The same overload returns.

Circuit breakers add a second layer. Netflix’s Hystrix library implements the pattern. Its defaults open the circuit when at least 20 requests arrive within a 10-second window and 50% or more of them fail. The circuit then stays open for 5 seconds before a trial request gets through, per the Hystrix configuration wiki.

Without these safeguards, rate limits turn into retry storms. Each retry adds load to a provider that is already rejecting requests. That provider can stay degraded long after the original problem clears.

How misconfigured timeouts cause damage

Python’s requests library does not time out unless you set a timeout. The requests quickstart warns that a call without one can hang indefinitely. Set an explicit timeout on every outbound call.

A hung connection holds a socket until something closes it. It also ties up a worker and memory. Under load, waiting connections pile up while new requests keep arriving. Eventually the connections, threads, or memory run out.

Heroku’s HTTP router expects an app to start sending a response within 30 seconds. Otherwise the router logs an H12 error, according to Heroku’s HTTP routing documentation. Consider an integration that calls an API which normally answers in 35 seconds. Local tests pass because they never reach the router. In production, each call past the 30-second window logs an H12 error.

Timeouts need values that fit each dependency. Pick a connect timeout and a read timeout for each call, plus an overall budget that covers both. Base them on that API’s normal response time plus a margin.

How synchronous operations exhaust resources

A synchronous call blocks the thread that makes it until the response arrives. Under light load, the pool has threads to spare. Under heavy load, requests queue behind calls that are still waiting.

Payment flows show the pattern. If a checkout waits on the payment provider before it responds, a slow provider holds a worker for the whole wait. Moving the charge into a queue lets the request return at once. A background job then completes the charge and records whether it succeeded.

Image processing follows the same pattern. A large upload transformed inside the request ties up a worker until the transform finishes.

How retry storms amplify failures

A brief outage can become a long one when clients retry aggressively. The API may recover in seconds, while retries keep it busy for minutes.

According to AWS’s event summary, the September 20, 2015 DynamoDB event ran from 2:19 AM to 7:10 AM PDT. Storage servers retried membership requests, which added load.

Picture 1,000 clients that each make a request while the API has a brief failure. They all fail and retry one second later. Some of those retries fail too. Those retries retry again. The load grows instead of falling.

Three controls fix this. Exponential backoff spreads retries over time. Jitter keeps clients from retrying in step. A maximum retry count stops the loop.

How large payloads cause memory problems

Large responses use memory and CPU before the application can process the data. Ten concurrent requests returning 10 MB each can hold 100 MB in the client.

GitHub’s pagination guide says most endpoints cap per_page at 100 items. Request pages up to that limit and follow the links in each response until the list ends.

Elasticsearch returns 10 hits by default. Its index.max_result_window setting caps from plus size at 10,000 by default, according to Elastic’s pagination guide.

Large sorts add memory pressure as well. A query that sorts a large result set can run out of memory under load, even when the API accepts the request.

What causes authentication bottlenecks under load

Authentication adds work to every request if the client repeats it. Cache tokens until they near expiry. Refresh them a few minutes early. That keeps requests clear of the expiry boundary and spreads refresh traffic over time.

Load keys and configuration once at startup. Reading an API key from disk on every request repeats work that never changes.

Validate JWT signatures against cached public keys. Fetching keys on every request adds latency and load to the identity provider. Cache the keys with a sensible time to live.

How dependency chains create single points of failure

Each extra call on a request path adds a dependency that can fail or slow down. Latency adds up along the chain. So does the chance that one link breaks.

An e-commerce checkout shows the problem. Suppose a checkout calls an inventory API in 200 ms, a payment gateway in 800 ms, a shipping calculator in 300 ms, a tax service in 150 ms, and an order email in 100 ms. With every service healthy, the calls add up to 1,550 ms. If the payment gateway stops responding and the timeout is 30 seconds, the request fails after 30 seconds. The customer then sees a broken page.

Availability multiplies along a chain. Suppose a request passes through eight services in series. If each one is up 99.9% of the time, the whole path is up about 99.2% of the time, which is 0.999 raised to the eighth power. At 99.99% per service, the path is up about 99.92% of the time.

The bulkhead pattern gives each dependency its own thread pool. One failing integration then cannot exhaust a shared pool. Timeout budgets shrink as calls move inward. Suppose the frontend allows 25 seconds in total. It gives the first API 20 seconds. That API then gives the next service 15. Each inner layer fails before its caller does.

A circuit breaker can return a cached or degraded response while a dependency recovers. Users then see a working page with some features missing. When Zapier stops being enough covers the ceiling of visual workflow tools.

How a lack of monitoring hides problems until a crisis

Without monitoring, customers often find integration problems before your team does. Monitoring that tracks errors and latency, along with rate-limit headroom, turns that around.

Six metrics expose most of these failure modes. Track the request rate and the error rate. Watch latency at the 50th, 95th, and 99th percentiles. Check saturation of CPU and connection pools, the state of each circuit breaker, and the share of rate-limit quota that remains.

Hosted monitoring services and self-run stacks such as Prometheus and Grafana can both collect these metrics. The choice depends on who runs the system and who gets paged when it fails.

Suppose a team misses a provider’s rate-limit change. The integration exceeds the new limit for three days before customers complain. A headroom alert would have shown the drop on the first day.

How skipping caching multiplies load

Caching removes repeated calls for data that has not changed. Many APIs return the same answer many times a day. Every repeat call costs latency and quota.

HTTP caching is the simplest start. A Cache-Control: max-age=3600 header lets clients and intermediaries reuse a response for an hour. An ETag sent with If-None-Match lets the server answer 304 Not Modified when nothing has changed. That reply carries no body.

Application caches such as Redis or Memcached answer far faster than a remote API. A small cache costs little next to repeated calls to a metered API.

Pick cache lifetimes from how stale the data can be before it causes trouble. Weather data can often be cached for minutes. A product catalog can often be cached for an hour, as long as catalog updates clear the cache.

Cache stampede is the subtle failure. When a popular entry expires, many requests miss at once and hit the API together. Locking the refresh lets one request rebuild the entry while the others wait. That keeps the spike off the API.

A CDN in front of the API handles the same problem at the edge for public, cacheable responses. Users get faster responses from nearby locations. The origin then handles only cache misses.

How skipping load testing hides breaking points

Load tests find breaking points before customers do. Teams that skip them learn their capacity limit from a production incident.

Test three scenarios. Normal load is the everyday baseline. Peak load is the busiest hour you expect. Stress testing pushes past peak to find where the system breaks.

Open-source tools such as k6 and Locust handle this work. k6 scripts are written in JavaScript. Locust scripts are written in Python.

What this means for your current integrations

These are ordinary failure modes. Each one has a measurable fix, from a rate-limit check to a load test above today’s peak.

Integrations often carry several of these problems. Development environments tend to hide them. Light production traffic seldom triggers them. Growth and traffic spikes do.

What to do next

Look for rate limits the integration does not handle, retries without backoff, one timeout shared across dependencies, or load tests that never exceed today’s peak. A code audit reads the retry, timeout, and rate-limit handling in one to two weeks and ranks what to fix first. When integrations are central to the business, custom software for small business covers the rebuild.