Developer Platform Developer Platform

Build và deploy app trên Cloudflare Build and deploy apps on Cloudflare

Lộ trình cho developer muốn deploy frontend, API, backend serverless hoặc app có AI. Bạn sẽ đi từ static site trên Pages đến Worker, storage (KV/D1/R2) và tích hợp cơ bản. For developers deploying frontends, APIs, serverless backends, or AI apps. You will go from a static Pages site to Workers, storage (KV/D1/R2), and basic integrations.

Ai nên học lộ trình này? Who is this for?

Developer, full-stack engineer, hoặc team build internal tool / MVP / side project muốn ship nhanh không quản lý server. Developers, full-stack engineers, or teams building internal tools, MVPs, or side projects who want to ship fast without managing servers.

Mô hình tư duy Mental model

User → Cloudflare edge (Pages / Workers) → KV / D1 / R2 / external API. Code chạy gần user, data lưu trên platform bindings. User → Cloudflare edge (Pages / Workers) → KV / D1 / R2 / external API. Code runs near users; data lives in platform bindings.

Sơ đồ kiến trúc tham chiếu Reference architecture diagrams

Figure 1: Cloudflare Developer Platform

Fullstack applications Fullstack applications

Ví dụ fullstack trên Developer Platform — Workers/Pages, storage và AI services trong một kiến trúc thực tế. A practical example of how these services come together in a real fullstack application architecture.

Thuật ngữ: Concepts: Workers · Pages · D1 · R2 · KV · Durable Objects

Sơ đồ chính thức ↗ Official diagram ↗ · Serverless Serverless

Figure 1: Knowledge seeding

Retrieval Augmented Generation (RAG) Retrieval Augmented Generation (RAG)

RAG kết hợp retrieval (Vectorize/KV) với Workers AI để chatbot trả lời chính xác hơn — seeding knowledge và query path tách biệt. RAG combines retrieval with generative models for better text. It uses external knowledge to create factual, relevant responses, improving coherence and accuracy in NLP tasks like chatbots.

Thuật ngữ: Concepts: RAG · Vectorize · Workers AI · Knowledge seeding · Embeddings

Sơ đồ chính thức ↗ Official diagram ↗ · AI Artificial Intelligence (AI)

Figure 1:  Traditional single-region architecture

Serverless global APIs Serverless global APIs

An example architecture of a serverless API on Cloudflare and aims to illustrate how different compute and data products could interact with each other. An example architecture of a serverless API on Cloudflare and aims to illustrate how different compute and data products could interact with each other.

Thuật ngữ: Concepts: Workers · D1 · R2 · Global API · Edge compute

Sơ đồ chính thức ↗ Official diagram ↗ · Serverless Serverless

Sau lộ trình bạn sẽ What you will achieve

  • Deploy site static hoặc full-stack trên Pages Deploy a static or full-stack site on Pages
  • Tạo API route bằng Pages Functions hoặc Worker Create an API route with Pages Functions or a Worker
  • Chọn đúng storage: KV vs D1 vs R2 Pick the right storage: KV vs D1 vs R2
  • Xử lý lỗi và logging cơ bản trên edge Handle errors and basic edge logging
  • Hiểu khi nào dùng Workers AI (không bắt buộc ngay) Know when to use Workers AI (optional early on)

Khái niệm cần nắm Key concepts

  • Pages
  • Workers
  • KV
  • D1
  • R2
  • Durable Objects
  • Workers AI
  • AI Gateway
  • Vectorize

Lỗi thường gặp Common mistakes

Sai thư mục build output trên Pages Wrong Pages build output directory

Astro dùng `dist`, Create React App dùng `build` — sai output khiến site trắng hoặc 404. Kiểm tra build log trước khi merge. Astro uses `dist`, CRA uses `build` — wrong output causes blank sites or 404s. Check build logs before merging.

Chọn nhầm storage (KV cho dữ liệu quan hệ) Wrong storage choice (KV for relational data)

KV không phù hợp giao dịch cần consistency. Dùng D1 cho bảng SQL; R2 cho file; KV cho flags/config. KV is wrong for consistency-critical transactions. Use D1 for SQL tables; R2 for files; KV for flags/config.

Secret/API key lộ ở client Secrets/API keys exposed in the client

Chỉ `PUBLIC_*` được embed build. Token Turnstile secret, DB credentials phải ở Pages Functions/Worker env. Only `PUBLIC_*` belongs in the build. Turnstile secrets and DB credentials belong in Pages Functions/Worker env.

Không verify Turnstile server-side No server-side Turnstile verification

