Skip to content

shawnginx/nginx-consistent-hash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nginx-consistent-hash

Example of NGINX Load Balancing (Consistent Hashing)

Load balancing across multiple application instances is a commonly used technique for optimizing resource utilization, maximizing throughput, reducing latency, and ensuring fault‑tolerant configurations.

This repo provides an example of how to configure a NGINX load balancer and test sample video services using the algorithm of consistent hashing.

Consistent Hashing

Consistent Hashing is a distributed hashing scheme that operates independently of the number of servers or objects in a distributed hash table by assigning them a position on an abstract circle, or hash ring. This allows servers and objects to scale without affecting the overall system.

Prerequisites

Getting Started

  • Run a NGINX load balancer and 5 sample video servcies as containers:

    make start
  • Check if the above containers are successfully started:

    make watch

  • Request sample APIs:

  • Check the status of load balancer:

    Note:

    Try killing some of containers and restart them to see how the load balancer works based on consistent hashing algorithm.

    docker kill video-service-05
    curl localhost/videos
    docker kill video-service-01
    curl localhost/videos
    curl localhost/dummy
    make start
  • Stop containers and clean the images:

    make down
    make clean

Consistent Hashing Configuration

upstream video_services {
    zone video_services 64k;
    hash $request_uri consistent;
    server host.docker.internal:11001;
    server host.docker.internal:11002;
    server host.docker.internal:11003;
    server host.docker.internal:11004;
    server host.docker.internal:11005;
}

References

About

Example of NGINX Load Balancing (Consistent Hashing)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published