jpskill.com
💬 コミュニケーション コミュニティ

arch-microservices

Microservices: decomposition, API gateway Kong/Traefik, service mesh Istio, circuit breakers, saga/outbox

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o arch-microservices.zip https://jpskill.com/download/22273.zip && unzip -o arch-microservices.zip && rm arch-microservices.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/22273.zip -OutFile "$d\arch-microservices.zip"; Expand-Archive "$d\arch-microservices.zip" -DestinationPath $d -Force; ri "$d\arch-microservices.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して arch-microservices.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → arch-microservices フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

arch-microservices

目的

このスキルは、APIゲートウェイにKong/Traefik、サービスメッシュにIstioといった特定のツールを使用し、回復性のためにサーキットブレーカーやSagaのようなパターンを用いて、AIがマイクロサービスアーキテクチャを設計、分解、実装することを可能にします。スケーラビリティと耐障害性を確保しながら、モノリスを独立したサービスに分解することに焦点を当てています。

使用する場面

このスキルは、高トラフィックのEコマースプラットフォームや、分離が必要な分散システム(例:ユーザー管理から分離された決済処理)など、モノリスを超えてアプリケーションをスケールさせる際に適用します。API管理が必要な新規プロジェクトや、回復性とデプロイ速度を向上させるためにレガシーアプリケーションをマイクロサービス化する際に使用します。

主要な機能

  • モノリスの分解:境界づけられたコンテキストを特定し、サービスに分割します。例えば、ドメイン駆動設計を使用してユーザーサービスと注文サービスを分離します。
  • APIゲートウェイ:ルーティングとレート制限のためにKongを、または動的なサービスディスカバリのためにTraefikを設定します。
  • サービスメッシュ:mTLSやトラフィックシフトを含む、サービス間通信を処理するためにIstioをデプロイします。
  • サーキットブレーカー:高いエラー率でブレーカーをトリップさせることで、カスケード障害を防ぐためにIstioのEnvoyプロキシで実装します。
  • 分散トランザクション:長時間のプロセスにはSagaパターンを、イベント駆動型の一貫性にはOutboxパターンを使用して、サービス間のアトミック性を確保します。

使用パターン

モノリスを分解するには、依存関係を分析し、個別のサービスを作成します。まずモジュールをマイクロサービスにマッピングし、次にAPIを定義します。APIゲートウェイの場合、サービスとルートを定義してKong経由でリクエストをルーティングします。サービスメッシュでは、自動トラフィック管理のためにIstioサイドカーをPodに注入します。サーキットブレーカーの場合、Istioポリシーを設定して障害を検出し、フォールバックします。Sagaは、コーディネーターサービスを介してトランザクションをオーケストレーションすることで使用します。パターン例:多段階操作のためにサービス呼び出しをSagaでラップし、結果に基づいてコミットまたは補償します。

一般的なコマンド/API

Kong API Gatewayの場合:

  • サービスを作成する:curl -X POST http://localhost:8001/services --data "name=my-service&url=http://myapp.com"
  • ルートを追加する:curl -X POST http://localhost:8001/services/my-service/routes --data "paths[]=/api" --data "methods[]=GET"
  • 設定形式:Kongの宣言型設定をYAMLで使用します。例:_format_version: "1.1" services: - name: my-service url: http://myapp.com

Istio Service Meshの場合:

  • Istioをインストールする:istioctl install -y --set profile=demo
  • サーキットブレーカー用のVirtualServiceを適用する:kubectl apply -f - <<EOF apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: my-service spec: hosts: - my-service retries: attempts: 3 EOF
  • APIエンドポイント:istiod Podを介してIstioのコントロールプレーンを使用します。例:kubectl exec -it istiod-xyz -- curl localhost:15014/statsでメトリクスをクエリします。

Saga/Outboxの場合:

  • Sagaを実装する:Axon Frameworkのようなライブラリを使用します。コードスニペット:
    Saga mySaga = Saga.builder().step(() -> orderService.createOrder()).step(() -> paymentService.process()).build();
    mySaga.execute();
  • Outboxパターン:サービス内で、イベントをデータベーステーブルにログ記録し、別のワーカーを介して処理します。設定:CREATE TABLE outbox (id UUID, payload JSONB);のようなSQLテーブル。

認証要件:認証されたAPI呼び出しのために$KONG_API_KEYのような環境変数を設定します。例:curl -H "apikey: $KONG_API_KEY" http://localhost:8001/services

