Client-Side Service Discovery
Why do we need Service Discovery?
Applications we build today have one commonality - they all, more or less, make network calls to external processes and to make such a call, we require the address of the process. We could, in theory, keep those fields somewhere in a static configuration assuming we know them, but the server instance on which the process is hosted changes frequently owing to failures and auto-scaling.
There are two ways in which we can discover said external process - server-side discovery and client-side discovery. Server-side discovery is usually done via load balancers, but today, our focus will be on client-side service discovery.
Service Registry
An important component of every service discovery process (be it server-side or client-side) is service registry. It can be thought of as a database (possibly AZ-aware) that holds the location of all instances of a service. When a new instance comes up, it needs to log its presence in the registry in order to be reachable. That’s not the end of it however; it needs to send periodic hearbeats to broadcast its liveness.
func RegisterInstance(config SvcInstanceCfg) Boolean {
}
func Heartbeat(config SvcInstanceCfg) Boolean {
}
func FetchInstances(svc String) []SvcInstance {
}
Flow
- Client-Side abstraction
- Sidecar pattern