Messaging & Streaming
Amazon MSK (Managed Streaming for Apache Kafka)
Managed Streaming for Apache Kafka, Serverless, MSK Connect
Tổng quan
Amazon MSK là dịch vụ fully managed Apache Kafka cho phép build và run applications sử dụng Kafka để xử lý streaming data.
Lợi ích chính
| Lợi ích | Mô tả |
|---|---|
| Fully managed | AWS lo brokers, patching, monitoring |
| Compatible | 100% tương thích Apache Kafka APIs |
| Highly available | Multi-AZ replication |
| Secure | VPC, encryption, IAM, TLS |
| Scalable | Scale brokers và storage dễ dàng |
Kiến trúc
Data Flow
Các thành phần chính
1. Brokers
| Đặc điểm | Mô tả |
|---|---|
| Là gì | Kafka servers xử lý read/write |
| Số lượng | Tối thiểu 2, recommended 3+ (multi-AZ) |
| Instance types | kafka.m5.large → kafka.m5.24xlarge |
| Storage | EBS volumes, auto-scaling available |
2. Topics & Partitions
| Thành phần | Mô tả |
|---|---|
| Topic | Category/feed của messages |
| Partition | Subset của topic, distributed across brokers |
| Replication | Copies of partitions (default: 3) |
| Retention | Bao lâu giữ messages (default: 7 days, max: unlimited) |
3. ZooKeeper vs KRaft
| Mode | Mô tả |
|---|---|
| ZooKeeper | Legacy, AWS quản lý ZooKeeper nodes riêng |
| KRaft | Mới, không cần ZooKeeper, metadata trong Kafka brokers |
[!TIP] KRaft mode được recommend cho clusters mới - đơn giản hơn và performance tốt hơn.
MSK Serverless vs Provisioned
| Tiêu chí | MSK Serverless | MSK Provisioned |
|---|---|---|
| Quản lý capacity | Tự động | Manual |
| Pricing | Per partition-hour + data | Per broker-hour + storage |
| Max partitions | 120 per cluster | Unlimited |
| Custom configs | Limited | Full access |
| Use case | Variable/unpredictable workloads | Steady, predictable workloads |
MSK Connect
MSK Connect cho phép stream data GIỮA MSK và các services khác mà không cần code.
Security
1. Network Security
| Layer | Options |
|---|---|
| VPC | MSK cluster trong private subnets |
| Security Groups | Control traffic vào brokers |
| Private connectivity | VPC endpoints, PrivateLink |
2. Encryption
| Type | Mô tả |
|---|---|
| At-rest | EBS encryption với KMS |
| In-transit | TLS between clients và brokers |
| In-cluster | TLS between brokers |
3. Authentication & Authorization
| Method | Mô tả |
|---|---|
| IAM | AWS IAM policies cho Kafka APIs |
| SASL/SCRAM | Username/password authentication |
| TLS mutual auth | Client certificates |
| ACLs | Kafka Access Control Lists |
So sánh MSK vs Kinesis
| Tiêu chí | Amazon MSK | Kinesis Data Streams |
|---|---|---|
| Protocol | Apache Kafka | AWS proprietary |
| Message size | Default 1MB, configurable | Max 1MB |
| Retention | Unlimited | Max 365 days |
| Replication | Configurable | 3 AZs (fixed) |
| Partition scaling | Manual/add brokers | Shard splitting (auto available) |
| Ordering | Per partition | Per shard |
| Pricing model | Per broker + storage | Per shard-hour + data |
| Serverless | ✅ MSK Serverless | ✅ On-demand mode |
| Migration from Kafka | ✅ Easy (same APIs) | ❌ Code changes needed |
Khi nào dùng MSK vs Kinesis?
| Scenario | Chọn |
|---|---|
| Đã có Kafka on-premises, muốn migrate | MSK ✅ |
| Team đã biết Kafka ecosystem | MSK ✅ |
| Muốn AWS native, ít operational overhead | Kinesis ✅ |
| Cần Lambda trigger dễ dàng | Kinesis ✅ |
| Cần message retention vô hạn | MSK ✅ |
| Cần Kafka Connect plugins | MSK ✅ |
Pricing
MSK Provisioned
| Component | Pricing |
|---|---|
| Broker hours | Per instance type per hour |
| Storage | Per GB-month |
| Data transfer | Standard AWS rates |
MSK Serverless
| Component | Pricing |
|---|---|
| Cluster hours | Per hour cluster runs |
| Partition hours | Per partition per hour |
| Data in/out | Per GB |
| Storage | Per GB-month |
Use Cases
| Use Case | Mô tả |
|---|---|
| Log aggregation | Collect logs từ nhiều sources |
| Real-time analytics | Process streaming data |
| Event-driven architecture | Decouple microservices |
| Data pipeline | ETL, data lake ingestion |
| IoT data streaming | Sensor data processing |
| Clickstream analysis | User behavior tracking |
Exam Tips
[!IMPORTANT] Các điểm quan trọng cho AWS Certification:
1. MSK vs Kinesis
- Đã có Kafka → MSK (zero code changes)
- AWS native → Kinesis
- Unlimited retention → MSK
2. MSK Serverless vs Provisioned
- Variable workload → Serverless
- Predictable, high throughput → Provisioned
- Max customization → Provisioned
3. Security
- MSK trong VPC private subnets
- TLS + KMS cho encryption
- IAM auth cho managed authentication
4. Integration patterns
5. Câu hỏi thường gặp
| Câu hỏi | Đáp án |
|---|---|
| Migrate Kafka to AWS? | MSK (Kafka compatible) |
| Real-time + AWS native? | Kinesis |
| Kafka Connect plugins? | MSK Connect |
| Serverless Kafka? | MSK Serverless |