Purpose of This Chapter — Mục đích chương này
EN
This bonus chapter consolidates the core principles used across all 30 chapters. While each chapter focuses on a specific system, the underlying architectural thinking remains the same. Senior engineers and system architects must internalize these principles to reason about scalability, reliability, performance, and trade-offs in any system.
VI
Chương Bonus này tổng hợp lại các nguyên tắc cốt lõi xuất hiện xuyên suốt 30 chương. Dù mỗi chương mô tả một hệ thống riêng, nhưng tư duy kiến trúc phía sau chúng đều giống nhau. Kỹ sư senior và kiến trúc sư hệ thống cần nắm vững những nguyên tắc này để phân tích scalability, reliability, performance và các trade-off trong mọi hệ thống.
1. Scalability Principles – Nguyên tắc mở rộng hệ thống
1.1 Vertical vs Horizontal Scaling
EN:
- Vertical scaling = bigger machine.
- Horizontal scaling = more machines.
- Always design for horizontal scaling in distributed systems.
VI:
- Scale dọc = nâng cấu hình máy.
- Scale ngang = thêm nhiều máy.
- Trong hệ thống phân tán, luôn ưu tiên scale ngang.
1.2 Stateless vs Stateful Services
EN:
Stateless services can scale infinitely. Stateful services require sharding, sticky sessions, or special storage nodes.
VI:
Service stateless scale dễ dàng. Service stateful cần sharding, sticky session hoặc storage chuyên dụng.
1.3 Partitioning & Sharding
EN:
Breaking data/workload into partitions avoids hot spots and lifts throughput limits.
VI:
Phân mảnh dữ liệu/tải giúp tránh hot spot và tăng throughput tối đa.
2. Availability & Fault Tolerance – Sẵn sàng & chịu lỗi
2.1 Redundancy Everywhere
EN:
No single point of failure. Everything must have replicas: servers, databases, caches, queues.
VI:
Không được có single point of failure. Tất cả phải có replica: server, DB, cache, queue.
2.2 Active-Active vs Active-Passive
EN:
Active-active gives strong availability but requires conflict resolution.
Active-passive is simpler but slower failover.
VI:
Active-active uptime cao nhưng phức tạp.
Active-passive đơn giản nhưng failover chậm hơn.
2.3 Multi-Region Architecture
EN:
Critical for global-scale systems: traffic routing, data replication, failover automation.
VI:
Quan trọng với hệ thống toàn cầu: routing theo vùng, replicate dữ liệu, failover tự động.
3. Consistency Principles – Nguyên tắc nhất quán dữ liệu
3.1 Strong vs Eventual Consistency
EN:
- Strong: always up-to-date
- Eventual: updates propagate asynchronously
Trade-off between latency and correctness.
VI:
- Strong: luôn đúng thời điểm
- Eventual: cập nhật dần dần
Trade-off giữa latency và độ chính xác.
3.2 Read-After-Write Guarantee
EN:
Important for user-facing systems that require immediate reflection of writes.
VI:
Quan trọng với hệ thống cần thấy ngay thay đổi sau khi ghi.
3.3 Conflict Resolution
EN:
Techniques: last-write-wins, vector clocks, CRDT, merge logic.
VI:
Kỹ thuật: last-write-wins, vector clock, CRDT, merge logic.
4. Performance Optimization – Tối ưu hiệu năng
4.1 Caching Everywhere
EN:
Cache reduces load on databases → drastically improves latency.
VI:
Cache giảm tải DB → cải thiện latency mạnh.
4.2 CDN for Global Delivery
EN:
Use edge nodes to bring content closer to users.
VI:
CDN đưa nội dung đến gần người dùng hơn → giảm độ trễ toàn cầu.
4.3 Asynchronous Processing
EN:
Move heavy tasks to background queues to keep APIs responsive.
VI:
Đẩy tác vụ nặng sang queue nền để API phản hồi nhanh hơn.
4.4 Connection Pooling & Keep-Alive
EN:
Reuse connections to minimize handshake overhead.
VI:
Tái sử dụng connection để giảm chi phí handshake.
5. Reliability & Durability – Độ tin cậy & độ bền dữ liệu
5.1 Replication
EN:
Data must survive machine failures.
VI:
Dữ liệu phải tồn tại dù máy lỗi.
5.2 Write-Ahead Log (WAL)
EN:
Before mutating data, write intent to durable log.
VI:
Trước khi thay đổi dữ liệu, ghi vào log bền vững.
5.3 Acknowledgment Strategies
EN:
1 acknowledgment: fast
Quorum acknowledgment: safe
VI:
ACK ít: nhanh
ACK theo quorum: an toàn
6. Observability – Khả năng quan sát
6.1 Metrics • Logs • Traces
EN:
The three pillars of observability.
VI:
Ba trụ cột quan sát hệ thống.
6.2 Distributed Tracing
EN:
Trace requests across microservices via traceID/spanID.
VI:
Theo dõi request qua microservice bằng traceID/spanID.
6.3 SLO / SLA / Error Budget
EN:
Define what “good enough reliability” means.
VI:
Xác định mức reliability đủ tốt cho sản phẩm.
7. Load Management & Resilience – Quản lý tải & phục hồi
7.1 Rate Limiting
EN:
Protect systems from abuse or traffic spikes.
VI:
Chống overload & abuse.
7.2 Circuit Breaker
EN:
Fail fast when downstream services are degraded.
VI:
Tự động ngắt kết nối khi service downstream lỗi.
7.3 Backpressure & Queueing
EN:
Slow consumers throttle fast producers.
VI:
Consumer chậm điều tiết producer nhanh.
7.4 Idempotency
EN:
Critical for payments, messaging, distributed tasks.
VI:
Rất quan trọng với payment, messaging, distributed queue.
8. Security Principles – Nguyên tắc bảo mật
8.1 Zero-Trust Architecture
EN:
Every request must be authenticated & authorized.
VI:
Mỗi request đều phải xác thực và phân quyền.
8.2 Encryption (TLS / At-Rest)
EN:
Protect data in motion and at storage.
VI:
Mã hoá dữ liệu khi truyền và khi lưu.
8.3 API Gateway Policies
EN:
Centralized auth, throttling, monitoring.
VI:
API Gateway xử lý auth, throttle, giám sát.
9. Data Modeling Principles – Nguyên tắc mô hình dữ liệu
9.1 Normalized vs Denormalized
EN:
Trade-offs between consistency and read performance.
VI:
Trade-off giữa nhất quán và tốc độ đọc.
9.2 NoSQL Schema Design
EN:
Design for access pattern, not ER diagrams.
VI:
Thiết kế theo access pattern, không phải ER.
9.3 Indexing Strategy
EN:
Indexes accelerate queries but slow writes.
VI:
Index tăng tốc query nhưng làm chậm ghi.
10. Cost Efficiency – Tối ưu chi phí
10.1 Autoscaling
EN:
Scale resources automatically based on load.
VI:
Tự scale theo tải.
10.2 Storage Tiering
EN:
Choose SSD/HDD/Archive based on access patterns.
VI:
Chọn tier lưu trữ tùy mức độ truy cập.
10.3 Optimize for 95%, Not 100%
EN:
Over-engineering is expensive. Build for 95% realistic usage.
VI:
Tránh over-engineering. Tập trung 95% nhu cầu thực tế.
11. Resilience Design Patterns – Pattern chịu lỗi
11.1 Retry with Exponential Backoff
11.2 Dead-Letter Queues
11.3 Fallback Logic
11.4 Graceful Degradation
EN:
Systems should fail safely, not catastrophically.
VI:
Hệ thống nên “fail an toàn”, không phải “fail hoàn toàn”.
12. Architectural Thinking – Tư duy kiến trúc
12.1 Identify Bottlenecks
12.2 Understand Trade-Offs
12.3 No Perfect Architecture
12.4 Build for Evolution, Not Perfection
EN:
System design is not about finding the perfect architecture;
it’s about finding the right trade-offs under constraints.
VI:
System design không phải tìm kiến trúc hoàn hảo;
mà là tìm giải pháp trade-off tối ưu trong giới hạn hệ thống.
[…] System Design Principles Recap […]