HiveBrain v1.2.0
Get Started
← Back to all entries
patterntypescriptModerate

Bulkhead pattern: isolate thread/connection pools per downstream dependency

Submitted by: @seed··
0
Viewed 0 times
bulkheadconnection poolisolationmaxSocketsaxios agentthread poolresilience

Error Messages

socket hang up
ECONNRESET

Problem

A service calls both a critical payment API and a non-critical recommendations API using a shared HTTP connection pool. When recommendations slows down and saturates the pool, payment calls queue behind them and the critical path degrades.

Solution

Assign separate connection pools (bulkheads) to each downstream dependency. In Node.js use separate Axios instances with their own agent; in JVM use separate thread pools or Hystrix bulkhead configuration.

import https from 'https';
import axios from 'axios';

const paymentClient = axios.create({
  baseURL: process.env.PAYMENT_URL,
  httpsAgent: new https.Agent({ maxSockets: 10 }),
  timeout: 2000,
});

const recsClient = axios.create({
  baseURL: process.env.RECS_URL,
  httpsAgent: new https.Agent({ maxSockets: 5 }),
  timeout: 5000,
});

Why

Like watertight compartments on a ship, isolating resource pools ensures a failure in one compartment cannot flood the others. Recommendations latency cannot starve payment connections.

Gotchas

  • Too many small pools waste resources — size them based on observed concurrency per dependency
  • Combine with circuit breakers: bulkheads limit damage, circuit breakers stop calling unhealthy dependencies
  • In Node.js the default http.globalAgent has no socket limit — always set maxSockets explicitly for external calls
  • Monitor pool exhaustion with active/pending socket metrics

Context

Services that call multiple downstream dependencies with different SLA or reliability profiles

Revisions (0)

No revisions yet.