Chỉ embed widget chưa đủ — attacker gửi POST trực tiếp tới API. Luôn verify token trước khi ghi D1. Embedding the widget is not enough — attackers POST directly to your API. Always verify tokens before writing to D1.

Bỏ qua observability khi debug edge Skipping observability when debugging edge code

Worker/Pages Function lỗi khó thấy trên server truyền thống. Dùng `wrangler tail`, logs và error handling rõ ràng. Worker/Pages Function errors are invisible like traditional servers. Use `wrangler tail`, logs, and explicit error handling.

Nội dung từng phần Module-by-module content

~40 phút ~40 min 2 bài 2 lessons

Phần 1: Deploy đầu tiên với Pages Part 1: First deploy with Pages

Đưa frontend lên Cloudflare Pages và hiểu preview/production. Ship a frontend on Cloudflare Pages and understand preview vs production.

  1. 1

    Tạo project Pages từ Git hoặc CLI Create a Pages project from Git or CLI

    Kết nối repo GitHub/GitLab hoặc dùng `wrangler pages deploy`. Mỗi PR có preview URL — rất hữu ích cho review. Connect GitHub/GitLab or use `wrangler pages deploy`. Each PR gets a preview URL — great for reviews.

  2. 2

    Cấu hình build và output Configure build and output

    Đặt build command (`npm run build`) và thư mục output (`dist`). Kiểm tra biến môi trường cho API URL. Set build command (`npm run build`) and output directory (`dist`). Check env vars for API URLs.

~50 phút ~50 min 2 bài 2 lessons

Phần 2: API trên edge Part 2: APIs on the edge

Thêm logic serverless nhỏ không cần server riêng. Add small serverless logic without a separate server.

  1. 1

    Pages Functions cho route `/api/*` Pages Functions for `/api/*` routes

    Đặt handler trong `functions/` để xử lý form, webhook, proxy nhẹ. Phù hợp logic gắn với site Pages. Put handlers in `functions/` for forms, webhooks, light proxying. Good for logic tied to your Pages site.

  2. 2

    Worker độc lập khi cần routing phức tạp Standalone Worker for complex routing

    Dùng Worker khi cần middleware, auth edge, hoặc nhiều hostname. Worker là đơn vị compute linh hoạt nhất. Use a Worker when you need middleware, edge auth, or multiple hostnames. Workers are the most flexible compute unit.

~35 phút ~35 min 3 bài 3 lessons

Phần 3: Chọn storage đúng Part 3: Pick the right storage

KV, D1 và R2 — khi nào dùng cái nào. KV, D1, and R2 — when to use each.

  1. 1

    KV cho config và cache nhẹ KV for config and light cache

    Lưu feature flags, session token ngắn, rate limit counter. Không dùng KV cho giao dịch tài chính cần consistency cao. Store feature flags, short session tokens, rate limit counters. Avoid KV for financial transactions needing strong consistency.

  2. 2

    D1 cho dữ liệu có schema D1 for structured data

    Workshop signup, quiz results, user preferences — bảng SQL nhỏ. Chạy migration với `wrangler d1 migrations`. Workshop signups, quiz results, user prefs — small SQL tables. Run migrations with `wrangler d1 migrations`.

  3. 3

    R2 cho file và tài liệu R2 for files and assets

    PDF, slides, upload user — object storage. Có thể phục vụ public hoặc signed URL sau này. PDFs, slides, user uploads — object storage. Serve public or via signed URLs later.

~30 phút ~30 min 2 bài 2 lessons

Phần 4: Vận hành và bước tiếp Part 4: Operate and level up

Analytics, bảo vệ form, và hướng AI. Analytics, form protection, and AI next steps.

  1. 1

    Web Analytics và log Workers Web Analytics and Worker logs

    Bật Cloudflare Web Analytics cho traffic. Dùng `wrangler tail` hoặc observability khi debug API. Enable Cloudflare Web Analytics for traffic. Use `wrangler tail` or observability when debugging APIs.

  2. 2

    Turnstile cho form public Turnstile for public forms

    Chống bot trên đăng ký workshop, contact form. Verify token server-side trước khi ghi D1. Stop bots on workshop signup and contact forms. Verify tokens server-side before writing to D1.

Trình tự học gợi ý Suggested learning order

  1. Deploy static site với Pages Deploy a static site with Pages
  2. Thêm một API route Add one API route
  3. Build một Worker endpoint nhỏ Build a small Worker endpoint
  4. Lưu dữ liệu đơn giản trong KV hoặc D1 Store simple data in KV or D1
  5. Upload files lên R2 Upload files to R2
  6. Thêm basic analytics và error handling Add basic analytics and error handling
  7. Thử một AI API use case Try an AI API use case