統合に関する注意点

KongをIstioと統合するには、KongをIstioイングレスゲートウェイとして実行します。Kubernetesアノテーションsidecar.istio.io/inject: "true"を介してIstioサイドカーインジェクションを持つKong Podをデプロイします。Traefikの場合、ConfigMapを使用してKubernetesイングレスコントローラーとして設定します。kubectl apply -f traefik-config.yamlと、api: {} entryPoints: web: address: ":80"のような内容を使用します。他のスキル(例:se-deployment)と組み合わせる場合、サービスがapp: my-microserviceのような互換性のあるラベルでデプロイされていることを確認し、複数名前空間のセットアップには$ISTIO_NAMESPACE環境変数を使用します。Sagaパターンでは、Kafkaのようなメッセージキューと統合し、イベントをパブリッシュします。kafka-producer.send("topic", eventPayload)

エラー処理

Istioでサーキットブレーカーのエラーを処理するには、VirtualServiceでフォールバックを設定します。シミュレートされた障害のためにroute: fault: abort: percentage: 100 httpStatus: 503を設定し、kubectl logs istiod-xyz | grep errorで監視します。Sagaの場合、障害時に補償アクションを実装します。例えば、注文が失敗した場合、ロールバックメソッドを呼び出します。コードスニペット:

  try { saga.execute(); } catch (Exception e) { saga.compensate(); log.error("Saga failed: " + e.getMessage()); }

APIゲートウェイの場合、Kongのプラグインを使用してエラー応答を処理します。curl -X POST http://localhost:8001/services/my-service/plugins --data "name=request-termination" --data "config.status_code=503"でプラグインを追加します。常にkong logsまたはistioctl analyzeでログをチェックして検証エラーを確認し、$ERROR_WEBHOOK_URLのような環境変数を使用して外部システムに通知します。

具体的な使用例

  1. マイクロサービスアプリケーションの分解とデプロイ:ブログプラットフォームの場合、「posts」と「comments」サービスに分割します。個別のDockerイメージを作成して分解し、Kongを設定します。コマンド:docker run -d -p 8000:8000 kong:latest; curl -X POST http://localhost:8000/services -d 'name=posts-service&url=http://posts-app:8080'。Istioと統合します。istioctl create -f posts-virtualservice.yamlでサーキットブレーカーを追加します。

  2. 決済システムにおける回復性の実装:サービスメッシュにIstioを、トランザクションにSagaを使用します。サーキットブレーカーを設定します。kubectl apply -f circuitbreaker.yamlと、apiVersion: networking.istio.io/v1alpha3 kind: DestinationRule spec: trafficPolicy: connectionPool: tcp: maxConnections: 100 outlierDetection: consecutiveErrors: 5 interval: 10mのような内容を使用します。Sagaの場合、決済フローをオーケストレーションします。コードスニペット:

    Saga paymentSaga = Saga.builder().step(() -> reserveFunds()).step(() -> processPayment()).build();
    paymentSaga.executeWithCompensation();
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

arch-microservices

Purpose

This skill enables the AI to design, decompose, and implement microservices architectures using specific tools like Kong/Traefik for API gateways, Istio for service meshes, and patterns like circuit breakers and sagas for resilience. Focus on breaking down monoliths into independent services while ensuring scalability and fault tolerance.

When to Use

Apply this skill when scaling applications beyond a monolith, such as e-commerce platforms with high traffic, or distributed systems needing isolation (e.g., payment processing separate from user management). Use it for new projects requiring API management or when retrofitting legacy apps for microservices to improve resilience and deployment speed.

Key Capabilities

  • Decompose monoliths: Identify bounded contexts and split into services, e.g., using domain-driven design to separate user and order services.
  • API Gateway: Configure Kong for routing and rate limiting, or Traefik for dynamic service discovery.
  • Service Mesh: Deploy Istio to handle inter-service communication, including mTLS and traffic shifting.
  • Circuit Breakers: Implement with Istio's Envoy proxies to prevent cascading failures by tripping breakers on high error rates.
  • Distributed Transactions: Use saga patterns for long-running processes or outbox for event-driven consistency, ensuring atomicity across services.

Usage Patterns

To decompose a monolith, analyze dependencies and create separate services: Start by mapping modules to microservices, then define APIs. For API gateways, route requests through Kong by defining services and routes. In service meshes, inject Istio sidecars into pods for automatic traffic management. For circuit breakers, configure Istio policies to detect failures and fallback. Use sagas by orchestrating transactions via a coordinator service. Example pattern: Wrap service calls in a saga for multi-step operations, committing or compensating based on outcomes.

