Introduction
Among the wide range of AWS services, Amazon Elastic Container Service (ECS), a container orchestration service, has gained attention as a cornerstone of modern application development. ECS is a managed service designed to facilitate container operations, and when using ECS, users must decide between the two data plane options: ECS on EC2 and ECS on Fargate. This article compares the EC2 and Fargate options for the data plane of ECS.
ECS on EC2
In the ECS on EC2 architecture, ECS functions as the control plane, while EC2 serves as the data plane. ECS Tasks are launched on EC2 instances, where containers are executed.
Cost Considerations
The cost of using ECS on EC2 primarily consists of two parts:
-
Service Usage Cost
This pertains to the usage of EC2 instances and EBS volumes. Specifically, EC2 instances are billed based on the time they are running. Proper capacity planning can help manage costs effectively. -
Operational Cost
This includes costs associated with maintaining EC2 instances. Tasks such as applying OS updates and security patches are the responsibility of the user.
Scalability
ECS on EC2 offers the following scalability features:
-
Deployment Speed
Storing image caches on EC2 hosts enables swift deployment of new containers. -
Horizontal Scaling
Scaling is limited to the allocated capacity, as determined by capacity planning. -
Resource Expansion
Adjusting EC2 instance sizes or choosing instance families allows easy modification and expansion of resources.
Reliability
Operational troubleshooting and issue investigation on EC2 are possible through:
-
SSH Access
If issues arise, users can directly access EC2 instances via SSH for investigation. -
System Manager
AWS System Manager allows accessing EC2 instances without using SSH.
ECS on Fargate
In ECS on Fargate, ECS functions as the control plane, and Fargate acts as the data plane. With this configuration, physical server management becomes unnecessary, and ECS Tasks can be executed directly on Fargate.
Cost Considerations
Costs associated with using ECS on Fargate are related to the following factors:
-
Service Usage Cost
This mainly involves the cost of using Fargate. Charges are based on vCPU and memory resource usage. The billing period starts from image retrieval until the ECS Task terminates. Usage fees are generally around 20-30% higher compared to EC2. -
Operational Cost
Due to its serverless nature, costs related to traditional infrastructure maintenance and management are significantly reduced.
Scalability
ECS on Fargate offers the following scalability characteristics:
-
Deployment Speed
Each container is associated with an Elastic Network Interface (ENI), causing slight latency at times. Additionally, the absence of image caching requires image retrieval with each container launch. -
Horizontal Scaling
Fargate automatically handles resource provisioning, enabling rapid scaling.
Reliability
Operational troubleshooting and issue investigation on ECS on Fargate are possible using ECS Exec. ECS Exec permits executing commands directly on containers running on Fargate.
Choosing Between EC2 and Fargate
EC2 and Fargate each have distinct use cases.
Need to Store Large Amounts of Data Locally
Certain applications, particularly those involving concepts like blockchain, require storing significant amounts of data locally. In such cases, EC2 is suitable due to the flexibility and scalability of physical storage.
Requirement for Machine Learning
Machine learning model training and inference demand substantial computational resources. Particularly when specialized hardware like GPUs is needed, selecting EC2 instance types can fulfill these requirements. Since current Fargate does not support GPUs, EC2 is better suited for such use cases.
Desire for High Resource Efficiency
Achieving "high resource efficiency" when running services on EC2 refers to using allocated CPU and memory without wastage. Optimal specification of instance types based on processing needs is essential for achieving high resource efficiency. Fargate eliminates the need for specifying instance types, as it automatically optimizes resources.