Tài nguyên chính thức (Resource Hub) Official resources (Resource Hub)

Liên kết từ Cloudflare Resource Hub — docs, community, case studies phù hợp track này. Links from the Cloudflare Resource Hub — docs, community, and case studies for this track.

Build & triển khai Build & deploy Gợi ý Recommended

AI Gateway AI Gateway

Quản trị request AI đa provider — observability, cache và kiểm soát chi phí. Govern multi-provider AI requests — observability, caching, and cost control.

Mở trên Cloudflare Open on Cloudflare
Học & tài liệu Learn & docs Gợi ý Recommended

Developer Documentation Developer Documentation

Tài liệu sản phẩm, tutorial và ví dụ cho mọi dịch vụ Cloudflare. Product docs, tutorials, and examples for every Cloudflare service.

Mở trên Cloudflare Open on Cloudflare
Build & triển khai Build & deploy

API Reference API Reference

Endpoint, schema và chi tiết xác thực cho Cloudflare APIs. Endpoints, schemas, and auth details for Cloudflare APIs.

Mở trên Cloudflare Open on Cloudflare
Học & tài liệu Learn & docs Trong hub In this hub Gợi ý Recommended

Reference Architectures Reference Architectures

Pattern kiến trúc và best practices — SASE, CDN, Workers, Zero Trust. Architecture patterns and best practices — SASE, CDN, Workers, Zero Trust.

Xem trong hub View in hub
Xem toàn bộ Resource Hub trong hub View full Resource Hub in this hub

Reference Architecture Reference Architecture

Sơ đồ và tài liệu thiết kế chính thức từ Cloudflare Architecture Center — bổ sung lộ trình học trong hub. Official design diagrams and docs from the Cloudflare Architecture Center — complementing this track in the hub.

Figure 1: Cloudflare Developer Platform
Sơ đồ kiến trúc Architecture diagram Nổi bật Featured Track: Track: Developer Platform

Fullstack applications on Workers Fullstack applications on Workers

Ví dụ kiến trúc fullstack thực tế — Workers, storage, compute phối hợp. A practical fullstack architecture — Workers, storage, and compute together.

Xem tất cả tài liệu kiến trúc View all architecture docs

Ví dụ từ GitHub Cloudflare Examples from Cloudflare GitHub

Repo open source chính thức trên github.com/cloudflare — học bằng README và code mẫu. Official open source at github.com/cloudflare — learn from READMEs and sample code.

Ví dụ 1: Worker đầu tiên với Wrangler Example 1: First Worker with Wrangler

Bắt đầu từ workers-sdk và cloudflare-docs — tạo project, dev local, deploy. Start with workers-sdk and cloudflare-docs — create a project, dev locally, deploy.

Ví dụ 3: AI Agents trên edge Example 3: AI Agents on the edge

Fork agents hoặc vibesdk — thêm tool, binding D1/R2, deploy production nhỏ. Fork agents or vibesdk — add a tool, D1/R2 bindings, deploy a small production app.

Pinned Pinned Workers & Platform Workers & Platform TypeScript ★ 4,100

cloudflare/workers-sdk

Home của Wrangler — CLI deploy và dev Workers, Pages, D1, R2. Home of Wrangler — CLI to develop and deploy Workers, Pages, D1, R2.

Gợi ý học / thử: Try this:

Clone repo → đọc README Wrangler → chạy `npm create cloudflare@latest` theo hướng dẫn trong docs. Clone the repo → read the Wrangler README → run `npm create cloudflare@latest` as documented.

Mở trên GitHub Open on GitHub
Pinned Pinned Hạ tầng & Core Infrastructure & Core C++ ★ 8,300

cloudflare/workerd

JavaScript/Wasm runtime chạy Cloudflare Workers — V8 isolates tại edge. The JavaScript/Wasm runtime behind Cloudflare Workers — V8 isolates at the edge.

Gợi ý học / thử: Try this:

Đọc kiến trúc runtime để hiểu cold start, limit CPU/subrequest khác với Node server. Read runtime architecture to understand cold starts and CPU/subrequest limits vs Node.

Mở trên GitHub Open on GitHub
Pinned Pinned Workers & Platform Workers & Platform Rust ★ 3,500

cloudflare/workers-rs

Viết Workers 100% Rust qua WebAssembly. Write Cloudflare Workers in 100% Rust via WebAssembly.

Gợi ý học / thử: Try this:

Làm ví dụ “Hello Worker” bằng Rust nếu team bạn ưu tiên Rust thay vì JS/TS. Build a “Hello Worker” in Rust if your team prefers Rust over JS/TS.