Common Commands/API

For Kong API Gateway:

  • Create a service: curl -X POST http://localhost:8001/services --data "name=my-service&url=http://myapp.com"
  • Add a route: curl -X POST http://localhost:8001/services/my-service/routes --data "paths[]=/api" --data "methods[]=GET"
  • Config format: Use Kong's declarative config in YAML, e.g., _format_version: "1.1" services: - name: my-service url: http://myapp.com

For Istio Service Mesh:

  • Install Istio: istioctl install -y --set profile=demo
  • Apply a VirtualService for circuit breaking: kubectl apply -f - <<EOF apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: my-service spec: hosts: - my-service retries: attempts: 3 EOF
  • API Endpoint: Use Istio's control plane via istiod pod, e.g., query metrics with kubectl exec -it istiod-xyz -- curl localhost:15014/stats

For Saga/Outbox:

  • Implement saga: Use a library like Axon Framework; code snippet:
    Saga mySaga = Saga.builder().step(() -> orderService.createOrder()).step(() -> paymentService.process()).build();
    mySaga.execute();
  • Outbox pattern: In a service, log events to a database table and process via a separate worker; config: SQL table like CREATE TABLE outbox (id UUID, payload JSONB);

Auth requirements: Set environment variables like $KONG_API_KEY for authenticated API calls, e.g., curl -H "apikey: $KONG_API_KEY" http://localhost:8001/services.

Integration Notes

Integrate Kong with Istio by running Kong as an Istio ingress gateway: Deploy Kong pod with Istio sidecar injection via Kubernetes annotation sidecar.istio.io/inject: "true". For Traefik, configure as a Kubernetes ingress controller using a ConfigMap: kubectl apply -f traefik-config.yaml with content like api: {} entryPoints: web: address: ":80". When combining with other skills (e.g., se-deployment), ensure services are deployed with compatible labels, such as app: my-microservice, and use $ISTIO_NAMESPACE env var for multi-namespace setups. For saga patterns, integrate with message queues like Kafka by publishing events: kafka-producer.send("topic", eventPayload).

Error Handling

Handle circuit breaker errors in Istio by configuring fallbacks in VirtualServices: Set route: fault: abort: percentage: 100 httpStatus: 503 for simulated failures, then monitor with kubectl logs istiod-xyz | grep error. For sagas, implement compensating actions on failure, e.g., if an order fails, call a rollback method: Code snippet:

  try { saga.execute(); } catch (Exception e) { saga.compensate(); log.error("Saga failed: " + e.getMessage()); }

For API gateways, use Kong's plugins for error responses: Add a plugin with curl -X POST http://localhost:8001/services/my-service/plugins --data "name=request-termination" --data "config.status_code=503". Always check logs with kong logs or istioctl analyze for validation errors, and use env vars like $ERROR_WEBHOOK_URL to notify external systems.

Concrete Usage Examples

  1. Decomposing and deploying a microservices app: For a blog platform, split into "posts" and "comments" services. Decompose by creating separate Docker images, then set up Kong: Command: docker run -d -p 8000:8000 kong:latest; curl -X POST http://localhost:8000/services -d 'name=posts-service&url=http://posts-app:8080'. Integrate with Istio: istioctl create -f posts-virtualservice.yaml to add circuit breaking.

  2. Implementing resilience in a payment system: Use Istio for service mesh and saga for transactions. Configure a circuit breaker: kubectl apply -f circuitbreaker.yaml with content apiVersion: networking.istio.io/v1alpha3 kind: DestinationRule spec: trafficPolicy: connectionPool: tcp: maxConnections: 100 outlierDetection: consecutiveErrors: 5 interval: 10m. For sagas, orchestrate payment flow: Code snippet:

    Saga paymentSaga = Saga.builder().step(() -> reserveFunds()).step(() -> processPayment()).build();
    paymentSaga.executeWithCompensation();

Graph Relationships

  • Related to: se-deployment (for deploying and scaling microservices built with this skill)
  • Connected to: se-scaling (for integrating auto-scaling with Istio's traffic management)
  • Part of cluster: se-architecture (shares tags like "architecture" for broader system design)
  • Links to: se-monitoring (for observing metrics from Kong and Istio setups)