frompybreakerimportCircuitBreakerdb_breaker=CircuitBreaker(fail_max=5,reset_timeout=60)@db_breakerdefquery_db(sql:str):returndb.execute(sql)try:result=query_db("SELECT * FROM users")exceptCircuitBreakerError:returncached_response()# fallback
import"golang.org/x/sync/semaphore"typeServicestruct{dbSem*semaphore.Weighted// 10 concurrent DB callsapiSem*semaphore.Weighted// 50 concurrent API calls}func(s*Service)CallDB(ctxcontext.Context)error{iferr:=s.dbSem.Acquire(ctx,1);err!=nil{returnerr}defers.dbSem.Release(1)returndoDBWork()}
언제: 매 distributed system design 시 failure mode enumeration, supervisor tree 설계, retry strategy 추천.
언제 X: 매 single-process script — fault tolerance overhead 가 value 보다 큼.
❌ 안티패턴
Catch-all exception swallow: 매 error를 log만 하고 무시 → 매 silent corruption.
Infinite retry: 매 backoff 없는 retry → 매 thundering herd, cascading failure.
Shared fate: 매 단일 DB 의존 모든 service → 매 single point of failure.
No timeout: 매 hang된 dependency가 매 caller exhaust.
🧪 검증 / 중복
Verified (Joe Armstrong, "Making Reliable Distributed Systems in the Presence of Software Errors", 2003).