오케스트레이션 사가 검증
보상 경로의 단위 검증, 시뮬레이션한 서비스 장애를 이용한 통합 검증, 사가 완료 여부의 엔드투엔드 검증을 포함해 오케스트레이션 기반 사가를 검증하는 방법을 익혀 보세요.
오케스트레이션 사가 검증은(는) CoddyKit의 무료 Microservices Communication Patterns (Saga, Circuit Breaker) 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Microservices Communication Patterns (Saga, Circuit Breaker) 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Microservices Communication Patterns (Saga, Circuit Breaker) 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Why Test Sagas?
An orchestration saga coordinates multiple services through a central orchestrator. A bug in the orchestrator can leave the system in an inconsistent state across services.
Testing sagas is harder than testing a single function because you must verify both the happy path and every compensation path.
- Did each step execute in order?
- Did failures trigger the right compensations?
- Is the final state consistent?
The Testing Pyramid for Sagas
Apply the classic testing pyramid:
- Unit tests — the orchestrator's decision logic in isolation.
- Integration tests — the orchestrator talking to real or stubbed services.
- End-to-end tests — the full saga across all services.
Most tests should be unit tests because they are fast and deterministic.
Unit Testing the Orchestrator
The orchestrator is often a state machine. You can unit test its transitions by feeding events and asserting the next command.
def next_command(state, event):
if state == 'STARTED' and event == 'PAYMENT_OK':
return 'RESERVE_STOCK'
if state == 'STARTED' and event == 'PAYMENT_FAILED':
return 'ABORT'
return 'NOOP'
print(next_command('STARTED', 'PAYMENT_OK'))
print(next_command('STARTED', 'PAYMENT_FAILED'))Mocking Service Calls
In unit tests, replace real service calls with mocks or stubs. This lets you control exactly what each step returns.
For example, force the payment service to return a failure so you can assert the orchestrator issues a compensation command.
class FakePayment:
def __init__(self, ok):
self.ok = ok
def charge(self, amount):
return 'PAYMENT_OK' if self.ok else 'PAYMENT_FAILED'
print(FakePayment(False).charge(100))Testing Compensation Paths
The riskiest part of any saga is compensation. For each forward step, write a test that:
- Executes steps up to a chosen point.
- Forces a failure.
- Asserts that every prior step was compensated in reverse order.
executed = ['reserve_stock', 'charge_card']
compensations = list(reversed(executed))
print('Compensate in order:', compensations)Integration Tests with Test Containers
Integration tests run the orchestrator against real dependencies in disposable containers (databases, message brokers).
Tools like Testcontainers spin up a real broker (e.g. Kafka or RabbitMQ) so message flow is exercised exactly as in production.
Simulating Service Failures
To test resilience, inject failures: make a downstream service return errors, time out, or crash mid-saga.
- HTTP 500 from a step
- Timeout (no response)
- Duplicate event delivery
Each scenario should leave the system consistent.
Testing Timeouts
Orchestrators often set a timeout for each step. If a step does not respond, the saga should trigger compensation.
import time
def wait_for_step(timeout, elapsed):
if elapsed > timeout:
return 'TIMEOUT -> COMPENSATE'
return 'OK'
print(wait_for_step(5, 7))
print(wait_for_step(5, 3))Asserting Final State Consistency
The most important assertion is that the system ends in a valid state. After a failed saga, no money should be charged and no stock reserved.
Query each service and verify the invariants hold across them.
Replaying Events in Tests
Because messages can be delivered more than once, replay the same event twice in your tests and assert the saga state is unchanged the second time. This verifies idempotency at the orchestrator level.
processed = set()
def handle(event_id):
if event_id in processed:
return 'IGNORED (duplicate)'
processed.add(event_id)
return 'PROCESSED'
print(handle('e1'))
print(handle('e1'))Observability in Tests
Add assertions on emitted logs, metrics, and trace spans. A well-tested saga should produce a clear audit trail so that, when a real failure happens in production, you can reconstruct exactly what occurred.
Quick Check
Which test type is the best place to verify the orchestrator's transition logic quickly and deterministically?
Recap
You learned how to test orchestrated sagas:
- Use the testing pyramid: many unit tests, fewer integration and E2E tests.
- Mock services to force happy and failure paths.
- Always test compensation order and final state consistency.
- Replay events to confirm idempotency, and inject timeouts and failures.
Thorough saga testing is what keeps distributed transactions trustworthy.
자주 묻는 질문
“오케스트레이션 사가 검증” 강의는 무료인가요?
네 — “오케스트레이션 사가 검증” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 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개 중 4번째 강의입니다.
“오케스트레이션 사가 검증” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Microservices Communication Patterns (Saga, Circuit Breaker) 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Microservices Communication Patterns (Saga, Circuit Breaker) 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- 사가 오케스트레이터 설계
- 오케스트레이션을 위한 상태 머신
- 워크플로 엔진을 사용한 구현
- 오케스트레이션 사가 검증