오케스트레이션 사가 해설
전담 서비스가 분산 트랜잭션의 단계를 조정하는 오케스트레이션 방식을 살펴봅니다.
오케스트레이션 사가 해설은(는) CoddyKit의 무료 Microservices Communication Patterns (Saga, Circuit Breaker) 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Microservices Communication Patterns (Saga, Circuit Breaker) 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Microservices Communication Patterns (Saga, Circuit Breaker) 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Introducing Orchestration Sagas
Welcome to the Orchestration Saga! In a distributed system, sometimes a business transaction needs to involve multiple services.
An Orchestration Saga is a pattern where a central service, called an orchestrator, takes charge of guiding the entire transaction.
The Role of the Orchestrator
Think of the orchestrator as a project manager for your distributed transaction. It knows all the steps and coordinates them.
- It sends commands to participant services.
- It waits for responses (events) from those services.
- It decides the next step based on the responses.
How it Works: A Simple Flow
Unlike a Choreography Saga where services react to events from each other, here the orchestrator is in control:
- Orchestrator sends a command to Service A.
- Service A performs its task and sends a completion event back to the orchestrator.
- Orchestrator receives the event and sends a command to Service B.
- This continues until the transaction is complete.
Example: Online Order Process
Let's use an online order as an example. An order might need to:
- Create an order in the Order Service.
- Reserve items in the Inventory Service.
- Process payment in the Payment Service.
- Initiate shipping in the Shipping Service.
An orchestrator would manage this sequence.
Orchestrator's State Management
The orchestrator must keep track of the saga's current state and context. This means it needs to store information like:
- Which steps have completed?
- What data was returned by previous steps?
- What is the current status (e.g.,
PAYMENT_PENDING,INVENTORY_RESERVED)?
This state is crucial for deciding the next action or handling failures.
Commands & Events
The orchestrator communicates using two main types of messages:
- Commands: Sent from the orchestrator to a service, telling it what to do (e.g.,
ReserveInventory). - Events: Sent from a service back to the orchestrator, reporting the outcome (e.g.,
InventoryReserved,PaymentFailed).
This clear distinction helps maintain control.
Handling Failures & Compensation
What if a step fails? The orchestrator is responsible for compensation.
If the Payment Service fails, the orchestrator detects the PaymentFailed event. It then knows to send compensation commands to previous services, such as ReleaseInventory to the Inventory Service and CancelOrder to the Order Service.
Orchestrator Flow Demo
Let's look at a simplified Java example. This isn't a full microservice, but it shows how an orchestrator's logic might flow, reacting to simulated service outcomes.
Notice how it tracks sagaState and triggers compensation if payment fails.
public class OrderSagaOrchestrator {
public static void main(String[] args) {
System.out.println("Saga Orchestrator Started: Order 123");
String sagaState = "ORDER_INITIATED";
System.out.println("Orchestrator: Sending 'CREATE_ORDER' command.");
// Simulate Order Service success
sagaState = "ORDER_CREATED";
System.out.println("Orchestrator: Received 'ORDER_CREATED' event.");
if (sagaState.equals("ORDER_CREATED")) {
System.out.println("Orchestrator: Sending 'RESERVE_INVENTORY' command.");
// Simulate Inventory Service success
sagaState = "INVENTORY_RESERVED";
System.out.println("Orchestrator: Received 'INVENTORY_RESERVED' event.");
}
if (sagaState.equals("INVENTORY_RESERVED")) {
System.out.println("Orchestrator: Sending 'PROCESS_PAYMENT' command.");
// Simulate Payment Service *failure*
System.out.println("Orchestrator: Received 'PAYMENT_FAILED' event.");
sagaState = "PAYMENT_FAILED";
}
if (sagaState.equals("PAYMENT_FAILED")) {
System.out.println("Orchestrator: Initiating compensation!");
System.out.println("Orchestrator: Sending 'CANCEL_ORDER' command.");
System.out.println("Orchestrator: Sending 'RELEASE_INVENTORY' command.");
sagaState = "SAGA_COMPENSATED";
System.out.println("Orchestrator: Saga completed with compensation.");
} else {
System.out.println("Orchestrator: Sending 'CONFIRM_ORDER' command.");
System.out.println("Orchestrator: Sending 'SHIP_ORDER' command.");
sagaState = "SAGA_COMPLETED_SUCCESSFULLY";
System.out.println("Orchestrator: Saga completed successfully.");
}
}
}Advantages of Orchestration
Orchestration Sagas offer clear benefits:
- Centralized Control: Easier to understand the overall flow.
- Simplified Participant Services: Services don't need to know about the entire saga; they just follow orchestrator commands.
- Easier Debugging: The orchestrator's state makes it simpler to trace issues.
- Explicit Compensation: Compensation logic is clearly defined within the orchestrator.
Check Your Understanding
Which of the following statements accurately describe key characteristics of an Orchestration Saga?
Recap: Orchestration Saga
You've learned about the Orchestration Saga pattern!
- It uses a central orchestrator service to manage a distributed transaction.
- The orchestrator sends commands to services and receives events as responses.
- It maintains the saga's state to know where it is in the transaction.
- It explicitly handles compensation by issuing rollback commands if a step fails.
This pattern provides clear control and simplifies participant services.
자주 묻는 질문
“오케스트레이션 사가 해설” 강의는 무료인가요?
네 — “오케스트레이션 사가 해설” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 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개 중 3번째 강의입니다.
“오케스트레이션 사가 해설” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Microservices Communication Patterns (Saga, Circuit Breaker) 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Microservices Communication Patterns (Saga, Circuit Breaker) 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- 사가 패턴이란 무엇인가
- 코레오그래피 사가 해설
- 오케스트레이션 사가 해설
- 안무 방식과 오케스트레이션 방식 중 선택