📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Microservices Bulkhead Pattern

Bulkhead Pattern

5 min read
Bulkhead isolates thread pools per downstream service — one slow dependency cannot starve others.

Bulkhead Pattern

# Isolate resources so one slow service cannot exhaust all threads
from concurrent.futures import ThreadPoolExecutor

payment_pool   = ThreadPoolExecutor(max_workers=10)
inventory_pool = ThreadPoolExecutor(max_workers=20)

def charge_payment(order_id):
    future = payment_pool.submit(payment_svc.charge, order_id)
    return future.result(timeout=5)

def check_inventory(item_id):
    future = inventory_pool.submit(inventory_svc.check, item_id)
    return future.result(timeout=2)

# Payment fills its 10 threads -- inventory is unaffected!

# Async semaphore bulkhead
import asyncio
payment_sem = asyncio.Semaphore(10)

async def safe_charge():
    async with payment_sem:  # max 10 concurrent calls
        return await payment_client.charge()