Service Discovery in Microservices _ Baeldung on Computer Science
Service Discovery in Microservices _ Baeldung on Computer Science
https://www.baeldung.com/cs/service-discovery-microservices 2/10
4/24/25, 5:02 PM Service Discovery in Microservices | Baeldung on Computer Science
(/wp-content/uploads/sites/4/2022/01/Service-Discovery-Client-Side.png)
Giving responsibility for client-side load balancing is both a burden and an
advantage. It’s an advantage because it saves an extra hop that we would’ve
had with a dedicated load balancer. It’s a disadvantage because the Service
Consumer must implement the load balancing logic.
https://www.baeldung.com/cs/service-discovery-microservices 4/10
4/24/25, 5:02 PM Service Discovery in Microservices | Baeldung on Computer Science
We can also point out that the Service Consumer and the Service Registry are
(/cs/) (/bael-search)
quite coupled. This means that Client-Side Discovery logic must be
implemented for each programming language and framework used by the
Service Consumers.
Now that we’ve clarified Client-Side Discovery, let’s take a look at Server-Side
Discovery.
(/wp-content/uploads/sites/4/2022/01/Service-Discovery-Server-Side.png)
In this approach, a dedicated actor, the Load Balancer, does the job of load
balancing. This is the main advantage of this approach. Indeed, creating this
level of abstraction makes the Service Consumer lighter, as it doesn’t have
to deal with the lookup procedure. As a matter of fact, there’s no need to
implement the discovery logic separately for each language and framework
that the Service Consumer uses.
On the other hand, we must set up and manage the Load Balancer, unless
it’s already provided in the deployment environment.
https://www.baeldung.com/cs/service-discovery-microservices 5/10
4/24/25, 5:02 PM Service Discovery in Microservices | Baeldung on Computer Science
Now that we’ve delved into the different approaches to the discovery
(/cs/) (/bael-search)
mechanisms, let’s move on to registration mechanisms.
7.1. Self-Registration
When using the self-registration model, a service instance is responsible
for registering and de-registering itself in the Service Registry. In addition, if
necessary, a service instance sends heartbeat
(https://martinfowler.com/articles/patterns-of-distributed-
systems/heartbeat.html) requests to keep its registration alive. The following
diagram shows the structure of this pattern:
https://www.baeldung.com/cs/service-discovery-microservices 6/10
4/24/25, 5:02 PM Service Discovery in Microservices | Baeldung on Computer Science
(/cs/) (/bael-search)
(/wp-content/uploads/sites/4/2022/01/Service-Discovery-Self-
Registration.png)
The self-registration model has several pros and cons. One advantage is that
it’s relatively simple and doesn’t require other system components as
intermediaries. However, a significant disadvantage is that it couples service
instances to the Service Registry, which means we must implement the
registration code in each language and framework used.
An alternate approach, which decouples services from the Service Registry, is
the third-party registration scheme.
https://www.baeldung.com/cs/service-discovery-microservices 7/10
4/24/25, 5:02 PM Service Discovery in Microservices | Baeldung on Computer Science
(/cs/) (/bael-search)
(/wp-content/uploads/sites/4/2022/01/Service-Discovery-3rd-
Registration.png)
Like self-registration, the third-party registration scheme also has various pros
and cons. One of the main advantages is that services are decoupled from the
Service Registry. There’s no need to implement service registration logic for
each programming language and framework. Instead, the registration of
service instances is managed centrally within a dedicated service.
One disadvantage of this model is that, unless it’s embedded in the
deployment environment, it’s yet another highly available system component
that needs to be set up and managed.
8. Conclusion
This article outlines how a microservice application contains several service
instances running with dynamic changes. These instances have dynamic
network locations and need a way to communicate or locate. Therefore, a
client needs a mechanism, such as Service Discovery, to make a request.
Service Discovery helps by providing a database of available service
instances so that services can be discovered, registered, and de-registered
based on usage.
2 COMMENTS Oldest
https://www.baeldung.com/cs/service-discovery-microservices 8/10