ZYVOPMulti-Platform Sync
SeriesAI NewsWhy ZyVOPJoin Discord
LoginGet Started
ZYVOPMulti-Platform Sync

The Developer Publishing Hub. Write once, publish everywhere, and make your work citation-ready with built-in SEO, AEO, and GEO discovery support. Zero reader paywalls.

Content

  • Categories
  • Tags
  • Badges
  • Leaderboard
  • Write Article
  • Newsletter

Company

  • About Us
  • Why ZyVOP
  • Changelog
  • Compare Platforms
  • Hashnode vs ZyVOP
  • DEV vs ZyVOP
  • Developer API & CLI
  • Author Handbook
  • Contact

Connect

  • Privacy Policy
  • Terms of Service
  • Cookie Policy
  • DMCA Policy
  • Code of Conduct

ยฉ 2026 ZyVOP. Developer Publishing Hub.

Zero paywalls ยท Full content ownership
All systems operational
HomeTutorialService Discovery with Eureka and Spring Cloud: A Production Hands-On Guide
Tutorial

Service Discovery with Eureka and Spring Cloud: A Production Hands-On Guide

A complete step-by-step guide to building resilient microservice discovery and client-side load balancing with Spring Boot.

Shubham Bhati
Shubham Bhati
Java Backend Engineer | Microservices
July 31, 2026Updated August 30, 2026
3 min read
Series

Production-Grade Microservices Architecture with Java & Spring Boot

Part 1 of 3

Prev
Next
Service Discovery with Eureka and Spring Cloud: A Production Hands-On Guide
#AI#backend#springcloud#eureka#springboot#java#Architecture#Microservices
๐Ÿ‘1

When you scale beyond two microservices, hardcoding IP addresses or domain names in application.properties breaks down fast. Instances get destroyed, auto-scaled up or redeployed on new port allocations. If your payment service has to track where three instances of the order service live, you end up writing custom routing scripts or risking downtime every time a deployment finishes.

In this guide we will set up a production-ready Service Discovery server using Netflix Eureka and Spring Cloud. I've used this exact pattern in production fintech and e-commerce setups where keeping infrastructure costs under โ‚น100 per month while processing thousands of requests was non-negotiable.


๐Ÿ” What is Eureka Service Discovery?

Netflix Eureka acts as a dynamic service registry. Think of it as an automated phone book for your backend microservices:

  1. Eureka Server: The central registry where every running instance registers its hostname, IP and port.

  2. Eureka Clients: Microservices (like user-service, order-service or payment-service) that register themselves at startup and periodically send heartbeats (every 30 seconds by default) to stay active in the registry.

When order-service needs to talk to user-service, it asks Eureka for the available live instances of user-service and client-side load balances the request using Spring Cloud LoadBalancer.


๐Ÿ› ๏ธ Step 1: Setting Up the Eureka Registry Server

First let's create a standalone Spring Boot application for our Eureka Server.

Maven Dependencies (pom.xml)

Add the Eureka Server starter dependency to your build file:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>

Application Main Class

Enable the server registry using the @EnableEurekaServer annotation:

package com.tracker.discovery;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class DiscoveryServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(DiscoveryServerApplication.class, args);
    }
}

Server Configuration (application.yml)

Because this is the central registry itself, we tell Eureka not to register with itself:

server:
  port: 8761

spring:
  application:
    name: discovery-server

eureka:
  instance:
    hostname: localhost
  client:
    register-with-eureka: false
    fetch-registry: false
    service-url:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
  server:
    wait-time-in-ms-when-sync-empty: 0
    response-cache-update-interval-ms: 5000

Start the application and open http://localhost:8761 in your browser. You will see the live Netflix Eureka dashboard running.


๐Ÿ“ก Step 2: Registering a Microservice (Eureka Client)

Now let's connect a Spring Boot microservice to register automatically with Eureka on startup.

Client Dependency (pom.xml)

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

Client Configuration (application.yml)

server:
  port: 8081

spring:
  application:
    name: activity-service

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/
    registry-fetch-interval-seconds: 5
  instance:
    prefer-ip-address: true
    lease-renewal-interval-in-seconds: 10
    lease-expiration-duration-in-seconds: 30

