Load balancer and API Gateway confusion

为君一笑 提交于 2020-07-09 12:48:05

问题


I have always worked on mobile technologies and now I am stepping into backend systems, more specifically systems design. I keep coming across conflicting statements for the roles of api gateway and load balancer. Googling has only returned the same half a dozen results that mostly focus on the implementations of load balancer or api gateway service provided by some famous service. I will list here all the confusing I am facing, in hope someone can clarify all of them.

Sometimes, i come across that API Gateway is the single point of communication with client devices. On the other hand, some places mention that 'request goes to load balancer, which spreads it across servers equally'. So what is correct? API Gateway receives requests or load balancer?

Other places, when I googled the topic, say that the two are totally different. I've understood that API Gateway does a lot of stuff, like SSL termination, logging, throttling, validation, etc, but it also does load balancing. So API Gateway is a load balancer itself, equipped with other responsibilities?

On the topic, I want to understand if load balancer distribute load among servers of the same cluster or across different data centers or clusters? And what about API Gateway?

What is so specific to api gateway that it is a choice by default for micro-service architecture? Where are API gateways hosted? A DNS resolves domain name to a load balancer or api gateway?

As it might be clear, I am totally confused. In what systems does a load balancer benefit more than API Gateway, if the question is correct.


回答1:


API gateway predominately does API management and provides various other key features such as IAM (Identity and Access Management), Rate limiting, circuit breakers. Hence, it mainly eliminates the need to implement API-specific code for functionalities such as security, caching, throttling, and monitoring for each of the microservice. Microservices typically expose the REST APIs for use in front ends, other microservices and 3rd party apps with help of API gateway.

However, normally, the API Management does not include load balancing function, so it should be used in conjunction with a load balancer to achieve the same.

In system architecture based on Azure, there is Azure Application Gateway which is a load balancer that runs on Layer 7 and provides more features than traditional load balancer ( Layer 4 ) in terms of routing traffic using routing decisions based on additional attributes of HTTP request or content of traffic. This can also be termed as an application load balancer. It shall be used in conjunction by Azure API Management (API gateway). Azure has a Traffic Manager for operating at DNS level which uses DNS to direct client requests to the most appropriate service endpoint based on a traffic-routing method and the health of the endpoints. Traffic manager also uses the rules configured at the DNS level and enables dstribution of the the load over multiple regions and data centers. Within every region or data center, there shall be application gateways coupled with load balancers such that, the application gateways shall help in determining the application server to fetch response from and the load balancer shall help in load balancing.

System overview based on Azure :

System overview based on Azure

Here are few related references:

  1. Azure Application Gateway - https://docs.microsoft.com/en-us/azure/application-gateway/application-gateway-introduction

  2. Azure Load Balancer- https://docs.microsoft.com/en-us/azure/load-balancer/load-balancer-overview

  3. Azure Traffic Manager - https://docs.microsoft.com/en-us/azure/traffic-manager/traffic-manager-overview

  4. Scenario Architecture - https://docs.microsoft.com/en-us/azure/traffic-manager/traffic-manager-load-balancing-azure




回答2:


API Gateway and Load Balancer are 2 different things.

Load Balancer -> Its a software which works at protocol or socket level (eg. tcp, http, or port 3306 etc.) Its job is to balance the incoming traffic by distributing it to the destinations with various logics (eg. Round robin). I doesn't offer features such as authorisation checks, authentication of requests etc.

Whereas

API Gateway -> Its a managed service provided by various hosting companies to manage API operations to seamlessly scale the API infra. It takes cares of the access control, response caching, response types, authorisation, authentication, request throttling, data handling, identifying the right destinations based on custom rules, and seamless scaling the backend. Generally Managed API gateways by default comes with scalable infra, so putting them behind load balancer might not make sense.

About resolving the Domain, most likely always the DNS resolves to the load balancer, which intern fetches the response from the API gateway service.

DNS -> Load Balancer -> API gateway -> Backend service

Hope I could explain and clear your confusion.



来源:https://stackoverflow.com/questions/61174839/load-balancer-and-api-gateway-confusion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!