Amazon Redshift
Data Warehouse, OLAP, Columnar Storage, MPP, Spectrum, Zero-ETL
Redshift là gì?
Amazon Redshift là dịch vụ Data Warehouse được quản lý hoàn toàn bởi AWS, được thiết kế cho OLAP (Online Analytical Processing) - phân tích dữ liệu lớn với quy mô petabyte.
Đặc điểm chính
| Đặc điểm | Mô tả |
|---|---|
| Columnar Storage | Lưu trữ theo cột, tối ưu cho query analytical |
| MPP (Massively Parallel Processing) | Xử lý song song trên nhiều node |
| Petabyte Scale | Xử lý dữ liệu từ GB đến PB |
| SQL Compatible | Dùng PostgreSQL-compatible SQL |
| BI Integration | Tích hợp với QuickSight, Tableau, Power BI... |
| Data Lakehouse | Kết hợp data lake (S3) + data warehouse |
Columnar vs Row Storage
Kiến trúc Redshift
Cluster Architecture
Thành phần chính
| Component | Mô tả |
|---|---|
| Leader Node | Nhận query, optimize, phân phối task, aggregate kết quả |
| Compute Nodes | Lưu trữ data, thực thi query song song |
| Slices | Phân vùng nhỏ trong mỗi compute node, xử lý độc lập |
| Redshift Managed Storage (RMS) | S3-backed storage cho RA3 nodes |
Provisioned vs Serverless
So sánh
| Tiêu chí | Provisioned | Serverless |
|---|---|---|
| Quản lý | Bạn chọn số lượng, type node | AWS tự động quản lý |
| Scaling | Manual hoặc Elastic Resize | Tự động scale |
| Billing | Per node-hour | Per RPU-second |
| Use case | Workload ổn định, predictable | Variable, unpredictable workload |
| Setup | Phức tạp hơn | Đơn giản, nhanh |
| Reserved pricing | ✅ Có (lên đến 75% discount) | ✅ Có (lên đến 24% discount) |
Provisioned Cluster
Serverless
Khi nào chọn cái nào?
| Tình huống | Recommendation |
|---|---|
| Workload 24/7, ổn định | 🏆 Provisioned + Reserved |
| Workload peak hours (8h/ngày) | 🏆 Serverless |
| POC, development, testing | 🏆 Serverless |
| Unpredictable workload | 🏆 Serverless |
| Budget hạn chế, cần optimize | Tính toán so sánh |
Node Types
RA3 Nodes (Recommended)
| Node Type | vCPU | Memory | Storage | Price/hour |
|---|---|---|---|---|
| ra3.xlplus | 4 | 32 GB | RMS | ~$1.086 |
| ra3.4xlarge | 12 | 96 GB | RMS | ~$3.26 |
| ra3.16xlarge | 48 | 384 GB | RMS | ~$13.04 |
DC2 Nodes (Dense Compute)
| Node Type | vCPU | Memory | Storage | Price/hour |
|---|---|---|---|---|
| dc2.large | 2 | 15 GB | 160 GB SSD | ~$0.25 |
| dc2.8xlarge | 32 | 244 GB | 2.56 TB SSD | ~$4.80 |
Chọn node nào?
| Tiêu chí | Recommendation |
|---|---|
| Data < 1TB, performance critical | DC2 |
| Data growing, cần flexibility | RA3 (recommended) |
| Muốn scale compute riêng storage | RA3 |
| Budget limited, small dataset | DC2.large |
Data Distribution và Sort Keys
Distribution Styles
Cách Redshift phân phối data giữa các nodes quyết định performance của JOIN và aggregation.
Sort Keys
Best Practices
| Scenario | Recommendation |
|---|---|
| Time-series data | Compound sort key (date first) |
| Multi-dimension filtering | Interleaved sort key |
| Large fact table JOIN | KEY distribution (join column) |
| Small dimension table | ALL distribution |
| Don't know | AUTO (let Redshift decide) |
Redshift Spectrum
Redshift Spectrum cho phép query data trực tiếp trên S3 mà không cần load vào Redshift.
Khi nào dùng Spectrum?
| Scenario | Recommendation |
|---|---|
| Historical data, ít query | 🏆 Spectrum (S3) |
| Hot data, query thường xuyên | Redshift tables |
| Data lake integration | 🏆 Spectrum |
| Ad-hoc exploration | 🏆 Spectrum |
Zero-ETL Integration
Zero-ETL là tính năng mới cho phép replicate data từ operational databases vào Redshift tự động, không cần xây dựng ETL pipeline.
Supported Sources
| Source | Status |
|---|---|
| Amazon Aurora MySQL | ✅ GA |
| Amazon Aurora PostgreSQL | ✅ GA |
| Amazon RDS for MySQL | ✅ GA |
| Amazon DynamoDB | ✅ GA |
Concurrency Scaling
Concurrency Scaling tự động thêm capacity khi có quá nhiều concurrent queries.
Data Sharing
Data Sharing cho phép chia sẻ data giữa các Redshift clusters/serverless mà không cần copy data.
Use Cases
| Scenario | Giải thích |
|---|---|
| Multi-tenant SaaS | Mỗi tenant có cluster riêng, đọc từ shared data |
| BI vs ETL separation | BI team đọc từ shared data, không ảnh hưởng ETL |
| Cross-account analytics | Share data với partners, subsidiaries |
Redshift ML
Redshift ML cho phép train và deploy ML models trực tiếp trong Redshift bằng SQL.
| Feature | Mô tả |
|---|---|
| AutoML | Tự động chọn algorithm, tune hyperparameters |
| Bring Your Own Model | Import models từ SageMaker |
| SQL Interface | Không cần biết Python/ML frameworks |
| Pricing | $20/million cells (first 10M) |
Bảo mật
Security Features
Access Control Options
| Feature | Mô tả |
|---|---|
| IAM Integration | authenticate với IAM users/roles |
| AWS IAM Identity Center | SSO cho federated users |
| Row-Level Security | Filter rows based on user |
| Column-Level Security | Grant access đến specific columns |
| Dynamic Data Masking | Mask sensitive data (PII, etc.) |
Chi phí
Provisioned Pricing (us-east-1)
| Node Type | On-Demand/hour | 1-yr Reserved | 3-yr Reserved |
|---|---|---|---|
| dc2.large | $0.25 | $0.145 (-42%) | $0.063 (-75%) |
| ra3.xlplus | $1.086 | $0.63 (-42%) | $0.27 (-75%) |
| ra3.4xlarge | $3.26 | $1.89 (-42%) | $0.82 (-75%) |
Managed Storage (RMS): $0.024/GB-month
Serverless Pricing
| Component | Price |
|---|---|
| RPU-hour | ~$0.375 (base 8 RPU = $3/hour) |
| Managed Storage | $0.024/GB-month |
| Spectrum | Included in RPU |
| Concurrency Scaling | Included in RPU |
Ví dụ tính chi phí
Provisioned (2 x ra3.xlplus, 24/7):
Serverless (8 hours/day, 8 RPU base):
So sánh với các dịch vụ khác
Redshift vs Athena vs RDS
| Tiêu chí | Redshift | Athena | RDS |
|---|---|---|---|
| Type | Data Warehouse | Serverless Query | OLTP Database |
| Use case | BI, Analytics | Ad-hoc queries on S3 | Transactions |
| Data size | GB - PB | GB - PB (S3) | GB - TB |
| Latency | Seconds | Seconds - Minutes | Milliseconds |
| Pricing | Node-hours / RPU | Per query ($5/TB) | Instance hours |
| ETL needed | ✅ Yes (load data) | ❌ No (query S3 directly) | N/A |
| Concurrency | High | Moderate | Very High |
Khi nào dùng gì?
| Scenario | Recommendation |
|---|---|
| Complex BI dashboards, reporting | 🏆 Redshift |
| Ad-hoc queries on S3 data lake | 🏆 Athena |
| Application database | 🏆 RDS / Aurora |
| Real-time analytics | Kinesis + Redshift |
| Data exploration, occasional queries | 🏆 Athena |
| Predictable, heavy analytics workload | 🏆 Redshift Provisioned |
Best Practices
Design
| Practice | Giải thích |
|---|---|
| Chọn Sort Key đúng | Dựa trên WHERE clause phổ biến nhất |
| Chọn Distribution Key đúng | Dựa trên JOIN conditions |
| Dùng RA3 nodes | Tách compute & storage, flexibility |
| Compress data | Automatic, nhưng analyze compression |
Performance
| Practice | Giải thích |
|---|---|
| VACUUM regularly | Sau DELETE/UPDATE để reclaim space |
| ANALYZE tables | Update statistics cho query optimizer |
| Use Workload Management (WLM) | Prioritize queries, set timeouts |
| Monitor with CloudWatch | Query performance, disk space, CPU |
Cost Optimization
| Practice | Giải thích |
|---|---|
| Reserved Instances | Lên đến 75% savings cho steady workload |
| Pause cluster | Khi không dùng (dev/test) |
| Use Spectrum | Cho cold data thay vì load vào Redshift |
| Right-size nodes | Monitor và resize nếu underutilized |
Exam Tips
Key Points
💡 Redshift = Data Warehouse = OLAP = Analytics
| Keyword trong đề | Nghĩ đến |
|---|---|
| Data warehouse, analytics, BI | Redshift |
| Petabyte scale analytics | Redshift |
| OLAP, complex queries | Redshift |
| Columnar storage | Redshift |
| MPP (Massively Parallel Processing) | Redshift |
| Query S3 data lake | Redshift Spectrum hoặc Athena |
| Real-time dashboard | Redshift (với materialized views) |
| ETL from Aurora/RDS | Zero-ETL hoặc Glue |
So sánh nhanh
| Scenario | Service |
|---|---|
| "Data warehouse for BI" | Redshift |
| "Ad-hoc queries on S3" | Athena |
| "Transactional database" | RDS/Aurora |
| "Real-time streaming analytics" | Kinesis Data Analytics |
| "ETL jobs" | Glue |
| "Serverless data warehouse" | Redshift Serverless |
Gotchas
| Trap | Sự thật |
|---|---|
| "Redshift là database?" | ❌ Là Data Warehouse (OLAP), không phải OLTP |
| "Redshift auto-scales?" | Provisioned: ❌ Manual, Serverless: ✅ Auto |
| "Spectrum cần load data?" | ❌ Query trực tiếp trên S3 |
| "Redshift chạy trong VPC?" | ✅ Luôn trong VPC |