Building Eureka Discovery for Spring Microservices

Creating a microservice with Spring Cloud Netflix Eureka for service discovery gives distributed Spring Boot applications a shared catalogue of available instances. Instead of hard-coding hosts and ports, each client registers under a logical service name, while consumers resolve that name through the registry.

The example below uses three small projects: a Eureka server, an inventory-service, and an order-service. It demonstrates registration, service-to-service calls with OpenFeign, and the checks required by teams running microservices for Australian organisations.

Start the Eureka server

Create a separate Spring Boot application and add spring-cloud-starter-netflix-eureka-server. Select a Spring Cloud release train compatible with your Spring Boot version, and manage it through the Spring Cloud dependency BOM rather than pinning individual starters.

For developers refreshing their setup, the practical Java guidance covers the foundations used here. The registry is a Spring Boot process too, so add normal logging, health checks and a secure deployment profile. Include spring-boot-starter-actuator when using Actuator health endpoints.

Annotate its application class with @EnableEurekaServer:

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(EurekaServerApplication.class, args);
    }
}

For a standalone local server, prevent it from registering with itself:

server:
  port: 8761
eureka:
  instance:
    hostname: localhost
  client:
    register-with-eureka: false
    fetch-registry: false

Register the business services

Add spring-cloud-starter-netflix-eureka-client to inventory-service and order-service. Spring Boot auto-registers the application, while @EnableDiscoveryClient makes the intent explicit. Give each service a stable spring.application.name.

spring:
  application:
    name: inventory-service
eureka:
  client:
    service-url:
      defaultZone: ${EUREKA_SERVICE_URL}
  instance:
    prefer-ip-address: true
    lease-renewal-interval-in-seconds: 10
    lease-expiration-duration-in-seconds: 30

Set EUREKA_SERVICE_URL to the registry’s full HTTP address, including the /eureka/ path. For local development, that address points to port 8761.

A dependable registration includes:

On startup, the client sends its registration and renews a lease as a heartbeat. The Eureka server groups instances by application name and removes one that stops renewing, allowing consumers to stop routing requests to it.

Call services by logical name

Add spring-cloud-starter-openfeign to the consuming service, enable scanning with @EnableFeignClients, and define a client without a host or port:

@FeignClient(name = "inventory-service")
public interface InventoryClient {
    @GetMapping("/inventory/{sku}")
    InventoryResponse checkStock(@PathVariable String sku);
}

Inject this interface into an order handler and call checkStock("SKU-123"). Spring Cloud LoadBalancer asks Eureka for available inventory-service instances and selects one. A Feign client can therefore replace a brittle URL containing a fixed inventory host with a logical dependency.

Configure connection and read timeouts so an unavailable replica cannot hold a request open indefinitely. A @LoadBalanced RestTemplate or WebClient can replace Feign where its declarative model does not suit the endpoint.

Secure the registry and calls

Do not expose the Eureka dashboard to the public internet. Restrict it to private networks or a VPN, require authentication, and avoid publishing sensitive Actuator data. Service metadata can reveal internal hostnames, so treat registration details as operational information.

Use TLS for registry and service traffic, and protect business endpoints with an authentication mechanism such as OAuth 2.0 resource servers and signed JWTs. Discovery locates a service; it does not verify who may call it or what data the caller may access.

Discovery also needs resilience. Apply bounded timeouts, circuit breakers and limited retries for idempotent operations. Avoid blind retries for order creation or payment requests. Spring Cloud Gateway can handle north-south routing, but Eureka remains a registry rather than an API gateway.

Run and verify the stack

Start the Eureka server first, then the inventory and order services. Run each from its own terminal with mvn spring-boot:run, and inspect the Eureka dashboard on port 8761. It should show two application groups, each with at least one registered instance.

A useful verification sequence is:

If registration fails, check the /eureka/ suffix, the client’s reachable address and the server logs. If discovery works but calls fail, inspect the returned host and port. Allow enough time for the lease to expire before judging failover behaviour.

Prepare for Australian production conditions

Choose Australian cloud regions deliberately. AWS regions in Sydney and Melbourne, plus comparable Azure regions, can reduce latency, but registry addresses, advertised instance addresses and security-group rules must be routable between services. Never publish localhost; clients can continue using cached registrations during a brief outage, but fresh lookups and rebalancing may pause.

Treat Eureka metadata as part of your data-governance assessment. Where microservices handle personal information, document the flows against the Privacy Act 1988 and the Australian Privacy Principles, and keep customer records out of service names or metadata. The Australian Signals Directorate’s Essential Eight also provides a useful baseline through MFA, timely patching, application control and centralised logging.

Record timestamps in UTC while presenting AEST and AEDT, because a Brisbane team working with Sydney and Melbourne colleagues sees different local times when daylight saving begins. For commercial APIs, support Australian dollar pricing and GST-inclusive billing through validated environment configuration, not hard-coded Eureka values. This keeps service location dynamic while making security, taxation and privacy responsibilities explicit and testable.