Mục tiêu học tập
- So sánh các database services
- Hiểu khi nào dùng database nào
- Nắm vững database scaling patterns
1. Database Decision Tree
2. Aurora Advanced
Aurora Global Database
Aurora Serverless v2
Scaling: 0 ACU to 256 ACU
- Max 256 ACU (từ 10/2024; trước đó 128)
- Min 0 ACU với auto-pause (từ 11/2024;
trước đó min 0.5 ACU)
- Auto-scales in seconds
- Pay per ACU-hour used
Use cases:
- Variable workloads
- Development/Test
- Multi-tenant applications
Lưu ý: Aurora Serverless v1 đã EOL 31/12/2024
— mọi scenario serverless Aurora giờ là v2.
Aurora DSQL (GA May 2025)
Aurora DSQL là distributed SQL serverless database PostgreSQL-compatible — khác hẳn Aurora Global Database thông thường ở chỗ hỗ trợ active-active multi-region writes với ACID đảm bảo.
Aurora DSQL vs Aurora Global Database:
| Tiêu chí | Aurora DSQL | Aurora Global Database |
|---|---|---|
| Write topology | Active-active multi-region | Single primary, async replicas (hoặc write forwarding) |
| Consistency cross-region | Strong (ACID) | Eventual (~< 1s lag) |
| Failover RTO | Near-zero (đã active) | < 1 minute |
| SLA | 99.999% multi-region | 99.99% region, 99.95% với failover |
| Schema/feature | PostgreSQL subset (no triggers, FKs có hạn chế) | Aurora full PostgreSQL/MySQL |
| Pricing | Serverless per-request | Per instance + I/O |
| Use case | Multi-region financial / inventory / global SaaS cần ACID | Multi-region read-heavy + DR |
Exam keyword:
- "Multi-region SQL với active-active writes, strong consistency" → Aurora DSQL
- "Global app cần ACID transaction cross-region, no downtime failover" → Aurora DSQL
- "Existing Aurora workload, cần multi-region read replica + failover < 1 min" → Aurora Global Database (write forwarding nếu cần write từ region phụ)
- "Cần feature PostgreSQL đầy đủ (triggers, extensions, foreign keys phức tạp)" → Aurora Global Database, KHÔNG phải DSQL (DSQL còn giới hạn feature)
3. DynamoDB Advanced
Global Tables
DynamoDB Streams + Lambda
4. ElastiCache Strategies
Caching Patterns
1. LAZY LOADING (Cache-Aside):
- Read: Cache miss → Read DB → Write cache
- Stale data possible
2. WRITE-THROUGH:
- Write: Write DB + Write cache
- Always consistent
- Higher write latency
3. TTL:
- Set expiration on cached data
- Balance freshness vs performance
Redis vs Memcached
| Feature | Redis | Memcached |
|---|---|---|
| Data structures | Yes (lists, sets) | No |
| Persistence | Yes | No |
| Replication | Yes | No |
| Multi-AZ | Yes | No |
| Pub/Sub | Yes | No |
| Use case | Complex caching | Simple caching |
5. Câu hỏi ôn tập
-
Khi nào chọn DynamoDB vs RDS?
Xem đáp án
DynamoDB khi: (1) cần millisecond latency at any scale (10M+ req/s), (2) data model là key-value hoặc document, (3) schema không cố định hoặc thay đổi thường xuyên, (4) serverless/global scale, (5) không cần complex SQL joins. RDS khi: (1) cần ACID transactions phức tạp, (2) complex JOINs giữa nhiều tables, (3) reporting/analytics với SQL, (4) existing apps với relational schema, (5) team quen với SQL. Aurora = enhanced RDS cho scale và availability cao hơn.
-
Aurora Global Database replication lag bao nhiêu?
Xem đáp án
Thường dưới 1 giây — Aurora Global Database dùng storage-level replication (không phải binlog) với dedicated replication infrastructure. Thực tế thường < 1 giây, trong tài liệu AWS cam kết thường < 1 giây cho "typical workloads". Failover (promote secondary): < 1 phút (managed failover). Đây là lý do Aurora Global Database phù hợp cho DR với RPO gần 0 và RTO < 1 phút.
-
DynamoDB Global Tables là active-active hay active-passive?
Xem đáp án
Active-active — tất cả Regions đều có thể read và write đồng thời. Khác với nhiều DB replication là active-passive (chỉ primary write). Global Tables dùng last-writer-wins để resolve conflicts. Phù hợp cho: global applications cần low-latency writes từ nhiều continents, gaming leaderboards, user profiles. Design pattern: partition users theo Region (user từ Asia → write Asia table) để tránh conflicts.
-
Redis vs Memcached khác nhau như thế nào?
Xem đáp án
Redis: persistence (RDB + AOF), replication, pub/sub, Sorted Sets, Streams, scripting, Multi-AZ failover — feature-rich. Memcached: đơn giản, multi-threaded (scale CPU cores), horizontal sharding, không có persistence — pure cache. Chọn Redis khi: cần persistence, replication, pub/sub, complex data types, HA. Chọn Memcached khi: pure caching đơn giản, cần multi-threading cho CPU-intensive cache operations, không cần persistence.
6. Bài tập thực hành
-
Aurora Serverless v2 auto-pause: tạo Aurora PostgreSQL Serverless v2 cluster với capacity range 0–4 ACU (min 0 để bật auto-pause). Để idle ~10 phút, quan sát metric
ServerlessDatabaseCapacityvề 0, rồi đo thời gian resume khi có connection mới. Ghi lại trade-off resume latency vs chi phí idle. -
DynamoDB Global Tables: tạo Global Table 2 regions, write cùng một item từ cả 2 region gần như đồng thời và quan sát last-writer-wins conflict resolution qua item cuối cùng. Rút ra vì sao nên partition user theo region.
-
Caching pattern với ElastiCache: dựng Redis (Serverless hoặc node nhỏ), implement lazy loading + TTL trước một bảng RDS/DynamoDB; đo latency cache hit vs miss và thảo luận khi nào cần write-through.
Tài liệu tham khảo chính thức
Ngày tiếp theo: Quiz tổng kết Tuần 5