Practical Guide to Building a Eureka Service Registry Cluster with Ribbon Load Balancing
This article provides a step‑by‑step tutorial on creating a Eureka registration center, developing product and order microservices, configuring Ribbon for client‑side load balancing, forming a Eureka cluster, and testing the complete microservice ecosystem, all using Spring Cloud and Spring Boot.
The article walks through a hands‑on implementation of a service discovery solution using Netflix Eureka and Spring Cloud, demonstrating how to register services, perform inter‑service calls without hard‑coded IPs, and achieve load balancing with Ribbon.
1. Create Eureka Server – A Spring Boot application annotated with @SpringBootApplication and @EnableEurekaServer is set up. The application.yml configures the server port (8761) and disables self‑registration ( register-with-eureka: false) and registry fetching ( fetch-registry: false). Required Maven dependencies are added for Spring Cloud and Eureka Server.
2. Build Product Service – Two instances run on ports 8006 and 8007. The application.yml registers each instance with the Eureka server ( defaultZone: http://localhost:8761/eureka). A @RestController provides a /product/{name} endpoint returning a simple string. Maven includes spring-boot-starter-web and Eureka client dependencies.
3. Build Order Service – Runs on port 9091, includes Ribbon for client‑side load balancing. The configuration adds spring-cloud-starter-netflix-ribbon. A RestTemplate bean is annotated with @LoadBalanced so calls to http://ProductService/product/{id} are resolved via Eureka. The controller exposes /order/{id} which forwards the request to the product service.
4. Form Eureka Cluster – Two Eureka servers (ports 8761 and 8762) are configured to register with each other via defaultZone URLs, and the local hosts file maps eureka-server1 and eureka-server2 to 127.0.0.1. After starting both, the dashboards at http://localhost:8761/ and http://localhost:8762/ show both servers, confirming clustering.
5. Register Services to the Cluster – Product and order services point their defaultZone to both Eureka instances ( http://localhost:8761/eureka,http://localhost:8762/eureka), enabling high availability.
6. Test the Setup – Using Postman or a browser, invoke the product API ( http://localhost:8006/getProduct/...) and the order API ( http://localhost:9091/order/...). The order service retrieves the product service URL from Eureka and calls it via Ribbon, demonstrating load‑balanced requests across the two product instances.
7. Summary – The tutorial covers how to use Eureka as a registration center, register multiple services, avoid hard‑coded IPs, create a Eureka cluster, and combine it with Ribbon to achieve client‑side load balancing in a microservice architecture.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Wukong Talks Architecture
Explaining distributed systems and architecture through stories. Author of the "JVM Performance Tuning in Practice" column, open-source author of "Spring Cloud in Practice PassJava", and independently developed a PMP practice quiz mini-program.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
