Using AWS ECS Service discovery with Application Load Balancer
Asked Answered
D

2

5

When creating a fargate service in an ECS cluster, I'm using an application load balancer and I'm also using service discovery so my service has an endpoint. My question is: where should I send my requests, to the endpoint provided by service discovery or to the load balancer?

Also, how does the service discovery decides to which task it should send the request to?

I've searched AWS documentation but couldn't find a straight answer to this question.

Diaphony answered 16/9, 2019 at 18:11 Comment(0)
A
5

Service Discovery is for network-level communication. Load balancer for client-server or in other word over internet communication.

So if you want send request from outside of VPC then you will use a Load balancer.

Or

If you want send a request within VPC then you can use service discovery.

how does the service discovery decides to which task it should send the request to?

enter image description here

So Route53 have IP against each fargate services.

To understand how both service work together let have a look in this diagram

enter image description here

So for internal communication better to use service discovery to save time as call is on same network.

For the client to server communication better to use Loadbalancer.

amazon-ecs-service-discovery

Asseverate answered 16/9, 2019 at 18:28 Comment(7)
In the scenario where I have micro-service A send a request to micro-service B (which runs multiple replicas of the same task) within the same VPC, do I need a load balancer for micro-service B ? or service discovery will take of loadbalancing incoming requests from within the vpc ?Diaphony
yes service discover will take care of it. LB is for external traffic (rule of thumb)Asseverate
that's wrong, Load balancer can be Internal and external both. we can even use public IP of fargate task(ENI) to direct traffic on one fargate service and distribute internally to other microservices using Internal load Balancer so it has nothing to do with Internet only. Service discovery with Route53 means you are omitting load balancer and can use route53 "A" record to manually configure service load balancing. This may be because of any reason like some features that LB don't offer or you want more control. aws.amazon.com/blogs/compute/task-networking-in-aws-fargateSybaris
If we talk about load balancr so its mean public load balancr, not internal. Or one can use internal load balancr and that was the approach before service discoverAsseverate
He is using both, and one should not put service in public if he using load balancr, as in the diagram they are in private subnetAsseverate
In Architecture we explicitly mention internal/external and also type like ALB or NLB. Service Discovery and LB are totally different concepts and used for different reasons. I didn't mention to put services in public subent, In Modern architecture for security you would use API Gateway for public access and behind that you need Internal load balancer in private subnet that can load balance between the services. Please have a look at official example on how to architect using fargate. aws.amazon.com/getting-started/projects/…Sybaris
Yes Thanks, Imran, it is one practice so we can not say it is wrong if we see the context of the question if we take the broad the different horses for different courses. I am a fan of service discovery for internal communication why should i managed LB if i can achieve the same without LB? docs.aws.amazon.com/whitepapers/latest/microservices-on-aws/…Asseverate
K
1

Load balancer provides the endpoint to which you can send your requests. The routing of requests to different tasks is taken care by Load balancer and you cannot really control that.

Service discovery on the other hand is a feature that allows the services to find each other by names/urls. This makes internal communication easier in case of Microservices where a master server can know the service discovery url of all and pass messages between micro services

Khaki answered 16/9, 2019 at 18:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.