Chuyển đến nội dung chính

レッスン 3: システム アーキテクチャの概要 — マイクロサービス、イベント駆動型、DDD

高レベルのシステム アーキテクチャ、限定されたコンテキスト (設計、カタログ、注文、製造、フルフィルメント、分析)、イベント駆動型アーキテクチャ、CQRS、テクノロジー スタックの選択、C4 図。

🏗️ アーキテクチャ — レッスン 3 レッスン 3: システム アーキテクチャの概要 — マイクロサービス、イベント駆動型、DDD

ファッション デザインとプリント オン デマンド システム アーキテクチャ — ドメイン分析から生産まで

パート 1: ドメイン ファッション デザインと POD の概要

xdev.asia

1. DDD 境界コンテキスト

申し込む ドメイン駆動設計 POD システムを明確に境界付けられたコンテキストに分割します。

┌──────────────────────────────────────────────────────────────────────────┐
│                    Fashion POD Platform                                  │
│                                                                          │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐                   │
│  │   Design     │  │   Catalog    │  │   Commerce   │                   │
│  │   Context    │  │   Context    │  │   Context    │                   │
│  │              │  │              │  │              │                   │
│  │ • Canvas     │  │ • Product    │  │ • Cart       │                   │
│  │ • AI Gen     │  │ • SKU       │  │ • Checkout   │                   │
│  │ • Assets     │  │ • Mockup    │  │ • Payment    │                   │
│  │ • Templates  │  │ • Channel   │  │ • Pricing    │                   │
│  └──────┬───────┘  └──────┬───────┘  └──────┬───────┘                   │
│         │                 │                 │                            │
│         ▼                 ▼                 ▼                            │
│  ┌────────────────────────────────────────────────┐                     │
│  │              Event Bus (Kafka)                  │                     │
│  └────────────────────────────────────────────────┘                     │
│         │                 │                 │                            │
│         ▼                 ▼                 ▼                            │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐                   │
│  │   Order      │  │  Production  │  │  Fulfillment │                   │
│  │   Context    │  │   Context    │  │   Context    │                   │
│  │              │  │              │  │              │                   │
│  │ • OMS       │  │ • Print Queue│  │ • Shipping   │                   │
│  │ • Saga      │  │ • Supplier   │  │ • Tracking   │                   │
│  │ • Split     │  │ • QC        │  │ • Returns    │                   │
│  │ • Timeline  │  │ • Routing   │  │ • Logistics  │                   │
│  └──────────────┘  └──────────────┘  └──────────────┘                   │
│                                                                          │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐                   │
│  │  Identity &  │  │   Analytics  │  │   AI/ML      │                   │
│  │  Access      │  │   Context    │  │   Platform   │                   │
│  │              │  │              │  │              │                   │
│  │ • Auth      │  │ • Warehouse  │  │ • Feature    │                   │
│  │ • RBAC      │  │ • Dashboard  │  │   Store      │                   │
│  │ • Teams     │  │ • Reports   │  │ • Training   │                   │
│  │ • API Keys  │  │ • BI        │  │ • Serving    │                   │
│  └──────────────┘  └──────────────┘  └──────────────┘                   │
└──────────────────────────────────────────────────────────────────────────┘

2. コンテキスト マップ — 関係

上流下流関係性統合
デザインカタログ顧客とサプライヤーデザインアセット → 製品画像
カタログ商業出版言語製品データ → ストアフロント
商業注文顧客とサプライヤーチェックアウト → 注文が作成されました
注文生産顧客とサプライヤー注文 → 印刷ジョブ
生産充実顧客とサプライヤー印刷→出荷
すべてのコンテキスト分析適合者イベント → データウェアハウス
AI/MLデザイン、カタログ、制作オープンホストサービスML推論API
チャンネル (Shopify/Etsy)カタログ、注文腐敗防止層外部API → 内部モデル

3. イベント駆動型アーキテクチャ

コアドメインイベント

// Design Context Events
interface DesignCreatedEvent {
  type: 'design.created';
  designId: string;
  designerId: string;
  imageUrl: string;
  metadata: { width: number; height: number; dpi: number };
  timestamp: string;
}

interface DesignApprovedEvent {
  type: 'design.approved';
  designId: string;
  qcScore: number;
  ipCheckResult: 'clean' | 'flagged';
}

// Catalog Context Events
interface ProductPublishedEvent {
  type: 'product.published';
  productId: string;
  designId: string;
  channels: string[];  // ['shopify', 'etsy', 'amazon']
  variants: Array<{ sku: string; size: string; color: string; price: number }>;
}

// Order Context Events
interface OrderCreatedEvent {
  type: 'order.created';
  orderId: string;
  customerId: string;
  items: Array<{ sku: string; quantity: number; designId: string }>;
  shippingAddress: Address;
  totalAmount: number;
}

interface OrderSplitEvent {
  type: 'order.split';
  orderId: string;
  subOrders: Array<{
    subOrderId: string;
    supplierId: string;
    items: Array<{ sku: string; quantity: number }>;
  }>;
}

// Production Context Events
interface PrintJobCompletedEvent {
  type: 'print_job.completed';
  subOrderId: string;
  supplierId: string;
  qcResult: 'pass' | 'fail';
  completedAt: string;
}

// Fulfillment Context Events
interface ShipmentCreatedEvent {
  type: 'shipment.created';
  shipmentId: string;
  orderId: string;
  carrier: string;
  trackingNumber: string;
  estimatedDelivery: string;
}

イベント フロー — 注文のライフサイクル