Mở trên GitHub Open on GitHub
AI & Agents AI & Agents TypeScript ★ 5,000

cloudflare/agents

Build và deploy AI Agents trên Cloudflare (Durable Objects, WebSocket, tools). Build and deploy AI Agents on Cloudflare (Durable Objects, WebSocket, tools).

Gợi ý học / thử: Try this:

Fork template agents → thêm 1 tool gọi D1 → deploy lên Workers — bài lab AI cơ bản. Fork the agents template → add one D1 tool → deploy to Workers — basic AI lab.

Mở trên GitHub Open on GitHub
Xem tất cả repo gợi ý View all suggested repos

Đọc thêm — kinh nghiệm thực tế (CloudSecOp) Further reading — field notes (CloudSecOp)

Bài viết từ cloudsecop.net — bổ sung lộ trình hub với context triển khai production, không thay tài liệu chính thức Cloudflare. Posts from cloudsecop.net — complement this track with production deployment context; not a replacement for official Cloudflare docs.

Chuỗi bài học Article series

Cloudflare Developer Platform Handbook Cloudflare Developer Platform Handbook

20 bài từ Workers runtime tới migration AWS — viết từ kinh nghiệm vận hành blog production trên stack Cloudflare. 20 posts from Workers runtime to AWS migration — written from running a production blog on Cloudflare.

20 bài · kinh nghiệm triển khai thực tế 20 posts · real deployment experience

Xem toàn bộ chuỗi View full series
Phần 1 Part 1 9 phút đọc 9 min read

Cloudflare developer platform là gì, và vì sao khác Lambda What the Cloudflare developer platform is — and why it differs from Lambda

Mental model đầu tiên: Workers, D1, R2, KV, Queues, DOs, Workers AI, Vectorize — nền tảng edge-native so với Lambda. First mental model: Workers, D1, R2, KV, Queues, DOs, Workers AI, Vectorize — edge-native vs Lambda.

  • Workers
  • mental model
Đọc trên CloudSecOp Read on CloudSecOp
Phần 2 Part 2 7 phút đọc 7 min read

Workers runtime mental model: lifecycle, context, limit Workers runtime mental model: lifecycle, context, limits

fetch handler, waitUntil, subrequest, CPU vs wall time, cold start — 6 ngộ nhận khi chuyển từ Node/Lambda. fetch handler, waitUntil, subrequests, CPU vs wall time, cold starts — six Node/Lambda misconceptions.

  • Workers
Đọc trên CloudSecOp Read on CloudSecOp
Phần 3 Part 3 8 phút đọc 8 min read

Mental model 3 tầng binding: Request, Identity, Storage The 3-binding mental model: Request, Identity, Storage

Khung chọn storage đúng cho mọi Worker — áp dụng trực tiếp lên app production. A frame for picking the right storage on every Worker — applied to a live app.

  • Workers
  • KV
  • D1
Đọc trên CloudSecOp Read on CloudSecOp
Phần 4 Part 4 6 phút đọc 6 min read

Wrangler và Miniflare dev loop: từ init tới deploy trong 30 phút Wrangler + Miniflare dev loop: init to deploy in 30 minutes

wrangler init, dev local, vitest, D1 migration, secret, deploy 300+ PoP — vòng đời từ folder trống. wrangler init, local dev, vitest, D1 migrations, secrets, deploy to 300+ PoPs.

  • Wrangler
  • Miniflare
Đọc trên CloudSecOp Read on CloudSecOp
Phần 5 Part 5 6 phút đọc 6 min read

KV deep-dive: cache toàn cầu, eventual consistency, vs D1 KV deep-dive: global cache, consistency, vs D1

5 pattern đúng, 3 anti-pattern, gotcha consistency khi dùng KV ở production. Five good patterns, three anti-patterns, and real consistency gotchas.

  • KV
Đọc trên CloudSecOp Read on CloudSecOp
Phần 6 Part 6 6 phút đọc 6 min read

D1 trong production: primary-replica, batch, và 7 gotcha D1 in production: primary-replica, batch, 7 gotchas

Sessions API, 5 query method, migration an toàn — bài học từ vận hành D1 thật. Sessions API, five query methods, safe migrations — lessons from real D1 ops.

  • D1
Đọc trên CloudSecOp Read on CloudSecOp
Xem tất cả bài gợi ý trong Tài nguyên View all suggested posts in Resources

Bước tiếp theo Next step

Áp dụng ngay qua tình huống thực tế và checklist. Apply what you learned via a use case and checklist.