When activity-service starts up, it sends a REST register payload to http://localhost:8761/eureka/. Refreshing http://localhost:8761 will show ACTIVITY-SERVICE registered under Instances currently registered with Eureka.


โšก Step 3: Inter-Service Communication with WebClient & LoadBalancer

Now let's call activity-service from another microservice using logical service names instead of hardcoded IPs.

WebClient Configuration

Annotate your WebClient.Builder with @LoadBalanced:

package com.tracker.gateway.config;

import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.client.WebClient;

@Configuration
public class ClientConfig {

    @Bean
    @LoadBalanced
    public WebClient.Builder loadBalancedWebClientBuilder() {
        return WebClient.builder();
    }
}

Making the Inter-Service Call

@Service
public class AnalyticsService {

    private final WebClient.Builder webClientBuilder;

    public AnalyticsService(WebClient.Builder webClientBuilder) {
        this.webClientBuilder = webClientBuilder;
    }

    public String fetchUserSummary(String userId) {
        return webClientBuilder.build()
                .get()
                .uri("http://activity-service/api/activitylog/user/{id}", userId)
                .retrieve()
                .bodyToMono(String.class)
                .block();
    }
}

Notice the URI target: http://activity-service/.... Spring Cloud LoadBalancer automatically resolves activity-service to a live IP and port from Eureka's local cache.


๐Ÿš€ Production Best Practices & Optimization

๐Ÿ’ก Production Tip: Tuning heartbeats and memory limits is what separates local dev setups from high-throughput production clusters.

  1. Eviction Timers & Heartbeats: Default heartbeat renewal is 30s with a 90s expiration. In fast-restarting cloud deployments, lower lease-renewal-interval-in-seconds to 10s and lease-expiration-duration-in-seconds to 30s to clean stale instances faster.

  2. Self-Preservation Mode: If network blips happen, Eureka enters self-preservation mode and stops evicting dead instances to prevent wiping the registry. In local/dev environments set eureka.server.enable-self-preservation: false.

  3. Cost & Memory Optimization: In our e-commerce platform that generated over โ‚น1L in revenue within 2 months, we ran Eureka Server alongside Spring Cloud Config Server on minimal instances (under โ‚น100/month hosting), keeping RAM usage below 250MB with tuned JVM heap limits (-Xmx256m).


๐ŸŽฏ Summary

Eureka service discovery removes hardcoded networking from microservices architecture. Combined with Spring Cloud Gateway and LoadBalancer, you get instant service registry, health-checking and dynamic routing out of the box.

Series

Production-Grade Microservices Architecture with Java & Spring Boot

Part 1 of 3

Prev
Next

Comments (0)

Login to post a comment.

Shubham Bhati
Shubham Bhati

Java Backend Engineer | Microservices

Backend Engineer with 3+ years of experience building resilient microservices, event-driven pipelines and high-concurrency systems using Java, Spring Boot, Kafka, Redis and PostgreSQL. Engineered fintech transaction routing at MobilePe, B2B logistics pipelines at AlignBits and architected an e-commerce backend hosted under โ‚น100/month in infra costs that generated โ‚น1L+ revenue in 2 months. I write hands-on guides on Spring Cloud, service discovery, database indexing and low-cost architecture patterns.

Subscribe to Shubham Bhati's Newsletter

Direct email dispatches when new stories are published. Zero algorithms.

More from Shubham Bhati

View profile

Event-Driven Microservices with Apache Kafka, Redis Caching and Transactional Outbox Pattern

Master high-throughput event-driven microservices architecture using Java 21, Spring Boot 3.4+, Apache Kafka, Redis distributed locking and the Transactional Outbox Pattern to guarantee zero data loss and sub-10ms P99 latency under traffic spikes.

3 minAug 16

Centralized Secret Management with Spring Cloud Config & Vault: A Production Guide

Hardcoding DB credentials, JWT secrets or API keys inside application.yml or Docker images is a security disaster waiting to happen. Learn how to set up a production-grade Spring Cloud Config Server integrated with HashiCorp Vault for zero-downtime secret rotation across microservices.

2 minAug 1