Claude CodeでSagaパターンを設計する:分散トランザクション・補償トランザクション・オーケストレーション

はじめに 「マイクロサービスをまたぐ注文処理が途中で失敗した——どこまで戻せばいい?」——Sagaパターンで分散トランザクションを補償トランザクションで巻き戻し、整合性を保つ設計をClaude Codeに生成させる。 CLAUDE.mdにSagaパターン設計ルールを書く ## Sagaパターン設計ルール ### オーケストレーション型 - SagaオーケストレーターがステップをRedisキュ...

By · · 1 min read

Source: dev.to

はじめに 「マイクロサービスをまたぐ注文処理が途中で失敗した——どこまで戻せばいい?」——Sagaパターンで分散トランザクションを補償トランザクションで巻き戻し、整合性を保つ設計をClaude Codeに生成させる。 CLAUDE.mdにSagaパターン設計ルールを書く ## Sagaパターン設計ルール ### オーケストレーション型 - SagaオーケストレーターがステップをRedisキューで順番に実行 - 各ステップは成功/失敗/補償の3つのハンドラーを持つ - 失敗時は逆順に補償トランザクションを実行 ### 冪等性 - 各ステップはリトライ可能(冪等キー必須) - 補償トランザクションも冪等(二重実行で同じ結果) - SagaログをDBに永続化(クラッシュ後の再開) ### タイムアウト - 各ステップに最大待機時間(例: 30秒) - タイムアウト時は自動補償開始 - SagaID単位でステータスを追跡 Saga実装の生成 Sagaパターンを設計してください。 要件: - オーケストレーション型Saga - 補償トランザクション - 冪等なステップ実行 - Sagaログ永続化 生成ファイル: src/saga/ 生成されるSaga実装 // src/saga/sagaOrchestrator.ts — Sagaオーケストレーター export interface SagaStep<TContext> { name: string; execute: (context: TContext, sagaId: string) => Promise<TContext>; compensate: (context: TContext, sagaId: string) => Promise<void>; timeoutMs?: number; } export interface SagaLog { sagaId: string; stepName: string; status: 'executing' | 'completed' | 'compensating' | 'compensated' | 'failed'; context: unknown; executedAt: Date; completedAt?:

Related Posts

Similar Topics

#ai (43)#webdev (26)#fix (18)#opensource (18)#feat (18)#javascript (17)#chore (10)#api (9)#react (9)#mcp (9)#large language models (4)#nextjs (7)#node (7)#backbonejs (6)#programming (6)#tutorial (6)#modernization (6)#es6 (6)#css (6)#security (6)

Trending on ShareHub

  1. Understanding Modern JavaScript Frameworks in 2026
    by Alex Chen · Feb 12, 2026 · 0 likes
  2. The System Design Primer
    by Sarah Kim · Feb 12, 2026 · 0 likes
  3. Just shipped my first open-source project!
    by Alex Chen · Feb 12, 2026 · 0 likes
  4. OpenAI Blog
    by Sarah Kim · Feb 12, 2026 · 0 likes
  5. Building Accessible Web Applications: A Practical Guide
    by Alex Chen · Feb 12, 2026 · 0 likes
  6. Rapper Lil Poppa dead at 25, days after releasing new music
    Rapper Lil Poppa dead at 25, days after releasing new music
    by Anonymous User · Feb 19, 2026 · 0 likes
  7. write-for-us
    by Volt Raven · Mar 7, 2026 · 0 likes
  8. Before the Coffee Gets Cold: Heartfelt Story of Time Travel and Second Chances
    Before the Coffee Gets Cold: Heartfelt Story of Time Travel and Second Chances
    by Anonymous User · Feb 12, 2026 · 0 likes
    #coffee gets cold #the #time travel
  9. Best DoorDash Promo Code Reddit Finds for Top Discounts
    Best DoorDash Promo Code Reddit Finds for Top Discounts
    by Anonymous User · Feb 12, 2026 · 0 likes
    #doordash #promo #reddit
  10. Premium SEO Services That Boost Rankings & Revenue | VirtualSEO.Expert
    by Anonymous User · Feb 12, 2026 · 0 likes
  11. NBC under fire for commentary about Team USA women's hockey team
    NBC under fire for commentary about Team USA women's hockey team
    by Anonymous User · Feb 18, 2026 · 0 likes
  12. Where to Watch The Nanny: Streaming and Online Viewing Options
    Where to Watch The Nanny: Streaming and Online Viewing Options
    by Anonymous User · Feb 12, 2026 · 0 likes
    #streaming #the nanny #where
  13. How Much Is Kindle Unlimited? Subscription Cost and Plan Details
    How Much Is Kindle Unlimited? Subscription Cost and Plan Details
    by Anonymous User · Feb 12, 2026 · 0 likes
    #kindle unlimited #subscription #unlimited
  14. Russian skater facing backlash for comment about Amber Glenn
    Russian skater facing backlash for comment about Amber Glenn
    by Anonymous User · Feb 18, 2026 · 0 likes
  15. Google News
    Google News
    by Anonymous User · Feb 18, 2026 · 0 likes

Latest on ShareHub

Browse Topics

#artificial intelligence (31587)#data science (24018)#ai (17376)#generative ai (15034)#crypto (15026)#machine learning (14681)#bitcoin (14282)#featured (13572)#news & insights (13064)#crypto news (11105)

Around the Network