ใน distributed system การเรียกย่อมล้มเหลว Retry พร้อม backoff กู้คืนจาก error แบบ ชั่วคราว ส่วน circuit breaker หยุดคุณจากการกระหน่ำ dependency ที่ ล่ม จริง ๆ ทั้งสองส่งเสริมกัน: retry กับความผิดปกติชั่วครู่ และ break เมื่อเกิด outage
ใน distributed system การเรียกย่อมล้มเหลว Retry พร้อม backoff กู้คืนจาก error แบบ ชั่วคราว ส่วน circuit breaker หยุดคุณจากการกระหน่ำ dependency ที่ ล่ม จริง ๆ ทั้งสองส่งเสริมกัน: retry กับความผิดปกติชั่วครู่ และ break เมื่อเกิด outage
สำหรับความล้มเหลวชั่วคราว (timeout, network blip ชั่วครู่, 503) ให้ retry — แต่ back off แบบ exponential และเพิ่ม jitter เพื่อให้ retry กระจายออกแทนที่จะ synchronize กลายเป็น thundering herd
attempt 1 → wait ~1s (+ random jitter)
attempt 2 → wait ~2s (+ random jitter)
attempt 3 → wait ~4s (+ random jitter)
→ cap at maxRetries (e.g. 3) and a max delay → don't retry forever
ข้อควรระวังสำคัญ:
Circuit breaker ติดตามความล้มเหลวไปยัง dependency และหลังจากถึง threshold มันจะ trip open — fail fast (หรือคืน fallback) แทนที่จะเรียก service ที่ตายไป หลังจาก cooldown มันจะไปสู่ half-open เพื่อ probe การฟื้นตัว
CLOSED → calls pass through; count failures
too many failures → trip → OPEN
OPEN → fail fast immediately (no call); start cooldown timer
cooldown elapsed → HALF-OPEN
HALF-OPEN → allow a few probe calls
success → CLOSED (recovered) ; failure → back to OPEN
Retry → transient, likely-to-succeed-soon errors (1 slow call)
Circuit breaker → repeated/sustained failures (the dependency is down)
→ use together: breaker prevents retries from piling onto a dead service
หากไม่มีสิ่งเหล่านี้ dependency หนึ่งที่ล้มเหลวจะลากผู้เรียกลงไปด้วย: คำขอกองพะเนินเพราะ timeout, retry ขยายโหลด และความล้มเหลวลุกลามข้าม service Exponential backoff พร้อม jitter กู้คืนจากความผิดปกติชั่วครู่โดยไม่เกิด retry storm การ cap และ idempotency ทำให้ retry ปลอดภัย และ circuit breaker หยุดการสิ้นเปลืองทรัพยากรกับ dependency ที่ตายไปและให้พื้นที่มันฟื้นตัว เมื่อรวมกันแล้วพวกมันเปลี่ยนความล้มเหลวของ dependency ให้เป็นเหตุการณ์ที่ถูกจำกัดและซ่อมแซมตัวเองได้