Commerce                    Order                     Production              Fulfillment
   │                          │                          │                       │
   │  checkout.completed      │                          │                       │
   │─────────────────────────▶│                          │                       │
   │                          │  order.created           │                       │
   │                          │─────────────────────────▶│                       │
   │                          │  order.split             │                       │
   │                          │─────────────────────────▶│                       │
   │                          │                          │  print_job.queued     │
   │                          │                          │──────────────────────▶│
   │                          │                          │  print_job.completed  │
   │                          │◀─────────────────────────│                       │
   │                          │                          │                       │
   │                          │  sub_order.ready_to_ship │                       │
   │                          │──────────────────────────────────────────────────▶│
   │                          │                          │  shipment.created     │
   │                          │◀─────────────────────────────────────────────────│
   │                          │  order.shipped           │                       │
   │                          │──▶ (notify customer)     │                       │

4. CQRSパターン

// Command Side — Write path
interface CreateProductCommand {
  designId: string;
  baseProductIds: string[];
  pricing: PricingConfig;
  publishTo: string[];
}

// Query Side — Read path (denormalized for performance)
interface ProductReadModel {
  id: string;
  title: string;
  designThumbnail: string;
  mockupImages: string[];
  variants: Array<{
    sku: string;
    size: string;
    color: string;
    price: number;
    inStock: boolean;
  }>;
  rating: number;
  reviewCount: number;
  salesCount: number;
  // Denormalized — no JOINs needed
}

5. テクノロジースタック

レイヤーテクノロジー理由
APIゲートウェイKong / AWS API ゲートウェイレート制限、認証、ルーティング
バックエンドサービスNode.js (NestJS) / Go高スループットの TypeScript エコシステム
AI/ML サービスPython (高速API)ML エコシステム、GPU 推論
フロントエンドNext.js / 反応SEO用SSR、デザインスタジオSPA
イベントバスアパッチ カフカ高スループット、イベントソーシング
プライマリDBPostgreSQLACID、JSONB、全文検索
キャッシュRedis クラスターセッション、製品キャッシュ、レート制限
検索エラスティックサーチ / メイリサーチ製品検索、ファセット化
オブジェクトストレージS3/MinIOデザインファイル、モックアップ、印刷ファイル
CDNCloudFront / Cloudflare画像配信、エッジキャッシング
タスクキューBullMQ (Redis)画像処理、メール、同期
GPU推論NVIDIA Triton/vLLMAIデザイン生成、CLIP
オーケストレーションKubernetes (EKS/GKE)自動スケーリング、マルチリージョン
モニタリングプロメテウス + グラファナメトリクス、アラート、ダッシュボード
データウェアハウスクリックハウス / BigQuery分析、レポート作成

6. 高レベルのアーキテクチャ図

                          ┌─────────────┐
                          │   CDN Edge   │
                          │ (Cloudflare) │
                          └──────┬───────┘
                                 │
                          ┌──────▼───────┐
                          │ API Gateway  │
                          │ (Kong)       │
                          └──────┬───────┘
                                 │
              ┌──────────────────┼──────────────────┐
              ▼                  ▼                  ▼
     ┌────────────────┐ ┌───────────────┐ ┌────────────────┐
     │ Design Service │ │Catalog Service│ │Commerce Service│
     │ (NestJS)       │ │ (NestJS)      │ │ (NestJS)       │
     └───────┬────────┘ └───────┬───────┘ └───────┬────────┘
             │                  │                  │
             ▼                  ▼                  ▼
     ┌────────────────────────────────────────────────────┐
     │                  Kafka Cluster                      │
     └────────────────────────┬───────────────────────────┘
              ┌───────────────┼───────────────┐
              ▼               ▼               ▼
     ┌────────────────┐ ┌──────────────┐ ┌────────────────┐
     │ Order Service  │ │ Production   │ │ Fulfillment    │
     │ (NestJS)       │ │ Service (Go) │ │ Service (NestJS│
     └───────┬────────┘ └──────┬───────┘ └───────┬────────┘
             │                 │                  │
             ▼                 ▼                  ▼
     ┌──────────────┐  ┌──────────────┐  ┌──────────────┐
     │ PostgreSQL   │  │ PostgreSQL   │  │ PostgreSQL   │
     │ (Orders)     │  │ (Production) │  │ (Shipping)   │
     └──────────────┘  └──────────────┘  └──────────────┘

     ┌────────────────┐ ┌──────────────┐ ┌────────────────┐
     │ AI/ML Service  │ │ Analytics    │ │ Channel Sync   │
     │ (FastAPI+GPU)  │ │ (ClickHouse) │ │ (Workers)      │
     └────────────────┘ └──────────────┘ └────────────────┘

7. データ フロー パターン

流れパターンレイテンシ
デザイン → モックアップ同期(リアルタイムプレビュー)< 2秒
設計→QC/IPチェック非同期 (キュー)5~30秒
製品 → チャンネル同期非同期 (イベント → ワーカー)1~5分
受注→生産非同期 (サガ オーケストレーター)秒。秒
生産 → 品質管理同期(インライン)< 5秒
すべて → 分析非同期 (CDC → Kafka → DW)1~5分
製品検索CQRS読み取りモデル< 100ms

8. まとめ

  • 9 境界のあるコンテキスト — デザイン、カタログ、コマース、注文、生産、フルフィルメント、アイデンティティ、分析、AI/ML

  • イベント駆動型 — Kafka イベント バス、疎結合用のドメイン イベント

  • CQRS — パフォーマンスのために読み取り/書き込みを分離 (製品カタログ、検索)

  • サーガパターン — 注文ライフサイクルの分散トランザクション

  • 技術スタック — NestJS + Go + FastAPI + PostgreSQL + Kafka + Redis + K8s