0Pricing
Microservices Communication Patterns (Saga, Circuit Breaker) · บทเรียน

รูปแบบ Bulkhead

เรียนรู้ว่ารูปแบบ Bulkhead แยกทรัพยากรออกจากกันอย่างไร เพื่อให้ความล้มเหลวในส่วนหนึ่งของระบบไม่สามารถใช้ทรัพยากรร่วมจนหมดและทำให้แอปพลิเคชันทั้งหมดหยุดทำงานได้

รูปแบบ Bulkhead เป็นบทเรียน Microservices Communication Patterns (Saga, Circuit Breaker) ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Microservices Communication Patterns (Saga, Circuit Breaker) และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Microservices Communication Patterns (Saga, Circuit Breaker) มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

What Is a Bulkhead?

The name comes from ships: a hull is divided into watertight bulkhead compartments. If one floods, the others stay dry and the ship survives.

In software, the bulkhead pattern isolates resources so a failure in one area cannot sink the entire system.

The Problem It Solves

Imagine one slow downstream service. If all requests share a single thread pool, requests to the slow service consume every thread. Soon healthy services cannot get a thread either. One failure cascades into total outage.

Isolating Resource Pools

The fix: give each dependency its own pool of resources (threads or connections). When the slow service exhausts its pool, only calls to that service degrade.

pools = {'payments': 10, 'inventory': 10, 'reports': 5}

def acquire(service):
    if pools[service] > 0:
        pools[service] -= 1
        return 'acquired'
    return 'rejected (bulkhead full)'

print(acquire('reports'))

Thread-Pool Bulkheads

The classic implementation assigns a dedicated thread pool per dependency. Calls run on that pool, so saturation is contained to one dependency.

Libraries like Resilience4j and the historical Hystrix offer this out of the box.

Semaphore Bulkheads

A lighter approach uses a semaphore that limits concurrent calls without a separate thread pool. It has less overhead but cannot enforce timeouts on the caller's thread.

max_concurrent = 3
in_flight = 0

def try_call():
    global in_flight
    if in_flight >= max_concurrent:
        return 'rejected'
    in_flight += 1
    return 'running'

print(try_call())

Rejecting Excess Load

When a bulkhead is full, the call is rejected immediately instead of queuing forever. Fast rejection lets the caller fall back gracefully and keeps the system responsive.

Sizing the Bulkhead

Pool size is a trade-off. Too small wastes capacity; too large defeats isolation. A common starting point is based on expected concurrency: poolSize = peakRPS * avgLatencySeconds plus a small buffer.

peak_rps = 50
avg_latency = 0.2
pool = round(peak_rps * avg_latency) + 5
print('Suggested pool size:', pool)

Bulkheads vs Circuit Breakers

They complement each other:

  • Bulkhead limits how many calls run at once (resource isolation).
  • Circuit breaker stops calling a failing service entirely.

Use both: the bulkhead contains the blast radius, the breaker stops the bleeding.

Per-Tenant Bulkheads

In multi-tenant systems, isolate resources per tenant so one noisy customer cannot starve others. This is sometimes called the noisy neighbor defense.

Monitoring Bulkheads

Track pool utilization and rejection counts. A consistently saturated bulkhead means either the dependency is unhealthy or the pool is undersized. Alerts on rejection rate catch problems early.

When to Use It

Apply bulkheads whenever a single component calls multiple independent dependencies, especially when some are slow or unreliable. It is one of the simplest, highest-value resilience patterns.

Quick Check

What is the primary benefit of the bulkhead pattern?

Recap

You learned the bulkhead pattern:

  • Isolate resources per dependency, like ship compartments.
  • Use thread-pool or semaphore bulkheads.
  • Reject excess load fast and size pools deliberately.
  • Combine with circuit breakers for layered resilience.

Bulkheads keep one failure from sinking the whole ship.

คำถามที่พบบ่อย

บทเรียน “รูปแบบ Bulkhead” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “รูปแบบ Bulkhead” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Microservices Communication Patterns (Saga, Circuit Breaker) ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Microservices Communication Patterns (Saga, Circuit Breaker) มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “รูปแบบ Bulkhead”

เรียนรู้ว่ารูปแบบ Bulkhead แยกทรัพยากรออกจากกันอย่างไร เพื่อให้ความล้มเหลวในส่วนหนึ่งของระบบไม่สามารถใช้ทรัพยากรร่วมจนหมดและทำให้แอปพลิเคชันทั้งหมดหยุดทำงานได้ คุณปฏิบัติ Microservices Communication Patterns (Saga, Circuit Breaker) ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Microservices Communication Patterns (Saga, Circuit Breaker) หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Microservices Communication Patterns (Saga, Circuit Breaker) บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน

บทเรียน “รูปแบบ Bulkhead” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Microservices Communication Patterns (Saga, Circuit Breaker) นี้ได้ไหม

ได้ บทเรียน Microservices Communication Patterns (Saga, Circuit Breaker) ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. เหตุใดความทนทานจึงสำคัญ
  2. พื้นฐานรูปแบบการลองใหม่
  3. การนำกลไกสำรองและการหมดเวลาการรอไปใช้
  4. รูปแบบ Bulkhead
← กลับไปที่ Microservices Communication Patterns (Saga, Circuit Breaker)