Consul
Consul is a shared directory that lets applications find services by name instead of keeping lists of IP addresses. It tracks individual service instances and uses health checks to help callers avoid unhealthy ones.
Also known as: service discovery
The problem Consul solves
Say an orders application needs to call a payments service. During a rollout, new payments instances start before old ones shut down. A hard-coded list of IP addresses can point at instances that no longer exist. With HashiCorp Consul, the caller looks up payments instead. Finding the network locations of a service by name at runtime is called service discovery. Consul is a tool that provides it, not another name for the technique.
From registration to lookup
An application or deployment tool registers each instance with a service name, an instance ID, an address, and a port. Several instances can share the same service name. A Consul agent can run a health check, such as an HTTP request to the instance's readiness endpoint, and report the result. Being in the catalog is not the same as being ready for traffic: an instance with a critical health check can remain registered even though Consul leaves it out of normal DNS lookup results for the service.
Callers can discover instances through DNS or the HTTP API. A client can pick an instance and connect directly, or a load balancer can use discovery to maintain its pool of backends. The registry itself does not forward application requests.
Consul servers maintain the catalog and use Raft to agree on changes. A three-server cluster needs two voting servers to commit writes. It can therefore lose one server without losing its ability to commit, but not two.
Example: ask for addresses and ports
This query goes directly to a local Consul agent listening on its default DNS port:
dig @127.0.0.1 -p 8600 payments.service.consul SRV
An SRV response gives target hostnames and ports. An A record gives an IPv4 address but carries no port information. In an application setup, the DNS resolver can forward queries for the .consul zone to Consul so callers do not have to specify its DNS address and port.
When to use it
A shared registry is useful when workloads run across environments, such as virtual machines and Kubernetes, and need a common way to find one another. If discovery is entirely within one Kubernetes cluster, Kubernetes Services and cluster DNS often cover the basic requirement. Consul also offers service mesh features, but a mesh is not required to register a service and look it up.
Interview angle: why do calls still fail?
Walk through what happens when a healthy instance crashes just after a client looks it up. The check may not have detected the failure yet, a resolver may still have the old DNS answer cached, or the client may be reusing an existing connection. Discovery narrows the choice of endpoints; it does not guarantee that the next request will succeed. Explain how timeouts bound the wait and why retries are appropriate only when repeating the operation is safe.