Backend2024년 11월 13일2분 읽기

마이크로서비스 아키텍처 설계 패턴 — 실전 가이드

YS
YoungSam
조회 1787

API Gateway 패턴

클라이언트의 단일 진입점으로, 라우팅, 인증, 속도 제한을 담당합니다.

Circuit Breaker

class CircuitBreaker {
  constructor(private threshold = 5, private timeout = 60000) {}
  private failures = 0;
  private state: "closed" | "open" | "half-open" = "closed";

  async call(fn: () => Promise<any>) {
    if (this.state === "open") throw new Error("Circuit is open");
    try {
      const result = await fn();
      this.reset();
      return result;
    } catch (err) {
      this.failures++;
      if (this.failures >= this.threshold) this.state = "open";
      throw err;
    }
  }
}
MicroservicesArchitectureDesign Pattern

댓글 0

아직 댓글이 없습니다.