Service discovery is the process of discovering and tracking the services running within a given network. This enables teams to create a record of those distributed services, monitor health, and dynamically push updated configurations with minimal disruption. 

By maintaining this centralized, real-time registry of what's actively running, solutions such as load balancers can help your services communicate with each other. For example, Service 1 may depend on Service 2 to power core functions, making it important that the load balancers can identify the instances of Service 2 that are ready for requests. That requires in-depth knowledge of existing endpoints, APIs, and other virtualized deployments within your environment. It also means accounting for different server clusters and nodes—each of which (potentially) hosts individual services depending on your infrastructure setup.

How does service discovery work?

Each service running on a network has an identity that distinguishes it from another. When a service spins up, it's automatically added to a registry (often called a "catalog"). A variety of tools such as DNS, Consul, Kubernetes, and others can manage this catalog.

This catalog updates automatically as services are added or removed. This process ensures that active services remain reachable while enabling more comprehensive load balancing. Such "volatility" is common within Kubernetes applications, which rely on numerous lightweight services and on demand instance scalability to cope with traffic changes. 

There are also two types of service discovery: 

  1. Client side – Each service instance registers itself with the catalog and queries it to find other services it needs to communicate with. Request routing and load balancing are largely the client's responsibility. 

  2. Server side – An intermediary load balancer receives client requests and queries the service catalog itself, before forwarding those requests to healthy service instances.

What makes service discovery useful?

As we've mentioned, service discovery is as much about visibility/monitoring as it is service interoperability. It enables closer observability over both conventional, cloud-based applications and modern microservices. Some other critical benefits include the following: 

  • Dynamic configuration – Service discovery helps organizations readily push application configuration changes even as services are added, removed, and scaled. This is also handy for uncovering services and configuring them in real-time as their locations change. These functions are especially important for ephemeral, containerized services running on pods. 

  • Easier management – Since all services are logged in one place, it's much easier to oversee them despite changes in environmental complexity. 

  • Load balancing – Knowledge of both services and their server locations enables load balancers to distribute traffic based on pre-configured rules, such as load balancing algorithms.  

  • Increased reliability – Since service discovery and health monitoring go hand in hand, a load balancer can detect cluster downtime and redirect traffic to functioning instances. 

  • Abstraction – Discovery business logic is hidden from applications and maintained elsewhere. 

  • Dynamic IP address & port discovery – Through mechanisms like data plane or control plane APIs (or popular integrations like Consul), solutions such as load balancers can automatically obtain this information as services come online. 

By empowering DevSecOps teams and the services they monitor, service discovery streamlines the otherwise painstaking process of manually finding and documenting application services.

How does HAProxy handle service discovery?

Together, HAProxy Enterprise and HAProxy Fusion Control Plane enable streamlined, automated service discovery for your applications. HAProxy Fusion offers deep observability of each HAProxy Enterprise instance and cluster, while connecting to the Kubernetes API to retrieve pod IP addresses and services. 

HAProxy Fusion can then dynamically update all HAProxy Enterprise instances as configuration changes are made. This works for instances running inside or outside of Kubernetes (K8s) while providing secure, high-performance load balancing for K8s traffic. To learn more about service discovery in HAProxy, check out our Kubernetes solution page or view our on-demand webinar on external load balancing.