RDS managed nghĩa là AWS lo OS patch, backup automation, failover. Nhưng bạn vẫn phải chọn đúng instance, storage, backup policy. Một team dev chạy db.t3.micro, 20GB gp2, backup retention 0 ngày, single-AZ. 6 tháng sau: DB crash vì hết storage, không backup để restore, downtime 2 ngày.
flowchart TB
App["Lambda / ECS / EC2"]
Proxy["RDS Proxy<br/>connection pooling<br/>multiplex 100 Lambda → 20 DB connections"]
Primary["Primary (Multi-AZ)<br/>standby ở AZ khác"]
Replica["Read Replica<br/>offload SELECT<br/>replication lag <100ms"]
S3Backup["S3 Backup<br/>automated + PITR"]
App --> Proxy
Proxy --> Primary
Primary -->|"async replication"| Replica
Primary -->|"automated"| S3Backup
Setup production: 6 setting mandatory
aws rds create-db-instance \
--db-instance-identifier myapp-db --engine postgres --engine-version 17 \
--db-instance-class db.t4g.medium \
--allocated-storage 100 --storage-type gp3 \
--max-allocated-storage 500 \
--multi-az --backup-retention-period 14 \
--enable-performance-insights --deletion-protection \
--vpc-security-group-ids sg-db --db-subnet-group-name db-subnet
| Setting | Value | Lý do |
|---|---|---|
--storage-type | gp3 | Rẻ hơn gp2 20%, baseline 3000 IOPS free |
--max-allocated-storage | 2-5x initial | Auto scale không downtime |
--multi-az | Yes for prod | Standby instance, failover <2 phút |
--backup-retention-period | 7-35 days | Point-in-Time Recovery |
--deletion-protection | Yes | Chống xóa nhầm |
--enable-performance-insights | Yes | Query performance dashboard |
Câu lệnh trên tạo instance với gp3 (rẻ hơn gp2, baseline IOPS cao hơn), Multi-AZ (failover tự động), và deletion protection (chống xóa nhầm). Đây là 3 setting tối thiểu cho production.
RDS Proxy: giải quyết connection storm
Lambda + RDS = 1,000 Lambda concurrent → 1,000 DB connections → DB overload. RDS Proxy multiplex: 1,000 Lambda share 20-30 DB connections.
aws rds create-db-proxy --db-proxy-name myapp-proxy \
--engine-family POSTGRESQL --role-arn $ROLE_ARN \
--auth "SecretArn=$SECRET_ARN,IAMAuth=DISABLED" \
--vpc-subnet-ids subnet-a subnet-b --require-tls
RDS Proxy giữ connection pool ổn định, tránh tình trạng DB sập vì connection storm khi Lambda scale.
Aurora Serverless v2 & backup
| RDS | Aurora Serverless v2 | |
|---|---|---|
| Scale | Manual | Auto (0.5-128 ACU) |
| Failover | <2 phút | <30 giây |
| Cost | Per instance-hour | Per ACU-hour |
# PITR: restore về điểm bất kỳ trong retention period
aws rds restore-db-instance-to-point-in-time \
--source-db-instance-identifier myapp-db \
--target-db-instance-identifier myapp-db-pitr \
--restore-time "2026-06-21T08:00:00Z"
# Read replica
aws rds create-db-instance-read-replica \
--db-instance-identifier myapp-db-replica \
--source-db-instance-identifier myapp-db --db-instance-class db.t4g.medium
Lưu ý: Read replica yêu cầu source DB instance phải có backup-retention-period > 0 (automated backups được bật). Nếu backup retention = 0, lệnh create-db-instance-read-replica sẽ fail với lỗi.
Ba thứ không thể thiếu trên RDS production: gp3 (rẻ hơn, IOPS cao hơn), Multi-AZ (failover tự động), và deletion protection (chống xóa nhầm). Còn lại tùy workload.