# Load Balancer for APIs

**URL:** <https://discuss.konghq.com/t/load-balancer-for-apis/169>\
**Category:** Questions\
**Created:** [December 10, 2017, 8:14pm UTC](https://discuss.konghq.com/t/load-balancer-for-apis/169 "2017-12-10T20:14:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ravi](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@ravi](https://discuss.konghq.com/u/ravi)\
**Post date:** [December 10, 2017, 8:14pm UTC](https://discuss.konghq.com/t/load-balancer-for-apis/169/1 "2017-12-10T20:14:46Z")

</div>

How the upstream added for ring balancer related with APIs upstream url?  
e.g., If I have added an API with upstream url [http://some-host.com:8181/service1](http://some-host.com:8181/service1) and added an upstream with name **ms1** and with target [some-host.com:8181](http://some-host.com:8181), then how can I pass the upstream url? What should be correct way of using upstream?

---

<div class="post-metadata">

**Author:** ![thibaultcha](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/thibaultcha/32/340_2.png) [@thibaultcha](https://discuss.konghq.com/u/thibaultcha)\
**Post date:** [December 11, 2017, 4:26am UTC](https://discuss.konghq.com/t/load-balancer-for-apis/169/2 "2017-12-11T04:26:04Z")

</div>

Hi,

Your question is very vague and open-ended. Have you read the [Load Balancing Reference](https://getkong.org/docs/0.11.x/loadbalancing/)?

Unless you have a more specific question to ask, if you are generally curious about how the Load Balancer works (or any other part of Kong really), I suggest that you read the documentation for it first.

---

<div class="post-metadata">

**Author:** ![ravi](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@ravi](https://discuss.konghq.com/u/ravi)\
**Post date:** [December 11, 2017, 5:28am UTC](https://discuss.konghq.com/t/load-balancer-for-apis/169/3 "2017-12-11T05:28:06Z")

</div>

Hi @thibaultcha,  
Thanks for your reply and I am sorry for not clarifying my question.  
I had read the documentation of Load Balancing. There it is written “upstream: a ‘virtual hostname’ which can be used in an API upstream\_url field”. So, I was not sure how this upstream can be used exactly in API upstream\_url field.  
Now, I think I got it. The name field of upstream could be used as hostname in upstream\_url of an API.

I will edit my previous question to make it more specific.

Thanks.

---

<div class="post-metadata">

**Author:** ![thibaultcha](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/thibaultcha/32/340_2.png) [@thibaultcha](https://discuss.konghq.com/u/thibaultcha)\
**Post date:** [December 11, 2017, 6:45am UTC](https://discuss.konghq.com/t/load-balancer-for-apis/169/4 "2017-12-11T06:45:45Z")

</div>

I see, thanks for clarifying your question.

Well, as specified in the documentation, you tie an Upstream to an API when the Upstream’s `name` matches the hostname in an API’s `upstream_url`. So in your case, your Upstream’s name should be `some-host.com`.

If that is how you configure Kong, then no DNS resolution will take place to resolve your API’s `upstream_url`. Kong de facto uses the list of Targets associated to an Upstream to proxy a request. Targets are intended to represent physical hosts, referenced to by their IP address and port. Kong will iterate over the list of Targets associated to an Upstream in a round-robin fashion, but taking a Target’s `weight` attribute into consideration.

Now, I hope you understand that you would have to script Kong in such a way that those Targets are added and removed appropriately by an orchestrator of your choosing (or your own in-house solution). If instead, you are using a service discovery tool (e.g., Consul), you can delete the Upstream, effectively we-enabling DNS resolution of the `upstream_url` by Kong, and point Kong’s DNS resolver to the nameserver provided by your orchestration tool. Under the hood, Kong can then load balance over A or SRV records automatically and will respect the records’ TTL values.

Now, I believe I have mostly re-stated what the referee documentation already establishes. Was anything not clear enough in the documentation that warranted your question?

---

<div class="post-metadata">

**Author:** ![ravi](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@ravi](https://discuss.konghq.com/u/ravi)\
**Post date:** [December 11, 2017, 7:11am UTC](https://discuss.konghq.com/t/load-balancer-for-apis/169/5 "2017-12-11T07:11:57Z")

</div>

Your explanation helped me to better understand the load balancing in kong.  
Thanks.
