1. POD 中的性能熱點
- 圖片流量大(模型、預覽、縮圖)
- 搜尋/過濾大目錄
- 按活動/季節爆發流量
- 後台作業:渲染、AI、同步頻道
2.CDN策略
Origin (S3/Object Storage)
-> CDN Edge Cache
-> Image transformation layer (WebP/AVIF, resize)
-> Browser cache
| 資產類型 | TTL | 快取鍵 |
|---|---|---|
| 不可變的模型 | 30-90天 | 基於哈希的 URL |
| 電漿影像 | 7天 | 產品 ID+型號+尺寸 |
| 編輯器資產 | 1-24小時 | 使用者範圍 |
3.多層緩存
L1: CDN edge
L2: API cache (Redis)
L3: Application in-memory cache
L4: DB query cache/materialized views
class ProductReadCache {
async get(productId: string) {
const key = `pdp:${productId}`;
const cached = await redis.get(key);
if (cached) return JSON.parse(cached);
const value = await this.repo.getPdpView(productId);
await redis.set(key, JSON.stringify(value), 'EX', 300);
return value;
}
}
4. 隊列架構
Queues
- q.realtime.preview (high priority)
- q.print.production (high priority)
- q.mockup.batch (medium)
- q.channel.sync (medium)
- q.analytics.enrichment (low)
Use dead-letter queues per domain.
interface QueuePolicy {
maxRetry: number;
backoffMs: number[];
timeoutMs: number;
concurrency: number;
}
5. 資料庫擴展
- 產品/搜尋讀取的讀取副本
- 分區如下 `shop_id` 或 `created_at` 帶大板
- 連接池(PgBouncer)
- 根據查詢模式的索引策略
6. 自動伸縮策略
| 工作量 | 秤觸發 | 範圍 |
|---|---|---|
| API 容器 | CPU+P95延遲 | 4-60 |
| 隊列工人 | 隊列深度+滯後 | 2-200 |
| GPU推理 | 請求數/秒 + VRAM | 1-20 |
7. 推薦的 SLO
- P95 PDP API 延遲 < 250ms
- P95 結帳 API 延遲 < 400 毫秒
- 影像首字節 (CDN) < 100ms
- 佇列延遲(嚴重)< 30 秒
八、總結
CDN+圖片優化 是 POD 最大的性能槓桿
佇列優先權 有助於在高負載期間保護關鍵工作流程
資料庫擴充 需要遵守查詢/索引規則
SLO 驅動的自動縮放 有助於平衡成本和服務質量