
Written on 13th April 2026 by Carter Phan.
Export trực tiếp (sync) → timeout / OOM / DB overload
Vì:
Client → API → Query 1M rows → build file → return
Hậu quả:
User click Export
↓
API create export job
↓
Return job_id (ngay lập tức)
↓
Worker xử lý background
↓
Generate file (CSV)
↓
Upload S3 / storage
↓
Notify user (email / UI)
{
"job_id":"uuid",
"status":"pending",
"filters": {...}
}
Dùng:
❌ Không dùng:
LIMIT1000000 OFFSET ...
WHERE id> last_id
LIMIT1000
Loop:
fetch 1000 → write file → next batch
Không build file trong memory
Upload:
⇒ Không trả file trực tiếp qua API
→ Fix: read replica / throttle
→ Fix: streaming + batch
→ Fix: snapshot / consistent query
→ Fix: async + parallel