Cloudflare Workers 2026 — Xây dựng Full-Stack trên Edge với Zero Cold Start và Zero Egress
Posted on: 4/17/2026 2:15:08 PM
Table of contents
- V8 Isolates — Bí mật đằng sau Zero Cold Start
- Hệ sinh thái Cloudflare cho Developer 2026
- Cloudflare Containers — Game Changer tháng 4/2026
- Free Tier chi tiết — Xây dựng Production App với $0
- So sánh Edge Platform: Cloudflare vs AWS vs Azure vs Vercel
- Architecture Patterns thực tế trên Cloudflare Edge
- Workflows — Durable Execution cho Edge
- Hyperdrive — Tăng tốc Database hiện tại
- Cloudflare Pages — JAMstack không giới hạn
- Wrangler CLI — Developer Experience
- Lộ trình phát triển Cloudflare Developer Platform
- Best Practices khi xây dựng trên Cloudflare
- Kết luận
- Tham khảo
Khi người dùng truy cập website từ Việt Nam nhưng server đặt tại US-East, mỗi request phải vượt qua hàng chục nghìn km — thêm 200-400ms latency chỉ vì khoảng cách vật lý. Edge Computing giải quyết triệt để vấn đề này bằng cách đưa code chạy ngay tại điểm gần người dùng nhất. Và trong cuộc đua edge platform, Cloudflare Workers đang dẫn đầu với hệ sinh thái toàn diện nhất cho developer năm 2026.
Bài viết này sẽ đi sâu vào kiến trúc, từng dịch vụ trong hệ sinh thái Cloudflare, free tier chi tiết, so sánh với AWS/Azure/Vercel, và các architecture pattern thực tế để bạn có thể xây dựng full-stack application chạy hoàn toàn trên edge.
V8 Isolates — Bí mật đằng sau Zero Cold Start
Điểm khác biệt cốt lõi của Cloudflare Workers so với AWS Lambda hay Azure Functions nằm ở mô hình runtime. Thay vì spin up container cho mỗi function invocation (tốn 100-2000ms), Workers sử dụng V8 Isolates — cùng engine JavaScript mà Chrome sử dụng.
Mỗi Worker chạy trong một isolate riêng biệt, được tạo trong chưa đầy 1 millisecond. Các isolate chia sẻ cùng một process nhưng hoàn toàn cách ly về memory — không có shared state, không có side-channel attacks. Đây là cùng mô hình security mà browser dùng để cách ly các tab.
graph TB
subgraph Traditional["Container-based (Lambda/Azure)"]
direction TB
R1["Request"] --> CS["Cold Start 100-2000ms"]
CS --> C1["Container Boot"]
C1 --> RT1["Runtime Init"]
RT1 --> EX1["Execute Code"]
end
subgraph Workers["V8 Isolate-based (CF Workers)"]
direction TB
R2["Request"] --> IS["Isolate Spawn <1ms"]
IS --> EX2["Execute Code ngay lập tức"]
end
style Traditional fill:#f8f9fa,stroke:#e0e0e0,color:#2c3e50
style Workers fill:#f8f9fa,stroke:#e94560,color:#2c3e50
style CS fill:#ff9800,stroke:#fff,color:#fff
style IS fill:#4CAF50,stroke:#fff,color:#fff
Hình 1: So sánh mô hình khởi tạo Container vs V8 Isolate
CPU Time Billing — Chỉ trả tiền khi CPU thực sự làm việc
Từ 2024, Workers chuyển sang Standard pricing tính theo CPU time thay vì wall-clock time. Nghĩa là nếu Worker đang await fetch() chờ API response trong 2 giây, bạn không trả đồng nào cho thời gian chờ đó. Chỉ tính tiền khi CPU thực sự tính toán — parsing JSON, transform data, render HTML. Đây là thay đổi game-changing cho I/O-heavy workloads.
Hệ sinh thái Cloudflare cho Developer 2026
Sức mạnh thực sự của Cloudflare không nằm ở riêng Workers, mà ở hệ sinh thái tích hợp chặt chẽ — tất cả các dịch vụ chạy trên cùng một mạng lưới, giao tiếp với nhau gần như zero-latency.
graph LR
subgraph Edge["Cloudflare Edge Network"]
W["Workers
Compute"] --> D1["D1
SQL Database"]
W --> KV["KV
Key-Value Store"]
W --> R2["R2
Object Storage"]
W --> DO["Durable Objects
Stateful Edge"]
W --> Q["Queues
Message Queue"]
W --> AI["Workers AI
Inference"]
W --> VE["Vectorize
Vector DB"]
W --> HD["Hyperdrive
DB Accelerator"]
end
U["Người dùng"] --> W
HD --> DB["PostgreSQL/MySQL
Origin DB"]
style Edge fill:#f8f9fa,stroke:#e0e0e0,color:#2c3e50
style W fill:#e94560,stroke:#fff,color:#fff
style U fill:#2c3e50,stroke:#fff,color:#fff
style DB fill:#2c3e50,stroke:#fff,color:#fff
Hình 2: Hệ sinh thái Cloudflare Developer Platform 2026
D1 — Serverless SQL Database trên Edge
D1 là database SQLite chạy trên edge với global read replication. Write operations được route đến primary instance, còn read queries được phục vụ từ replica gần nhất — pattern quen thuộc nhưng được Cloudflare tự động hóa hoàn toàn.
Những cải tiến đáng chú ý trong 2025-2026:
- Storage limit tăng từ 250 GB lên 1 TB mỗi database (tháng 7/2025)
- Worker API latency giảm 40-60% nhờ loại bỏ redundant network round trips
- Jurisdiction support cho data localization — quan trọng với GDPR và các quy định vùng (tháng 11/2025)
- Time Travel cho point-in-time backup và disaster recovery
- Tự động retry read-only queries lên đến 2 lần khi gặp lỗi tạm thời
// Ví dụ: Query D1 từ Worker
export default {
async fetch(request: Request, env: Env) {
const url = new URL(request.url);
const slug = url.pathname.slice(1);
const post = await env.DB.prepare(
"SELECT title, body, created_at FROM posts WHERE slug = ?"
).bind(slug).first();
if (!post) return new Response("Not Found", { status: 404 });
return new Response(JSON.stringify(post), {
headers: { "Content-Type": "application/json" }
});
}
};R2 — Object Storage không tốn Egress
R2 là câu trả lời của Cloudflare cho Amazon S3, với một khác biệt quyết định: zero egress fees. Với S3, bandwidth ra ngoài tốn $0.09/GB — một ứng dụng phục vụ 10 TB/tháng sẽ tốn $900 chỉ riêng egress. R2 cho phép bạn phục vụ cùng lượng data đó với $0.
R2 tương thích S3 API, nên bạn có thể sử dụng bất kỳ S3 SDK nào. Migration từ S3 sang R2 thường chỉ cần đổi endpoint URL.
| Tiêu chí | Cloudflare R2 | Amazon S3 | Azure Blob |
|---|---|---|---|
| Standard Storage | $0.015/GB/tháng | $0.023/GB/tháng | $0.018/GB/tháng |
| Egress | $0 (miễn phí) | $0.09/GB | $0.087/GB |
| Class A ops (PUT) | $4.50/triệu | $5.00/triệu | $5.40/triệu |
| Class B ops (GET) | $0.36/triệu | $0.40/triệu | $0.40/triệu |
| Free tier storage | 10 GB | 5 GB (12 tháng) | 5 GB (12 tháng) |
| Infrequent Access | $0.01/GB/tháng | $0.0125/GB/tháng | $0.01/GB/tháng |
KV — Global Key-Value Store
Workers KV là key-value store eventually consistent được tối ưu cho read-heavy workloads. Data được replicate đến tất cả 330+ edge locations, nên read latency cực thấp từ bất kỳ đâu trên thế giới.
Tuy nhiên, KV có trade-off quan trọng: writes có thể mất đến 60 giây để propagate globally. Điều này khiến KV phù hợp cho:
- Configuration và feature flags
- Cached API responses
- Static metadata (user profiles, product info)
- Session data (khi chấp nhận eventual consistency)
Khi nào KHÔNG dùng KV
Nếu bạn cần strong consistency (đọc ngay sau khi ghi phải thấy giá trị mới), hãy dùng Durable Objects thay vì KV. Ví dụ: counter real-time, inventory stock, auction bidding — những use case mà stale read có thể gây hậu quả nghiêm trọng.
Durable Objects — Stateful Computing trên Edge
Durable Objects (DO) là tính năng độc đáo nhất trong hệ sinh thái Cloudflare — cho phép bạn có state có địa chỉ (addressable state) trên edge. Mỗi Durable Object là một instance duy nhất trên toàn mạng, có riêng storage (giờ là SQLite) và có thể xử lý WebSocket connections.
Điều này mở ra các use case mà trước đây không thể làm trên edge:
// Chat room với Durable Object
export class ChatRoom extends DurableObject {
private sessions: WebSocket[] = [];
async fetch(request: Request) {
const pair = new WebSocketPair();
this.ctx.acceptWebSocket(pair[1]);
this.sessions.push(pair[1]);
return new Response(null, { status: 101, webSocket: pair[0] });
}
async webSocketMessage(ws: WebSocket, message: string) {
// Broadcast tin nhắn đến tất cả sessions trong room
const data = JSON.parse(message);
const broadcast = JSON.stringify({
sender: data.sender,
text: data.text,
timestamp: Date.now()
});
for (const session of this.sessions) {
if (session !== ws && session.readyState === WebSocket.OPEN) {
session.send(broadcast);
}
}
// Lưu vào SQLite storage của Durable Object
this.ctx.storage.sql.exec(
"INSERT INTO messages (sender, text, ts) VALUES (?, ?, ?)",
data.sender, data.text, Date.now()
);
}
}Durable Objects giờ hỗ trợ SQLite storage API (GA, không còn beta), cho phép mỗi object có riêng một SQLite database lên đến 10 GB. Kết hợp với WebSocket support, đây là nền tảng lý tưởng cho real-time collaboration, multiplayer games, và distributed coordination.
Queues — Message Queue trên Edge
Cloudflare Queues cung cấp guaranteed message delivery cho async processing. Từ tháng 2/2026, Queues đã có mặt trên Free plan — một bước tiến lớn cho developer muốn thử nghiệm event-driven architecture mà không tốn chi phí.
Queues hỗ trợ hai consumer mode: Workers consumer (tự động trigger Worker khi có message) và HTTP pull consumer (pull messages từ bất kỳ service nào qua HTTP). Điều này giúp tích hợp với hệ thống hiện tại rất linh hoạt.
Workers AI — Inference trên Edge
Workers AI cho phép chạy inference các model AI (Llama, Mistral, Stable Diffusion, embedding models) trực tiếp trên edge — không cần provision GPU, không cần manage infrastructure. Billing theo Neurons — đơn vị tính toán chuẩn hóa: $0.011 per 1,000 Neurons.
Kết hợp với Vectorize (vector database) và AutoRAG (managed RAG pipeline — đang beta miễn phí), bạn có thể xây dựng AI application hoàn chỉnh trên edge: upload documents lên R2, AutoRAG tự động chunking + embedding + lưu vào Vectorize, Workers AI thực hiện inference với context từ vector search.
Cloudflare Containers — Game Changer tháng 4/2026
Tính năng được mong đợi nhất vừa GA vào tháng 4/2026: Cloudflare Containers. Giờ đây bạn có thể chạy full Linux containers trên Cloudflare edge, sử dụng Firecracker microVMs — cùng công nghệ mà AWS Lambda sử dụng bên dưới.
| Instance Type | Memory | Phù hợp cho |
|---|---|---|
| Dev | 256 MiB | Prototyping, lightweight services |
| Basic | 1 GiB | API servers, background workers |
| Standard | 4 GiB | Data processing, ML inference |
Containers được billing theo 10ms granularity, hỗ trợ Docker Hub images, SSH access cho debugging, và preview URLs cho testing. Điều này giải quyết hạn chế lớn nhất của Workers: giờ bạn có thể chạy bất kỳ language/runtime nào (Python, Go, Rust, Java) trên Cloudflare edge, không chỉ giới hạn ở JavaScript/TypeScript/WASM.
Workers vs Containers — Khi nào dùng gì?
Workers (V8 Isolates): Cho request-response workloads cần ultra-low latency (<1ms cold start), JavaScript/TypeScript code, memory ≤128 MB. Ví dụ: API gateway, SSR, routing, auth middleware.
Containers (Firecracker): Cho workloads cần nhiều memory (lên đến 4 GiB), chạy non-JS runtime, long-running processes, hoặc cần full Linux environment. Ví dụ: data processing, ML model serving, headless browser.
Free Tier chi tiết — Xây dựng Production App với $0
Một trong những lý do Cloudflare hấp dẫn nhất với developer và startup là free tier cực kỳ hào phóng. Bạn hoàn toàn có thể chạy production application với traffic vừa phải mà không tốn đồng nào.
| Dịch vụ | Free Tier | Ghi chú |
|---|---|---|
| Workers | 100,000 requests/ngày | ~3 triệu requests/tháng |
| Pages | Unlimited bandwidth, 500 builds/tháng | Unlimited sites |
| R2 | 10 GB storage, 10M GET/tháng | Zero egress luôn |
| D1 | 5M reads/ngày, 100K writes/ngày, 5 GB | Lên đến 50,000 databases |
| KV | 100K reads/ngày, 1K writes/ngày, 1 GB | Eventually consistent |
| Queues | 10,000 ops/ngày | Mới có từ 02/2026 |
| Durable Objects | SQLite-backed DOs có sẵn | Free plan |
| Hyperdrive | 100,000 queries/ngày | Accelerate Postgres/MySQL |
| AI Gateway | Có sẵn trên mọi plan | Proxy AI API calls |
| AutoRAG | Open beta, miễn phí | Managed RAG pipeline |
Ước tính cho blog/portfolio cá nhân
Một blog cá nhân với ~1,000 unique visitors/ngày, mỗi người xem trung bình 3 trang = ~3,000 requests/ngày. Free tier Workers cho phép 100,000 requests/ngày — dư sức gấp 33 lần. Kết hợp Pages cho static hosting (unlimited bandwidth) và D1 cho database (5M reads/ngày), bạn có full-stack blog chạy hoàn toàn miễn phí.
So sánh Edge Platform: Cloudflare vs AWS vs Azure vs Vercel
| Tiêu chí | CF Workers | AWS Lambda@Edge | Azure Functions | Vercel Edge |
|---|---|---|---|---|
| Edge locations | 330+ | ~20-30 | ~60 | ~30 |
| Cold start | <1ms | 100-1000ms | 200-2000ms | ~5ms |
| Max memory | 128 MB (4 GiB containers) | 3 GB | 1.5 GB | 128 MB |
| Max execution | 30s (5 phút paid) | 30s | 10 phút | 30s |
| Free requests | 100K/ngày | 1M/tháng | 1M/tháng | 100K/tháng |
| Egress fees | $0 | $0.09/GB | $0.087/GB | Included |
| Runtime | JS/TS/WASM + Containers | Node.js, Python | .NET, JS, Python, Java | JS/TS |
| Integrated DB | D1, KV, DO | DynamoDB (separate) | CosmosDB (separate) | KV, Postgres |
| Paid base | $5/tháng | Pay-per-use | Pay-per-use | $20/tháng |
Khi nào chọn Cloudflare: Bạn cần ultra-low latency toàn cầu, zero egress, hệ sinh thái tích hợp chặt chẽ, và muốn simple pricing. Phù hợp nhất cho web apps, API gateways, edge-first architectures.
Khi nào chọn AWS/Azure: Enterprise workloads cần 200+ integrated services, heavy compute (>4 GB memory), mature compliance frameworks, hoặc đã có investment lớn vào ecosystem hiện tại.
Architecture Patterns thực tế trên Cloudflare Edge
Pattern 1: Full-Stack Edge Application
Đây là pattern phổ biến nhất — toàn bộ application chạy trên edge, không cần origin server.
graph LR
U["Người dùng"] --> W["Worker
SSR + API + Auth"]
W --> D1["D1
Posts, Users, Comments"]
W --> R2["R2
Images, Files"]
W --> KV["KV
Sessions, Cache"]
W --> Q["Queues"]
Q --> W2["Worker
Background Jobs"]
W2 --> R2
style U fill:#2c3e50,stroke:#fff,color:#fff
style W fill:#e94560,stroke:#fff,color:#fff
style W2 fill:#e94560,stroke:#fff,color:#fff
style D1 fill:#f8f9fa,stroke:#e0e0e0,color:#2c3e50
style R2 fill:#f8f9fa,stroke:#e0e0e0,color:#2c3e50
style KV fill:#f8f9fa,stroke:#e0e0e0,color:#2c3e50
style Q fill:#f8f9fa,stroke:#e0e0e0,color:#2c3e50
Hình 3: Full-Stack Edge Application — không cần origin server
Worker đóng vai trò vừa là web server (SSR), vừa là API server, vừa xử lý authentication. D1 lưu trữ dữ liệu quan hệ, R2 chứa static assets và file uploads, KV quản lý sessions và cached data. Queues xử lý background jobs như resize images hay gửi email.
Pattern 2: Hybrid Edge + Origin
Cho hệ thống đã có origin server (ví dụ .NET API trên Azure, Node.js trên AWS), Workers đóng vai trò smart edge layer:
export default {
async fetch(request: Request, env: Env) {
const url = new URL(request.url);
// 1. Auth check tại edge — không cần round-trip về origin
const token = request.headers.get("Authorization");
const session = await env.KV.get(`session:${token}`);
if (!session) return new Response("Unauthorized", { status: 401 });
// 2. Feature flags từ KV
const flags = JSON.parse(await env.KV.get("feature-flags") || "{}");
// 3. A/B testing dựa trên geo
const country = request.cf?.country || "US";
const variant = flags.newCheckout?.includes(country) ? "v2" : "v1";
// 4. Rate limiting với Durable Object
const limiter = env.RATE_LIMITER.get(
env.RATE_LIMITER.idFromName(session)
);
const allowed = await limiter.fetch("/check");
if (!allowed.ok) return new Response("Too Many Requests", { status: 429 });
// 5. Forward đến origin với context
const origin = await fetch(`${env.ORIGIN_URL}${url.pathname}`, {
headers: {
...Object.fromEntries(request.headers),
"X-User-Session": session,
"X-AB-Variant": variant,
"X-Country": country
}
});
return origin;
}
};Pattern này đặc biệt hiệu quả khi bạn muốn thêm edge capabilities vào hệ thống hiện tại mà không cần rewrite toàn bộ. Auth, rate limiting, A/B testing, và geolocation routing đều xử lý tại edge — giảm tải cho origin server và cải thiện latency cho end user.
Pattern 3: Real-Time Collaboration với Durable Objects
graph TB
U1["User A
Hà Nội"] -->|WebSocket| DO["Durable Object
Room #42
SQLite State"]
U2["User B
HCM"] -->|WebSocket| DO
U3["User C
Đà Nẵng"] -->|WebSocket| DO
DO -->|Persist| D1["D1
Long-term Storage"]
DO -->|Notify| Q["Queues
Async Events"]
style DO fill:#e94560,stroke:#fff,color:#fff
style U1 fill:#2c3e50,stroke:#fff,color:#fff
style U2 fill:#2c3e50,stroke:#fff,color:#fff
style U3 fill:#2c3e50,stroke:#fff,color:#fff
style D1 fill:#f8f9fa,stroke:#e0e0e0,color:#2c3e50
style Q fill:#f8f9fa,stroke:#e0e0e0,color:#2c3e50
Hình 4: Real-Time Collaboration — mỗi room là một Durable Object
Mỗi Durable Object đại diện cho một "room" (chat room, collaborative document, game session). Tất cả WebSocket connections cho cùng một room được route đến cùng một DO instance — đảm bảo strong consistency trong room đó. DO có SQLite storage riêng cho state ngắn hạn, và periodically sync xuống D1 cho long-term persistence.
Pattern 4: AI-Augmented Edge Application
graph LR
U["Upload PDF"] --> R2["R2 Storage"]
R2 -->|Event| Q["Queues"]
Q --> W["Worker
Processing"]
W -->|Chunk + Embed| AI["Workers AI
Embedding Model"]
AI --> VE["Vectorize
Vector DB"]
U2["User Query"] --> W2["Worker
Search API"]
W2 --> VE
VE -->|Top-K results| W2
W2 -->|Context + Query| AI2["Workers AI
LLM Inference"]
AI2 --> W2
W2 -->|Answer| U2
style U fill:#2c3e50,stroke:#fff,color:#fff
style U2 fill:#2c3e50,stroke:#fff,color:#fff
style W fill:#e94560,stroke:#fff,color:#fff
style W2 fill:#e94560,stroke:#fff,color:#fff
style R2 fill:#f8f9fa,stroke:#e0e0e0,color:#2c3e50
style Q fill:#f8f9fa,stroke:#e0e0e0,color:#2c3e50
style AI fill:#4CAF50,stroke:#fff,color:#fff
style AI2 fill:#4CAF50,stroke:#fff,color:#fff
style VE fill:#f8f9fa,stroke:#e0e0e0,color:#2c3e50
Hình 5: RAG Pipeline hoàn chỉnh trên Cloudflare Edge
Đây là pattern xây dựng RAG (Retrieval-Augmented Generation) hoàn toàn trên edge. Upload documents lên R2, trigger processing qua Queues, Workers AI tạo embeddings lưu vào Vectorize. Khi user query, vector search tìm relevant context, rồi LLM generate câu trả lời. Toàn bộ pipeline chạy trên Cloudflare — không cần external vector DB hay GPU server.
Workflows — Durable Execution cho Edge
Cloudflare Workflows (GA 2025) mang đến durable execution — khả năng chạy multi-step processes với automatic retry và state persistence. Nếu bạn quen với Temporal hay Azure Durable Functions, Workflows là phiên bản edge-native của concept đó.
import { WorkflowEntrypoint, WorkflowStep } from "cloudflare:workers";
export class OrderWorkflow extends WorkflowEntrypoint {
async run(event: WorkflowEvent, step: WorkflowStep) {
// Step 1: Validate order
const order = await step.do("validate", async () => {
return await this.env.DB.prepare(
"SELECT * FROM orders WHERE id = ?"
).bind(event.payload.orderId).first();
});
// Step 2: Process payment (auto-retry on failure)
const payment = await step.do("charge", async () => {
const res = await fetch("https://api.stripe.com/v1/charges", {
method: "POST",
headers: { Authorization: `Bearer ${this.env.STRIPE_KEY}` },
body: new URLSearchParams({ amount: order.total.toString() })
});
if (!res.ok) throw new Error("Payment failed");
return res.json();
});
// Step 3: Send confirmation
await step.do("notify", async () => {
await this.env.QUEUE.send({
type: "order_confirmed",
orderId: order.id,
paymentId: payment.id
});
});
}
}Mỗi step.do() được persist — nếu Worker crash giữa step 2 và step 3, workflow tự động resume từ step 3 mà không re-execute payment. Đây là tính năng critical cho business logic quan trọng (payments, order processing, data pipelines).
Hyperdrive — Tăng tốc Database hiện tại
Không phải ai cũng muốn migrate toàn bộ data sang D1. Hyperdrive giải quyết bài toán này bằng cách đóng vai trò database accelerator — giữ connection pool ấm sẵn tại edge và cache query results.
Hyperdrive hỗ trợ PostgreSQL và MySQL, tương thích với các managed database như Neon, PlanetScale, CockroachDB, Supabase, RDS, Cloud SQL. Free tier cho phép 100,000 queries/ngày.
Kết hợp Hyperdrive + D1 trong cùng project
Một pattern hiệu quả: dùng D1 cho data thuần edge (sessions, cache, feature flags, analytics), dùng Hyperdrive để query PostgreSQL gốc cho business-critical data cần strong consistency và complex queries mà SQLite không cover tốt (JOINs phức tạp, stored procedures, full-text search nâng cao).
Cloudflare Pages — JAMstack không giới hạn
Pages là hosting platform cho static sites và full-stack frameworks (Next.js, Nuxt, SvelteKit, Astro). Điểm nổi bật nhất: unlimited bandwidth trên free tier — không giới hạn traffic cho static assets.
Pages Functions (serverless backend logic) chạy trên Workers runtime, nên bạn có tất cả capabilities của Workers trong Pages project. Mỗi git push tự động trigger build và deploy, với branch preview URLs cho testing.
Hỗ trợ mới nhất: Node.js v22 mặc định, pnpm 10, tăng giới hạn files lên 100,000 trên paid plan.
Wrangler CLI — Developer Experience
Wrangler là CLI tool chính thức để develop, test, và deploy Workers. Một vài lệnh quan trọng:
# Tạo project mới
npx wrangler init my-worker
# Dev server với hot-reload
npx wrangler dev
# Deploy lên production
npx wrangler deploy
# Tạo D1 database
npx wrangler d1 create my-db
npx wrangler d1 execute my-db --local --file=./schema.sql
# Upload file lên R2
npx wrangler r2 object put my-bucket/image.png --file=./image.png
# Tail logs real-time
npx wrangler tailwrangler dev chạy local development server mô phỏng Cloudflare runtime — bao gồm D1, KV, R2, Durable Objects — cho phép test offline trước khi deploy. Đây là trải nghiệm development mượt mà hơn đáng kể so với AWS SAM/CDK hay Azure Functions Core Tools.
Lộ trình phát triển Cloudflare Developer Platform
Best Practices khi xây dựng trên Cloudflare
- Đưa auth và rate limiting lên edge — giảm tải origin, chặn abuse sớm nhất có thể
- Dùng KV cho read-heavy, DO cho write-heavy — hiểu rõ consistency model trước khi chọn
- Cache aggressively với KV — edge read latency gần 0, tận dụng tối đa
- D1 cho relational data vừa phải — SQLite phù hợp với hầu hết web apps, nhưng complex analytics nên dùng Hyperdrive + PostgreSQL
- Queues cho decoupling — tách image processing, email sending, webhook delivery ra khỏi request path
- Workers cho latency-sensitive, Containers cho compute-heavy — không ép mọi thứ vào 128 MB isolate
- Giữ payment processing tại origin — business-critical financial logic nên ở nơi bạn control hoàn toàn, với audit trail đầy đủ
Kết luận
Cloudflare đã xây dựng một hệ sinh thái đáng kinh ngạc trong vài năm qua — từ một CDN/security company trở thành full-stack edge platform cạnh tranh trực tiếp với AWS, Azure, và GCP. Với Containers GA vào tháng 4/2026, rào cản cuối cùng (giới hạn runtime) đã được tháo bỏ.
Đối với developer Việt Nam, Cloudflare đặc biệt hấp dẫn vì ba lý do: free tier hào phóng để học và prototyping, zero egress fees giúp kiểm soát chi phí khi scale, và mạng lưới edge bao gồm các PoP tại Singapore và Hong Kong — gần Việt Nam hơn bất kỳ US-based cloud nào.
Nếu bạn đang bắt đầu dự án mới hoặc muốn thêm edge layer cho hệ thống hiện tại, Cloudflare Workers là lựa chọn đáng cân nhắc nghiêm túc. Bắt đầu với npx wrangler init và khám phá.
Tham khảo
- Cloudflare Workers Documentation
- Workers Pricing — Never Pay to Wait on I/O Again
- Cloudflare D1 Documentation
- Cloudflare R2 Pricing
- Durable Objects Documentation
- Cloudflare Queues Documentation
- Cloudflare Containers Announcement
- Workers AI Documentation
- Introducing AutoRAG on Cloudflare
- SQLite in Durable Objects
Resilience Patterns trên .NET 10 — Polly, Circuit Breaker và Retry cho Microservices
AWS Lambda Serverless 2026: Kiến trúc, SnapStart, Event-Driven Patterns và Free Tier cho Production
Disclaimer: The opinions expressed in this blog are solely my own and do not reflect the views or opinions of my employer or any affiliated organizations. The content provided is for informational and educational purposes only and should not be taken as professional advice. While I strive to provide accurate and up-to-date information, I make no warranties or guarantees about the completeness, reliability, or accuracy of the content. Readers are encouraged to verify the information and seek independent advice as needed. I disclaim any liability for decisions or actions taken based on the content of this blog.