0Pricing
Microservices Communication Patterns (Saga, Circuit Breaker) · 강의

이벤트 기반 사가 설계

이벤트를 사용하여 여러 마이크로서비스에서 작업을 트리거하는 코레오그래피 사가의 흐름을 설계합니다.

이벤트 기반 사가 설계은(는) CoddyKit의 무료 Microservices Communication Patterns (Saga, Circuit Breaker) 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Microservices Communication Patterns (Saga, Circuit Breaker) 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Microservices Communication Patterns (Saga, Circuit Breaker) 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Event-Driven Saga Design

Welcome! In this lesson, we'll learn how to design the flow of a Choreography Saga. This pattern helps manage complex business transactions that span multiple services.

We'll focus on using events as the primary way services communicate and trigger each other's actions.

Choreography Refresher

Remember Choreography Sagas? In this style, services communicate directly by publishing and subscribing to events.

  • No central orchestrator: Services react to events from others.
  • Decentralized decisions: Each service decides its next step based on the event it receives.

Our Business Scenario

Let's design a saga for an "Online Order Placement" system. This common scenario involves several steps across different microservices:

  • Customer places order.
  • Inventory is checked and reserved.
  • Payment is processed.
  • Order is shipped.

Identifying Core Saga Steps

For our "Order Placement" saga, we can break it down into these main steps, each potentially handled by a different service:

  • Order Service: Creates the order.
  • Inventory Service: Reserves items.
  • Payment Service: Processes payment.
  • Shipping Service: Schedules shipment.

Events Drive the Flow

In a choreography saga, each step is initiated by an event. When one service completes its task, it publishes an event.

Other services, interested in that event, subscribe to it and react accordingly. This creates a chain reaction.

Kicking Off the Saga

Every saga needs a starting point. For our "Order Placement," the Order Service initiates the process.

When a customer places an order, the Order Service creates it and publishes an OrderCreatedEvent.

Inventory Reacts to Order

The Inventory Service subscribes to OrderCreatedEvent. Upon receiving it, it attempts to reserve the items for the order.

After processing, it publishes either an InventoryReservedEvent or an InventoryFailedEvent.

class OrderCreatedEvent {
    String orderId;
    String customerId;
    // ... item details
}

class InventoryService {
    public void handleOrderCreated(OrderCreatedEvent event) {
        System.out.println("Inventory Service: Received OrderCreatedEvent for " + event.orderId);
        // Logic to reserve items...
        boolean success = true; // Assume success for now
        if (success) {
            System.out.println("Inventory Service: Items reserved. Publishing InventoryReservedEvent.");
            // In a real system, publish InventoryReservedEvent
        } else {
            System.out.println("Inventory Service: Inventory failed. Publishing InventoryFailedEvent.");
            // In a real system, publish InventoryFailedEvent
        }
    }
}

public class Main {
    public static void main(String[] args) {
        InventoryService inventory = new InventoryService();
        OrderCreatedEvent newOrder = new OrderCreatedEvent();
        newOrder.orderId = "ORD123";
        newOrder.customerId = "CUST456";

        inventory.handleOrderCreated(newOrder);
    }
}

Payment Reacts to Inventory

The Payment Service subscribes to InventoryReservedEvent. This means payment only proceeds if inventory is successfully reserved.

It processes the payment and then publishes either a PaymentProcessedEvent or a PaymentFailedEvent.

Shipping Reacts to Payment

Finally, the Shipping Service subscribes to PaymentProcessedEvent. It schedules the shipment only after payment is confirmed.

It then publishes an OrderShippedEvent to complete the main saga flow.

Planning for Rollbacks

What if a step fails? For example, if payment fails after inventory is reserved? In a choreography saga, we use compensation events.

The Payment Service would publish a PaymentFailedEvent. The Inventory Service would subscribe to this event and publish an InventoryReleasedEvent to undo its previous action.

Saga Flow Check

Consider our Order Placement saga. What is the correct sequence of events if the entire process is successful?

Recap: Designing Event Flows

We've learned how to design a choreography saga by breaking down a business transaction into steps.

  • Each step publishes an event to trigger the next.
  • We identified the initial event and subsequent events for a successful flow.
  • We also briefly considered how compensation events are used to handle failures.

Next, we'll explore how message brokers facilitate this communication!

자주 묻는 질문

“이벤트 기반 사가 설계” 강의는 무료인가요?

네 — “이벤트 기반 사가 설계” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Microservices Communication Patterns (Saga, Circuit Breaker) 강의 전체를 잠금 해제할 수 있습니다. Microservices Communication Patterns (Saga, Circuit Breaker) 강의에는 총 4개의 강의가 포함되어 있습니다.

“이벤트 기반 사가 설계”에서 뭘 배우나요?

이벤트를 사용하여 여러 마이크로서비스에서 작업을 트리거하는 코레오그래피 사가의 흐름을 설계합니다. 브라우저에서 직접 실행하는 실습 코드로 Microservices Communication Patterns (Saga, Circuit Breaker)을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Microservices Communication Patterns (Saga, Circuit Breaker)을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Microservices Communication Patterns (Saga, Circuit Breaker)은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.

“이벤트 기반 사가 설계” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Microservices Communication Patterns (Saga, Circuit Breaker) 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Microservices Communication Patterns (Saga, Circuit Breaker) 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 이벤트 기반 사가 설계
  2. 이벤트 버스 및 메시지 브로커
  3. 이벤트를 사용한 보상 처리
  4. 멱등 이벤트 소비자 구축
← Microservices Communication Patterns (Saga, Circuit Breaker)(으)로 돌아가기