1. Performance Hotspots trong POD
- Image-heavy traffic (mockups, previews, thumbnails)
- Search/filter catalog lớn
- Burst traffic theo campaign/season
- Background jobs: rendering, AI, sync channel
2. CDN Strategy
Origin (S3/Object Storage)
-> CDN Edge Cache
-> Image transformation layer (WebP/AVIF, resize)
-> Browser cache
| Asset type | TTL | Cache key |
|---|---|---|
| Mockup immutable | 30-90 ngày | hash-based URL |
| PDP images | 7 ngày | productId+variant+size |
| Editor assets | 1-24h | user scope |
3. Multi-layer Caching
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. Queue Architecture
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. Database Scaling
- Read replicas cho product/search reads
- Partitioning theo `shop_id` hoặc `created_at` với bảng lớn
- Connection pooling (PgBouncer)
- Index strategy theo query patterns
6. Auto-scaling Policies
| Workload | Scale trigger | Range |
|---|---|---|
| API pods | CPU + P95 latency | 4-60 |
| Queue workers | Queue depth + lag | 2-200 |
| GPU inference | Requests/sec + VRAM | 1-20 |
7. SLO đề xuất
- P95 PDP API latency < 250ms
- P95 checkout API latency < 400ms
- Image first byte (CDN) < 100ms
- Queue lag (critical) < 30s
8. Tổng kết
CDN + image optimization là đòn bẩy hiệu năng lớn nhất cho POD
Queue priority giúp bảo vệ workflow quan trọng khi tải cao
DB scaling cần đi cùng query/index discipline
SLO-driven autoscaling giúp cân bằng chi phí và chất lượng dịch vụ