# Load Balancing

![](https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mf443pgq4_SWw_OlWdL%2Fuploads%2Fd81WZJFxboKnW09lWPuT%2Fimage.png?alt=media\&token=449a04c3-2f01-4872-bfc8-f6cef1863737)

* Client to gateway: DNS parse domain to different ip addresses. (If we have multiple data centers, DNS will find the geographically closest data center)
* Gateway to web server: reverse proxy
* web server to application server: connection pool
* database load balancing: partition / sharding

How to distribute traffic:

* random, round-robin
* min connection count
* min latency
* based on IP.

{% embed url="https://www.youtube.com/watch?t=2s&v=K0Ta65OqQkY" %}

### Consistent Hashing <a href="#consistent-hashing" id="consistent-hashing"></a>

* Consistent Hashing is one of the ways to achieve load balancing.
* Consistent Hashing allows requests to be mapped into hashed buckets which allowing the system to add/remove nodes flexibly so as to maintain a good load factor on each machine.

{% embed url="https://www.youtube.com/watch?v=zaRkONvyGr8" %}
