Trung BìnhSystem Design iconSystem Design

Circuit Breaker Pattern là gì? Nó ngăn chặn cascading failures như thế nào? (What is the Circuit Breaker Pattern? How does it prevent cascading failures?)

Circuit Breaker là pattern bảo vệ hệ thống khỏi cascading failures khi một dependency bị lỗi – lấy cảm hứng từ cầu dao điện.

  • Hoạt động qua 3 states: Closed (hoạt động bình thường, theo dõi failure rate), Open (sau khi failure rate vượt threshold, tất cả requests đều fail fast ngay lập tức mà không gọi service lỗi – cho service thời gian recover), Half-Open (sau timeout, cho một số requests thử đến service, nếu thành công thì đóng lại, nếu thất bại thì mở lại).

Ví dụ không có Circuit Breaker: Payment Service gọi Fraud Detection Service bị chậm → threads bị block chờ timeout → thread pool exhaustion → Payment Service cũng down → cascading failure lan rộng.

Xem toàn bộ System Design cùng filter theo level & chủ đề con.

Mở danh sách System Design