Giới thiệu về BackendIntroduction to Backend Development
Thuộc bộ kiến thức Backend Roadmap.
Tổng quan
Backend development là việc xây dựng phần server-side của phần mềm: code, kho dữ liệu và hạ tầng chạy trên server thay vì chạy trong browser hay mobile app của người dùng. Khi bạn bấm “Mua ngay”, refresh feed, hay đăng nhập, sẽ có một backend nào đó xác thực bạn là ai, kiểm tra tồn kho hay quyền hạn, đọc/ghi database, gọi tới các service khác, rồi trả về một response. Frontend hiển thị kết quả; backend mới là nơi quyết định kết quả đó là gì.
Note này là điểm khởi đầu của toàn bộ Backend Roadmap. Nó giải thích backend làm những gì, một request đi qua một hệ thống điển hình như thế nào, và các phần còn lại của roadmap ghép nối ra sao — để bạn hiểu tại sao sau này phải học HTTP, database, API, caching và deployment.
Vì sao cần backend
Bất cứ thứ gì bạn không thể tin tưởng để client tự làm đúng, an toàn và nhất quán đều thuộc về backend:
- Tin cậy và bảo mật (security) — browser có thể bị người dùng chỉnh sửa, nên việc tính giá, kiểm soát quyền truy cập và validation phải được thực thi ở server-side.
- Shared state — nhiều client cần chung một nguồn sự thật nhất quán (số dư tài khoản, số ghế còn lại của chuyến bay).
- Độ bền dữ liệu (durability) — dữ liệu phải tồn tại sau khi người dùng đóng tab, tức là cần persistent storage mà client không cung cấp được.
- Công việc nặng hoặc nhạy cảm — gửi email, thu tiền thẻ, chạy report, hay gọi API của đối tác cần secrets và tài nguyên tính toán mà client không bao giờ nên nắm giữ.
Kiến thức nền tảng
Frontend vs backend vs full-stack
| Khía cạnh | Frontend | Backend |
|---|---|---|
| Chạy ở đâu | Thiết bị người dùng (browser, mobile app) | Server do bạn kiểm soát |
| Nhiệm vụ chính | Hiển thị, tương tác, UX | Logic, dữ liệu, security, tích hợp |
| Ngôn ngữ phổ biến | JavaScript, TypeScript, Swift, Kotlin | Go, Python, Java, C#, Node.js, Rust, PHP, Ruby |
| Nhìn thấy | Những gì người dùng thấy | Những gì người dùng không được thấy (secrets, dữ liệu thô) |
| Lỗi trông như thế nào | Vỡ layout, nút không phản hồi | Sai dữ liệu, lỗi 500, mất dữ liệu, rò rỉ |
Một developer full-stack làm việc ở cả hai phía. Thực tế phần lớn kỹ sư nghiêng về một bên; “full-stack” thường nghĩa là đủ thoải mái ở phía còn lại để làm việc hiệu quả, chứ không phải giỏi ngang nhau ở mọi thứ.
Mô hình client-server
Gần như mọi công việc backend đều theo mô hình client-server: client gửi một request, server xử lý và trả về một response. Client và server là hai chương trình riêng biệt, thường nằm trên các máy khác nhau, giao tiếp qua mạng — phổ biến nhất là qua HTTP trên nền TCP/IP.
Các đặc điểm chính:
- Request/response — client khởi đầu; server trả lời. (Các mô hình dạng push như WebSockets và Server-Sent Events đảo ngược điều này cho các tình huống real-time.)
- HTTP stateless — mặc định mỗi HTTP request là độc lập; server không nhớ các request trước đó trừ khi bạn thêm session, token, hoặc database.
- Nhiều client, một backend — web, mobile, CLI và các tích hợp bên thứ ba đều có thể gọi cùng một backend, đó là lý do API sạch sẽ rất quan trọng.
Bạn sẽ tìm hiểu sâu hơn về networking và HTTP trong Internet & Web Fundamentals.
Cái gì chạy ở đâu
Frontend (client) Backend (server)
───────────────── ─────────────────
Render UI Business logic / quy tắc
Nhập & validate form (UX) Validation có thẩm quyền
Routing phía client API endpoints / routing
Gọi API Lưu trữ dữ liệu (DB)
Optimistic updates Auth & authorization
Tích hợp (email, payments…)
Background jobs & scheduling
Khái niệm chính
Backend thực sự làm những gì
Một backend production chịu trách nhiệm cho một số nhóm việc lặp đi lặp lại:
- Business logic — các quy tắc làm nên sản phẩm của riêng bạn: cách tính tổng đơn hàng, ai được duyệt hoàn tiền, khi nào một subscription gia hạn. Đây là phần code có giá trị cao nhất và cũng tốn kém nhất nếu làm sai.
- Data persistence — lưu và truy xuất dữ liệu một cách tin cậy, thường trong database. Xem Relational Databases.
- Authentication & authorization — authentication trả lời “bạn là ai?” (login, token, session); authorization trả lời “bạn được phép làm gì?” (role, permission).
- API — hợp đồng (contract) mà các chương trình khác dùng để giao tiếp với backend của bạn, thường là REST hoặc GraphQL trên HTTP. Xem APIs.
- Tích hợp (integration) — giao tiếp với hệ thống bên ngoài: payment provider, email/SMS, object storage, các microservice khác, API bên thứ ba.
- Cross-cutting concerns — logging, metrics, xử lý lỗi, rate limiting, caching, validation input, và công việc chạy nền/bất đồng bộ (asynchronous).
Giải phẫu một request backend điển hình
Hãy theo một HTTP request — ví dụ GET /api/users/42/orders — đi qua một web application thông thường:
- 01ClientBrowser/app gửi một HTTP request: GET /api/users/42/orders (kèm auth token)
- 02DNS + networkDomain phân giải thành IP; request đi qua TCP/TLS.
- 03Web server / reverse proxyNginx / load balancer / API gateway kết thúc TLS, định tuyến request tới một application instance.
- 04ApplicationFramework khớp route → controller/handler. Middleware chạy: kiểm tra auth, rate limit, logging, validate request.
- 05Business logicHandler xác minh user 42 == người gọi (authorization), áp dụng quy tắc, quyết định cần dữ liệu gì.
- 06Data layerORM/query gọi database (và/hoặc cache như Redis). SQL: SELECT * FROM orders WHERE user_id=42;
- 07Dựng responseCác dòng dữ liệu map thành object → serialize sang JSON. Đặt status code + headers (ví dụ 200 OK).
- 08Trả ngược raResponse đi ngược qua proxy về client, và client render.
Một phiên bản tối giản của bước 4–7 bằng Express (Node.js):
// GET /api/users/:id/orders
app.get("/api/users/:id/orders", authenticate, async (req, res) => {
const userId = Number(req.params.id);
// Authorization: user chỉ được đọc order của chính mình
if (req.user.id !== userId) {
return res.status(403).json({ error: "Forbidden" });
}
// Data layer
const orders = await db.query(
"SELECT id, total, status, created_at FROM orders WHERE user_id = $1",
[userId]
);
// Response
return res.status(200).json({ orders });
});
Để ý xem có bao nhiêu chủ đề của roadmap xuất hiện chỉ trong một request: HTTP, routing, middleware, auth, database, caching, serialization và status code. Đó chính là lý do roadmap phải cover tất cả.
Bức tranh công nghệ backend
Hệ sinh thái backend ánh xạ trực tiếp sang các phần sau của roadmap:
| Tầng | Ví dụ | Vị trí trong roadmap |
|---|---|---|
| Ngôn ngữ | Go, Python, Java, C#, Node.js/TypeScript, Rust, PHP, Ruby | Programming Languages |
| Framework | Express/NestJS, Spring, Django/FastAPI, ASP.NET, Gin, Rails | gắn với lựa chọn ngôn ngữ |
| API | REST, GraphQL, gRPC | APIs |
| Database | PostgreSQL, MySQL (relational); MongoDB, Redis (NoSQL) | Relational Databases |
| Web/app server | Nginx, Caddy, application runtime | Internet & Web Fundamentals |
| Caching & messaging | Redis, Memcached, Kafka, RabbitMQ | các chủ đề sau của roadmap |
| Hạ tầng (infra) | Docker, Kubernetes, CI/CD, cloud (AWS/GCP) | giao với phần DevOps & Cloud |
Bạn không cần tất cả những thứ này ngay ngày đầu. Hãy chọn một ngôn ngữ, một framework và một relational database, rồi xây một thứ gì đó hoàn chỉnh từ đầu đến cuối trước.
Vai trò & kỹ năng của một backend engineer
Ngoài việc viết code, backend engineer được kỳ vọng biết suy luận về:
- Tính đúng đắn (correctness) — edge case, validation, tính nhất quán và các kịch bản lỗi.
- Data modeling — thiết kế schema và quan hệ phù hợp với domain.
- API design — contract rõ ràng, ổn định, có version mà các team khác phụ thuộc vào.
- Security — OWASP Top 10, authentication, secrets, xử lý input.
- Hiệu năng & khả năng mở rộng (scalability) — indexing, caching, N+1 query, concurrency.
- Khả năng vận hành (operability) — logging, monitoring, deployment và debug trên production.
Kỹ năng mềm cũng quan trọng: đọc yêu cầu một cách phản biện, trao đổi về các trade-off, và viết code người khác bảo trì được.
Cách tiếp cận việc học
Một thứ tự thực tế bám theo roadmap này:
- Học tốt một ngôn ngữ và hiểu internet/HTTP hoạt động ra sao (02, 03).
- Xây một CRUD API nhỏ dựa trên một relational database (06, 08).
- Thêm authentication, validation và xử lý lỗi.
- Học caching, background jobs và testing.
- Học deployment — Docker, CI/CD và một cloud provider.
- Đi sâu vào scalability, security và system design.
Hãy làm project ở mỗi bước. Chỉ đọc không thôi sẽ không giúp các khái niệm thấm vào bạn.
Coding truyền thống vs coding có AI hỗ trợ
Công việc backend ngày càng diễn ra cùng các AI assistant (code completion, chat, và agent). Sự dịch chuyển này là có thật, nhưng phần nền tảng lại càng quan trọng hơn, chứ không kém đi:
| Coding truyền thống | Coding có AI hỗ trợ | |
|---|---|---|
| Tốc độ bản nháp đầu | Chậm hơn | Nhanh hơn nhiều |
| Boilerplate & code kết dính | Viết tay | Phần lớn được sinh tự động |
| Rủi ro | Lỗi con người | Output tự tin nhưng sai, bug tinh vi, default không an toàn |
| Cái bạn vẫn phải chịu trách nhiệm | Thiết kế, review, tính đúng đắn | Thiết kế, review, tính đúng đắn |
AI có thể dựng khung một endpoint, phác một query, hay giải thích một stack trace — nhưng nó không thể chịu trách nhiệm cho hệ thống của bạn. Bạn vẫn phải hiểu vòng đời của request, nhận ra một query không an toàn, và đánh giá được một gợi ý có đúng hay không. Hãy dùng AI để đi nhanh hơn với những thứ bạn đã hiểu, và học nhanh hơn với những thứ bạn chưa hiểu; đừng bao giờ ship code mà bạn không giải thích được. Xem thêm trong AI for Backend.
Best Practices
- Không bao giờ tin client. Validate và authorize lại mọi thứ ở server, kể cả khi frontend đã kiểm tra rồi.
- Giữ secrets ngoài client và ngoài source control. Dùng environment variable hoặc secrets manager.
- Thiết kế API contract trước. Endpoint ổn định, có tài liệu tốt sẽ tiết kiệm công cho mọi consumer phía sau.
- Tách bạch các concern. Giữ routing, business logic và data access ở các tầng riêng để mỗi phần dễ test.
- Dùng đúng status code và error có cấu trúc.
200/201/400/401/403/404/409/500đều mang ý nghĩa; đừng trả200kèm body báo lỗi. - Làm cho hệ thống observable. Log kèm ngữ cảnh, expose metrics, và xử lý lỗi tường minh thay vì nuốt lỗi.
- Ưu tiên công cụ “nhàm chán” nhưng đã được kiểm chứng cho những hệ thống đầu tiên — PostgreSQL thay vì database mới nhất, một framework trưởng thành thay vì cái đang hot nhất.
- Ship nhỏ, hoàn chỉnh đầu-cuối. Một hệ thống nhỏ chạy được hơn hẳn một hệ thống lớn làm dở dang; hãy học bằng cách lặp (iterate).
Tài liệu tham khảo
Part of the Backend Roadmap knowledge base.
Overview
Backend development is the practice of building the server-side of software: the code, data stores, and infrastructure that run on servers rather than in the user’s browser or mobile app. When you tap “Buy now”, refresh a feed, or log in, a backend somewhere validates who you are, checks inventory or permissions, reads and writes to a database, talks to other services, and sends back a response. The frontend renders the result; the backend decides what the result is.
This note is the entry point to the whole Backend Roadmap. It explains what a backend does, how a single request flows through a typical system, and how the rest of the roadmap fits together — so you know why you’re later learning HTTP, databases, APIs, caching, and deployment.
Why the backend exists
Anything you cannot trust the client to do correctly, safely, or consistently belongs on the backend:
- Trust and security — a browser can be modified by the user, so price calculation, access control, and validation must be enforced server-side.
- Shared state — many clients need one consistent source of truth (your bank balance, the number of seats left on a flight).
- Durability — data must survive after the user closes the tab, which means persistent storage the client cannot provide.
- Heavy or privileged work — sending email, charging a card, running a report, or calling a partner API needs secrets and compute the client should never hold.
Fundamentals
Frontend vs backend vs full-stack
| Aspect | Frontend | Backend |
|---|---|---|
| Runs on | User’s device (browser, mobile app) | Servers you control |
| Primary job | Presentation, interaction, UX | Logic, data, security, integration |
| Typical languages | JavaScript, TypeScript, Swift, Kotlin | Go, Python, Java, C#, Node.js, Rust, PHP, Ruby |
| Sees | What the user sees | What the user must not see (secrets, raw data) |
| Failure looks like | Broken layout, unresponsive button | Wrong data, 500 error, data loss, breach |
A full-stack developer works across both. In practice most engineers lean one way; “full-stack” usually means comfortable enough on the other side to be productive, not equally expert at everything.
The client-server model
Almost all backend work follows the client-server model: a client sends a request, a server processes it and returns a response. The client and server are separate programs, usually on different machines, communicating over a network — most often via HTTP over TCP/IP.
Key properties:
- Request/response — the client initiates; the server answers. (Push-style patterns like WebSockets and Server-Sent Events invert this for real-time cases.)
- Stateless HTTP — each HTTP request is independent by default; the server does not remember previous requests unless you add sessions, tokens, or a database.
- Many clients, one backend — web, mobile, CLI, and third-party integrations can all hit the same backend, which is why clean APIs matter.
You’ll go deeper on networking and HTTP in Internet & Web Fundamentals.
What runs where
Frontend (client) Backend (server)
───────────────── ─────────────────
UI rendering Business logic / rules
Form input & validation (UX) Authoritative validation
Client-side routing API endpoints / routing
Calling APIs Data persistence (DB)
Optimistic updates Auth & authorization
Integrations (email, payments…)
Background jobs & scheduling
Key Concepts
What a backend actually does
A production backend is responsible for a handful of recurring concerns:
- Business logic — the rules that make your product your product: how an order total is computed, who may approve a refund, when a subscription renews. This is the code with the most value and the highest cost of getting wrong.
- Data persistence — storing and retrieving data reliably, usually in a database. See Relational Databases.
- Authentication & authorization — authentication answers “who are you?” (login, tokens, sessions); authorization answers “what are you allowed to do?” (roles, permissions).
- APIs — the contract other programs use to talk to your backend, typically REST or GraphQL over HTTP. See APIs.
- Integration — talking to external systems: payment providers, email/SMS, object storage, other microservices, third-party APIs.
- Cross-cutting concerns — logging, metrics, error handling, rate limiting, caching, input validation, and background/asynchronous work.
Anatomy of a typical backend request
Follow one HTTP request — say GET /api/users/42/orders — through a conventional web application:
- 01ClientBrowser/app sends an HTTP request: GET /api/users/42/orders (with an auth token)
- 02DNS + networkDomain resolves to an IP; request travels over TCP/TLS.
- 03Web server / reverse proxyNginx / load balancer / API gateway terminates TLS, routes the request to an application instance.
- 04ApplicationFramework matches the route → controller/handler. Middleware runs: auth check, rate limit, logging, request validation.
- 05Business logicHandler verifies user 42 == caller (authorization), applies rules, decides what data is needed.
- 06Data layerORM/queries hit the database (and/or a cache like Redis). SQL: SELECT * FROM orders WHERE user_id=42;
- 07Response builtRows mapped to objects → serialized to JSON. Status code + headers set (e.g. 200 OK).
- 08Back outResponse passes back through proxy to the client, which renders it.
A minimal version of steps 4–7 in Express (Node.js):
// GET /api/users/:id/orders
app.get("/api/users/:id/orders", authenticate, async (req, res) => {
const userId = Number(req.params.id);
// Authorization: users may only read their own orders
if (req.user.id !== userId) {
return res.status(403).json({ error: "Forbidden" });
}
// Data layer
const orders = await db.query(
"SELECT id, total, status, created_at FROM orders WHERE user_id = $1",
[userId]
);
// Response
return res.status(200).json({ orders });
});
Notice how many roadmap topics appear in one request: HTTP, routing, middleware, auth, databases, caching, serialization, and status codes. That is why the roadmap covers them all.
The backend tech landscape
The backend ecosystem maps directly onto later roadmap sections:
| Layer | Examples | Where in the roadmap |
|---|---|---|
| Languages | Go, Python, Java, C#, Node.js/TypeScript, Rust, PHP, Ruby | Programming Languages |
| Frameworks | Express/NestJS, Spring, Django/FastAPI, ASP.NET, Gin, Rails | tied to your language choice |
| APIs | REST, GraphQL, gRPC | APIs |
| Databases | PostgreSQL, MySQL (relational); MongoDB, Redis (NoSQL) | Relational Databases |
| Web/app servers | Nginx, Caddy, application runtimes | Internet & Web Fundamentals |
| Caching & messaging | Redis, Memcached, Kafka, RabbitMQ | later roadmap topics |
| Infrastructure | Docker, Kubernetes, CI/CD, cloud (AWS/GCP) | overlaps the DevOps & Cloud sections |
You do not need all of these on day one. Pick one language, one framework, and one relational database, and build something end to end first.
Roles & skills of a backend engineer
Beyond writing code, backend engineers are expected to reason about:
- Correctness — edge cases, validation, consistency, and failure modes.
- Data modeling — designing schemas and relationships that fit the domain.
- API design — clear, stable, versioned contracts other teams depend on.
- Security — the OWASP Top 10, authentication, secrets, input handling.
- Performance & scalability — indexing, caching, N+1 queries, concurrency.
- Operability — logging, monitoring, deployment, and debugging in production.
Soft skills matter too: reading requirements critically, communicating trade-offs, and writing code others can maintain.
How to approach learning
A practical order that mirrors this roadmap:
- Learn one language well and how the internet/HTTP works (02, 03).
- Build a small CRUD API backed by a relational database (06, 08).
- Add authentication, validation, and error handling.
- Learn caching, background jobs, and testing.
- Learn deployment — Docker, CI/CD, and a cloud provider.
- Go deep on scalability, security, and system design.
Build projects at every step. Reading alone will not make the concepts stick.
Traditional coding vs AI-assisted coding
Backend work increasingly happens with AI assistants (code completion, chat, and agents). The shift is real but the fundamentals matter more, not less:
| Traditional coding | AI-assisted coding | |
|---|---|---|
| Speed of a first draft | Slower | Much faster |
| Boilerplate & glue code | Manual | Largely generated |
| Risk | Human error | Confident but wrong output, subtle bugs, insecure defaults |
| What you still must own | Design, review, correctness | Design, review, correctness |
AI can scaffold an endpoint, draft a query, or explain a stack trace — but it cannot be accountable for your system. You still must understand the request lifecycle, spot an insecure query, and judge whether a suggestion is correct. Use AI to go faster on things you already understand and to learn faster on things you don’t; never ship code you can’t explain. More in AI for Backend.
Best Practices
- Never trust the client. Re-validate and re-authorize everything on the server, even if the frontend already checked.
- Keep secrets out of the client and out of source control. Use environment variables or a secrets manager.
- Design the API contract first. Stable, well-documented endpoints save every consumer downstream.
- Separate concerns. Keep routing, business logic, and data access in distinct layers so each is testable.
- Use the right status codes and structured errors.
200/201/400/401/403/404/409/500carry meaning; don’t return200with an error body. - Make it observable. Log with context, expose metrics, and handle errors explicitly rather than swallowing them.
- Prefer boring, proven tools for your first systems — PostgreSQL over the newest database, a mature framework over the trendiest one.
- Ship small, end-to-end. A tiny working system beats a large half-built one; learn by iterating.