Skip to content

A Spring Boot project with HAProxy as load balancer and Docker

License

Notifications You must be signed in to change notification settings

ernestaskardzys/springcluster

Repository files navigation

Introduction

I have decided to play a bit with Docker and Spring Boot. The result is this project - Spring Boot application with HAProxy as load balancer.

I have used the following technologies:

Architecture

Project's architecture is a bit artificial, but it shows how Docker's containers can communicate with each other.

Client calls load balancer (port 80) which redirects REST call to web project. web projects calls number-generator project which is REST application generating random number. This random number is returned back to web project and later back to the user.

As HAProxy works as load balancer it's easy to add multiple instances of the services without no downtime.

Testing

To test the functionality, open a terminal and run:

$ ./gradlew clean build
$ docker-compose build
$ docker-compose up --scale number-generator=5 --scale web=5

This will start a cluster of 1 load balancer, 5 random number generators and 5 web service endpoints (sort of wrapper for random number generators).

And then curl to the load balancer:

$ curl http://localhost/count

Now we have one instance of load balancer running and 5 instances of number-generator and web services.

About

A Spring Boot project with HAProxy as load balancer and Docker

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published