원클릭으로
saga-architecture
Saga coordination patterns for distributed transactions with compensating actions.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Saga coordination patterns for distributed transactions with compensating actions.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Optimize token usage and context window discipline. Reduce costs and improve response quality through smart context management.
Unified context lifecycle for FlowDeck sessions — ingest, filter, prune, protect, summarize, and persist with telemetry.
Predict affected files, modules, APIs, tests, and DB paths before changes. Returns an impact map for human review.
Map architecture, conventions, and file structure into `.codebase/`. Use when onboarding or before deep feature work.
Plan differently when the agent has low certainty — ask for clarification or narrow scope instead of pretending full understanding.
Protect critical context from pruning during compaction. Preserve active plans, safety files, pending operations, and user intent anchors.
| name | saga-architecture |
| description | Saga coordination patterns for distributed transactions with compensating actions. |
| origin | FlowDeck |
When coordinating distributed operations across multiple services or data stores where ACID transactions are not available and compensating actions are needed to maintain eventual consistency.
// Saga State
interface SagaState<T> {
id: string
currentStep: number
data: T
status: 'pending' | 'in_progress' | 'completed' | 'compensating' | 'failed'
}
// Orchestrating Saga - Central coordinator manages steps
class OrderProcessingSaga {
private readonly steps: SagaStep[]
constructor(
private readonly sagaOrchestrator: SagaOrchestrator,
private readonly inventoryService: InventoryService,
private readonly paymentService: PaymentService,
private readonly shippingService: ShippingService
) {
this.steps = [
{
name: 'reserve_inventory',
execute: (state) => this.inventoryService.reserve(state.orderId, state.items),
compensate: (state) => this.inventoryService.release(state.orderId, state.items)
},
{
name: 'process_payment',
execute: (state) => this.paymentService.charge(state.orderId, state.total),
compensate: (state) => this.paymentService.refund(state.orderId, state.total)
},
{
name: 'initiate_shipping',
execute: (state) => this.shippingService.createShipment(state.orderId),
compensate: (state) => this.shippingService.cancelShipment(state.shipmentId)
}
]
}
async execute(orderId: string): Promise<void> {
const state: SagaState<OrderSagaData> = {
id: generateId(),
currentStep: 0,
data: { orderId, items: [], total: 0 },
status: 'in_progress'
}
await this.sagaOrchestrator.start(state, this.steps)
}
}
// Choreography-based Saga - Events trigger reactions
class OrderCreatedHandler {
constructor(private readonly eventBus: EventBus) {}
async handle(event: OrderCreatedEvent): Promise<void> {
// Step 1: Reserve inventory
try {
await this.inventoryService.reserve(event.orderId, event.items)
this.eventBus.publish(new InventoryReservedEvent(event.orderId))
} catch (error) {
this.eventBus.publish(new InventoryReservationFailedEvent(event.orderId, error.message))
}
}
}
class InventoryReservedHandler {
async handle(event: InventoryReservedEvent): Promise<void> {
// Step 2: Process payment
try {
await this.paymentService.charge(event.orderId, event.total)
this.eventBus.publish(new PaymentProcessedEvent(event.orderId))
} catch (error) {
// Compensate by releasing inventory
this.eventBus.publish(new InventoryReleaseRequestedEvent(event.orderId))
}
}
}
// Idempotent Step Implementation
class PaymentService {
async charge(orderId: string, amount: Money): Promise<TransactionId> {
const existingTx = await this.transactionRepo.findByOrderId(orderId)
if (existingTx) {
return existingTx.id // Idempotent: return existing instead of charging again
}
const transaction = await this.paymentGateway.charge(amount)
await this.transactionRepo.save({ orderId, transaction })
return transaction.id
}
}