C.W.K.
Stream
Lesson 04 of 06 · published

Retry 자세와 신뢰성 패턴

~14 min · retries, reliability, circuit-breaker

Level 0Observer
0 XP0/64 lessons0/13 achievements
0/150 XP to next level150 XP to go0% complete

Failure 클래스 셋, 응답 셋

Claude API failure가 permanent(4xx — 너 버그, retry X), transient(5xx, 529 — backoff와 retry), rate-limited(429 — retry-after대로 retry)로 떨어져. SDK가 예산까지 auto-retry; 그 너머는 너 결정.

Upstream outage엔 circuit breaker

Claude API degraded일 때 즉시 retry는 상황 더 나쁘게. N 연속 failure 후 open, cool-down 동안 open 유지, 그다음 half-open으로 recovery 테스트하는 circuit breaker가 service amplifying outage 방지. Fallback(Haiku, Bedrock의 Sonnet, queued retry)와 페어.

cwkPippa는 일일 약 4시간 degraded와 살아

실세계 Claude availability 높지만 완벽 X. cwkPippa 메모리 룰 — 일일 ~4시간 degraded 정상. Fallback chain(Codex → Claude → Gemini)이 v1 must-have, v2 nice-to-have X. 프로덕션 디자인이 upstream fail 가정; 질문은 얼마나 우아하게.

원칙: Retry는 unreliability 안 고쳐. Circuit breaker와 fallback path가 unreliability 고쳐. Retry는 transient blip 고쳐.

Code

Simple circuit breaker·python
import time

class Breaker:
    def __init__(self, threshold=5, cool_down=30):
        self.fails = 0
        self.opened_at = 0
        self.threshold = threshold
        self.cool_down = cool_down

    def allow(self) -> bool:
        if self.fails < self.threshold:
            return True
        return (time.time() - self.opened_at) > self.cool_down

    def record(self, ok: bool):
        if ok:
            self.fails = 0
        else:
            self.fails += 1
            if self.fails == self.threshold:
                self.opened_at = time.time()

breaker = Breaker()

def call_with_breaker(*args):
    if not breaker.allow():
        return fallback(*args)
    try:
        out = client.messages.create(*args)
        breaker.record(True)
        return out
    except Exception:
        breaker.record(False)
        raise
Provider fallback chain·python
def call_with_fallback(messages):
    try:
        return claude_sonnet(messages)
    except (RateLimitError, InternalServerError):
        try:
            return claude_haiku(messages)  # 더 싼 Anthropic 모델
        except Exception:
            return openai_gpt(messages)  # cross-provider 마지막 수단

External links

Exercise

Critical Claude 호출 하나에 fallback path 추가(모델 downgrade, 프로바이더 switch, 또는 batch에 queue). Primary fail 강제하고 fallback 실행 봐. User-facing 계약에 commit하는 SLA 문서화.
Hint
Fallback이 진짜로 안 도는 건 보통 버그 있음. Quarterly drill 일정으로 primary 강제 off.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.