STARA INSIGHTS · SEO
Bulkhead Pattern: Preventing One Slow Dependency from Disrupting Your API
Learn how the bulkhead pattern isolates API resources, limits the impact of slow dependencies, and supports capacity and recovery testing.
When one external service slows down, waiting requests can exhaust a shared connection pool or worker capacity. Other features may then fail even when their own dependencies are healthy. The bulkhead pattern limits that impact by separating resources for dependencies or workload groups. It does not guarantee uninterrupted service: isolation boundaries, shared resources, and behavior at capacity still need to be designed and tested.
Why can one dependency disrupt other services?
An application may call payment, inventory, and notification systems. If all calls use the same pool, connections to a slow system can remain occupied until they time out. New requests keep arriving and capacity runs out. Microsoft describes how this resource exhaustion can spread failure to otherwise healthy services.
Illustration: an order application calls payment and catalog services. When payment slows down, 20 shared connections are occupied by waiting requests. Catalog searches also wait for a connection even though the catalog service is healthy. The number is illustrative, not a capacity recommendation.
The consequences go beyond errors: customers may be unable to browse products, operations teams may struggle to distinguish failed transactions from uncertain ones, and recovery becomes harder.
How does a bulkhead work?
A bulkhead partitions capacity so one group cannot consume all resources. In the example, the application could use separate connection pools and concurrency limits for payment and catalog calls. When the payment allocation is full, subsequent payment requests are rejected or handled according to policy; the separate catalog allocation remains available as long as other shared resources are sufficient.
Boundaries can follow dependencies, tenants, business priority, or workload types. Options include connection pools, semaphores, separate workers or queues, and separate processes or containers. Isolation varies: two pools in one process still share CPU, memory, and runtime. Choose a boundary based on the failure you need to contain, not merely a different configuration name.
Set limits and decide what happens at capacity
Start with critical flows and map their dependencies. Record normal and peak concurrency, latency, downstream capacity, and the end-to-end deadline. Set initial limits using measurements and load tests; there is no universally safe number.
When capacity is exhausted, choose behavior that fits the contract: fail fast with an actionable response, or accept work into a bounded queue if asynchronous processing is appropriate. A queue is not unlimited capacity. AWS recommends limiting queues because stale work can delay recovery. Define queue length, message age, and a procedure for expired work according to business needs.
For operations that change data, an error or timeout does not necessarily mean the transaction did not happen. Do not retry automatically without understanding its status and idempotency. See our guides to timeouts and retries and asynchronous APIs.
How bulkheads relate to timeouts, retries, and circuit breakers
A timeout limits waiting time; a bulkhead limits shared resource consumption. A circuit breaker temporarily stops calls according to a failure policy, while rate limiting controls request rate. They address different problems and can be combined.
Unbounded retries can increase load on a struggling dependency. Limit attempts and use appropriate delays, account for the overall deadline, and ensure that an operation is safe to repeat. See the circuit breaker and health check guide.
Trade-offs to consider
Isolation adds configuration and monitoring, and capacity may sit idle in one pool while another is full. Limits that are too small can reject work that could otherwise be processed. Limits that are too large can still exhaust shared CPU, database connections, or vendor quotas.
Measure shared dependencies beneath each pool. Separating workers without controlling a shared database connection pool, for example, may not prevent a wider incident. If the added resource cost and complexity are disproportionate to the risk, a simpler approach may be sufficient.
Production checklist
- Map critical flows, dependencies, shared resources, and operational owners.
- Set isolation groups and concurrency, connection, queue, and deadline limits using measurements.
- Define responses at capacity, priorities, and client behavior after rejection.
- Test a slow dependency, timeouts, traffic spikes, full queues, and gradual recovery.
- Monitor pool utilization, rejections, waiting time, queue age, errors, and the health of other flows.
- Test duplicate effects and reconciliation for state-changing operations; prepare recovery procedures.
FAQ
Does a bulkhead replace a circuit breaker?
No. A bulkhead limits resources available to a group; a circuit breaker controls calls to a dependency based on failure conditions. Test the combination to ensure its responses and recovery meet your needs.
Is the pattern only for microservices?
No. Separate pools or workers can also be used in a monolith that calls multiple dependencies. Benefits depend on the resource isolation actually implemented.
Does a queue always improve resilience?
Not necessarily. A queue can absorb a burst that can be processed later, but an unbounded backlog can make results stale and delay recovery.
Next steps
Start with one critical flow, measure normal behavior, and simulate a slow dependency. Compare the impact before and after isolation, including resources that remain shared. To discuss architecture and integration for your needs, explore StaraSolution Services.