Service Discovery
Tags: systems, microservices, architecture, beginners
Published: 2023-03-07 06:42:49

Service discovery is a process of detecting services within network [clusters](https://dev.to/pragyasapkota/clustering-how-much-does-it-differ-from-load-balancing-3i1e). It works on Service Discovery Protocol (SDP) — a networking standard for detecting network service by identifying resources. Usually, we see services invoke each other via language-level methods or procedure calls in the [monolithic](https://dev.to/pragyasapkota/monoliths-2n2m) application. But modern [microservices](https://dev.to/pragyasapkota/microservices-21oe) have virtualized or containerized environments where there are instances of a service and their locations that change dynamically. Also, we have mechanisms that enable clients of the service to make requests to the dynamically changing set of temporary service instances.

Some of the common examples of service discovery tools are etcd, Consul, Apache Thrift, Apache Zookeeper, etc.

## Implementations of service discovery

### Client-side Discovery

On the Client-side service discovery, the client looks for the service location of another service by querying a service registry that handles the network locations of all the service instances.

![Client-side Discovery](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/53mqb004npc0z18tq3st.jpg)

### Server-side Discovery

Likewise, we have an intermediate element like a load balancer where a client requests the service via the load balancer which will be consequently forwarded to the available service in an instant.

![Server-side Discovery](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/or9jg45qaelbbvmmo2bd.jpg)

## What is Service Registry?

Service Registry is a database with the network locations of service instances for the clients to reach out to when required. To note, a service registry is highly available and up to date at any time.

## Service Registration

There are some ways of getting the service information known as service registration.

### Self-Registration

Self-registration registers and de-registers service instances itself in the service registry. It even encourages the service instances to send a [heartbeat request](https://dev.to/pragyasapkota/heartbeat-messaging-what-is-it-18a6) to keep its registration alive.

### Third-Party Registration

Further, we have third-party registration that keeps the track of changes in the running instances by polling the deployment environment or subscribing to events. It also records a new service instance in the database while the service registry also de-registers terminated service instances.

## Service Mesh

When you have [distributed](https://dev.to/pragyasapkota/distributed-system-the-definition-nkh) communication, service-to-service communication is necessary but routing this communication, all the application clusters within and across the system gets complex. Then, comes Service Mesh to the rescue by managing and securing the communications between the individual services. In addition, communication is also made observable. The SDP works on full standards for service detection in the mesh. Some of the common examples of service mesh are [Istio](https://istio.io/latest/about/service-mesh/) and [Envoy](https://www.envoyproxy.io/).

**_I hope this article was helpful to you._**

**_Please don’t forget to follow me!!!_**

**_Any kind of feedback or comment is welcome!!!_**

**_Thank you for your time and support!!!!_**

**_Keep Reading!! Keep Learning!!!_**