Backend Development 11 min read

Implementing a Lightweight Service Registry with Eureka for Task Distribution

This article describes how to build a lightweight service registry using Eureka Server that also acts as a client, enabling a task dispatcher to discover and load‑balance task executor instances without deploying a separate registry, including Maven dependencies, Spring annotations, Feign client definitions, and troubleshooting steps.

Architect's Guide
Architect's Guide
Architect's Guide
Implementing a Lightweight Service Registry with Eureka for Task Distribution

The author presents a practical scenario where a leader requires two services—Task Distribution Center and Task Executor—to support horizontal scaling, but the deployment environment cannot host a separate registration center. The solution is to implement a simplified registration center by integrating Eureka Server directly into the task distribution center, allowing it to also function as a client.

Requirement Overview

Service discovery: store and manage addresses of all available services.

Service registration: providers register their address information.

Health check: periodically verify service availability.

Horizontal expansion: ensure high availability and consistent service lists across nodes.

To avoid deploying a full‑blown registry like Nacos, the author chooses Eureka for its simplicity and familiarity.

Implementation Steps

1. Add Maven Dependency

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

2. Enable Eureka Server, Eureka Client and OpenFeign

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

3. Define Feign Client for Task Executor

@FeignClient("TASK-EXECUTOR")
public interface TaskExecutorService {
    @GetMapping("task/exec")
    String exec(@RequestParam("taskId") Long taskId);
}

4. Implement Dispatch Logic

@GetMapping("dispatch")
public String dispatch(Long jobId) {
    LOGGER.info("Received job [jobId={}]", jobId);
    List
taskIds = Arrays.asList(123L, 666L, 888L, 999L);
    for (Long taskId : taskIds) {
        String result = taskExecutorService.exec(taskId);
        LOGGER.info("Task [{}] result: {}", taskId, result);
    }
    return "success";
}

Initially the request returned HTTP 500 because the load balancer could not find any instance of TASK-EXECUTOR . The root cause was the configuration property fetch-registry=false , which prevented the Eureka client from pulling service instances. Setting it to true resolved the issue.

After correcting the configuration, both task-dispatcher and task-executor start successfully. Sample logs show the dispatcher splitting a job into four tasks and invoking each executor, while the executor logs the receipt and completion of each task.

Running multiple instances of task-executor demonstrates load‑balancing across services.

Summary

It is recommended to deploy a registration center separately from business code.

Eureka Server can act as both server and client, though this is not the best practice.

Experimentation is essential; trying out unconventional approaches can reveal viable solutions.

Microservicesbackend developmentload balancingService DiscoveryfeignEurekaSpring Cloud
Architect's Guide
Written by

Architect's Guide

Dedicated to sharing programmer-architect skills—Java backend, system, microservice, and distributed architectures—to help you become a senior architect.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.