The Eureka discovery service is a Netflix project that Spring Cloud uses to implement microservices, Eureka helps microservices find each other, all services will register with the eureka discovery service so that when a request comes in this service can route traffic to an available service. Services can be added and removed on the fly, this allows for the application to scale when heavily used. Generally a load balancer is also used so that the load can be spread across the services if multiple instances of the service have been started.
To setup a Eureka Discovery Service we first need to pull in two dependencies in to a Spring Boot project, as per below
Next we need to enable Eureka in the application start up using the @EnableEurekaServer annotation, as per below
Lastly we need to setup a few properties as below, we define a specific port and give the application a name, then we disable the client features and then finally set a URL which the client will use to communicate with this service.
Thats it (pretty simple), when you start the application and go to the URL specified in the properties file you should see something like below, which is the Eureka Discovery Service Dashboard. You can setup the Discovery Service to have replica's for fault tolerance, as you can see we have nothing that is registered yet, in the bootom half we have some general information and the instance information about the service.
Lets build a simple user microservice, I am not going to cover everything regarding the Spring Boot app itself but only focus on the Spring Cloud parts, the dependency that you need is the Eureka client as per below but as you can see its a web application, and I will be using a H2 database, we will also touch on security later in its own section.
To make this a Eureka client we use the @EnableDiscoveryClient annotation
We then add the following application properties, using port 0 will mean that the Eureka Discovery Service will pick a port for us, this allows the coming and going of a user service if we decide to use multiple instances (Eureka will manage the port numbers for us), we give the application a name and a URL, we use devtools to restart our application to restart if changed (remove for production), the eureka instance id allows you to run multiple instances of the same services.
When we start the user service we can see it connecting to the Eureka Discovery Service
If we take a look at the Euireka dashboard we can see that the client has registered, if you start up two services we can see that in the right-hand screenshot.
![]() |
![]() |
If you click on the users-ws... link you will get the port that the client has been assigned, I have created a basic controller to return some text using the URI /users/status/check as you can see below, bear in mond we are directly going to the application service later we will setup the load balancer which will use the Discovery Service to obtain IP and Port numbers of the registered services.
To add other microservices you can simple follow the setup below, this is an example of a Account Management service (not fully configured), simple add the @EnableDiscoveryClient annotation, update the properties and create your controller/service/repository to hook into the Eureka Discovery service. You can slice and dice the application up into whatever services that you need, remember try and keep them small and focused on one task.
If we take a look at the dashboard we can see that the account-ws service is now available