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 |
| イベントバス | アパッチ カフカ | 高スループット、イベントソーシング |
| プライマリDB | PostgreSQL | ACID、JSONB、全文検索 |
| キャッシュ | Redis クラスター | セッション、製品キャッシュ、レート制限 |
| 検索 | エラスティックサーチ / メイリサーチ | 製品検索、ファセット化 |
| オブジェクトストレージ | S3/MinIO | デザインファイル、モックアップ、印刷ファイル |
| CDN | CloudFront / Cloudflare | 画像配信、エッジキャッシング |
| タスクキュー | BullMQ (Redis) | 画像処理、メール、同期 |
| GPU推論 | NVIDIA Triton/vLLM | AIデザイン生成、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