Chạy production app với chi phí gần như 0đ
Hướng dẫn cấu trúc project để tận dụng tối đa Firebase Free Tier (Spark Plan).
Giới hạn Spark Plan (miễn phí):
- Firestore: 1GB storage, 50K reads/day, 20K writes/day
- Authentication: Unlimited users
- Hosting: 10GB storage, 360MB/day transfer
- Functions: 2 triệu invocations/month (Blaze only)
Chiến lược tối ưu:
- Firestore reads:
- Cache data ở client (React Query, SWR)
- Sử dụng pagination thay vì load all
- Denormalize data để giảm queries
Prompt: "Refactor Firestore query này để giảm số reads:
// Hiện tại: 1 read cho mỗi post + N reads cho mỗi author
const posts = await getDocs(collection(db, 'posts'));
for (const post of posts.docs) {
const author = await getDoc(doc(db, 'profiles', post.data().authorId));
}
```"
Gemini gợi ý: Embed author info vào post document (denormalization)
2. **Hosting bandwidth:**
- Optimize images (WebP, lazy loading)
- Enable caching headers
- Sử dụng CDN external cho static assets lớn
3. **Cloud Functions (nếu dùng Blaze):**
- Set memory thấp nhất có thể
- Timeout ngắn
- Cold start optimization
**Monitoring chi phí:**
Firebase Console > Usage and billing
- Set budget alerts: Thông báo khi vượt $5, $10...
- Gemini: "Phân tích usage report này và gợi ý cách giảm 30% chi phí"
**Kết luận:**
Với Vibe Coding + Firebase Free Tier, bạn có thể chạy app phục vụ hàng nghìn users mà không tốn đồng nào!
