radio_button_unchecked AWS ECS: Service vs. Task Architecture

Interactive simulation of Traffic Flow, Auto-Healing, and "Service Crash" scenarios.

Created by Rajat Kumar

help First, answering "1-home-instance"

Based on the name 1-home-instance, this is almost certainly a Task (or an underlying EC2 Instance), NOT a Service. Services usually have static names like home-service. Specific running copies with IDs or numbers (like 1-...) are the actual workers (Tasks).

Architecture Simulator

person

Client

alt_route ALB

Load Balancer

Listener: 80

Target Group
  • 10.0.1.5:80
  • 10.0.1.6:80
  • 10.0.1.7:80

radio_button_unchecked ECS Service

Active
LOGIC CRASHED / STUCK

Role: The Manager

Desired Count: 3

Auto-Healing: ON

dns Task 10.0.1.5
dns Task 10.0.1.6
dns Task 10.0.1.7

Architecture Notes

1. The Request Lifecycle (Client to Task)

When a user makes a request to your application, the flow is strictly hierarchical. The Load Balancer does not "know" about the Service logic; it only knows IP addresses.

  1. Client: Sends a request (e.g., GET /api) to the Load Balancer's DNS name.
  2. Load Balancer (ALB): Receives the request on a specific Listener (e.g., Port 80).
  3. Target Group (The Registry): The ALB checks the Target Group associated with that Listener. The Target Group contains a list of IP addresses and ports of currently healthy Tasks.
  4. Task (The Worker): The ALB picks one IP from the Target Group and forwards the request directly to that Task. The Task processes it and responds.

2. Service vs. Task: Who does what?

3. Key Takeaway: "The Service Crash Scenario"

Scenario: Service Management Logic Fails

If your Service crashes (the management logic fails or CloudFormation stack is stuck), your application will stay online.

Why? Because the Load Balancer talks to the Tasks (via the Target Group registry), not to the Service. As long as the Tasks (containers) are alive on the EC2/Fargate infrastructure, traffic flows.

The Catch (No Auto-Healing)

Because the "Manager" (Service) is dead, if a Task fails now (e.g., runs out of memory), a new Task will NOT start automatically. The brain is gone, so the body cannot heal itself.

4. Additional Q&A

Q: If I delete my Service, do Tasks delete?

A: Yes. When you explicitly delete a Service via Console/CLI, the Service sends a "Stop" signal to all its Tasks before it dies. This is different from the Service "crashing" or being "unreachable."

Q: Can 3 tasks in 1 Service have different Target Groups?

A: No. Tasks in a Service are clones. The Service registers all its tasks to the Target Group(s) you defined. You cannot route Task A to TG-1 and Task B to TG-2. They all go to the same place(s).

Visual Summary Diagram

Detailed AWS ECS Architecture Diagram showing Clients, ALB, Target Groups and Services

Diagram: Client Traffic vs Service Management Plane