Microservices Service Discovery Design Patterns

Service Discovery

Application-level service discovery patterns

This approach is a combination of two patterns.

  1. Self-registration pattern — During startup, a service instance invokes the registry’s registration API to register its network location. A service registry may require that the service instance invoke a heartbeat API periodically to prevent its registration from expiring. When the service instance shuts down, it unregisters itself from the service registry.
  2. Client-side discovery pattern — To invoke a service, a service client queries the service registry for a list of the service’s instances. A load-balancing algorithm is used by the service client to select an instance of the service. The client then requests the selected instance.

Drawbacks of Application-level service discovery

  • Language-specific service discovery libraries are required.
  • It is your responsibility to set up and manage the service registry.
  • When a service instance is running but not handling requests, it often lacks the self-awareness to unregister from the service registry.

Platform-provided service discovery patterns

This approach is a combination of two patterns:

  1. 3rd Party registration pattern —Rather than a service registers itself with the service registry, a third party called the registrar, which is typically part of the deployment platform, does it instead. The registrar registers the service instance with the service registry when it starts up. The registrar unregisters the service instance from the service registry when the instance shuts down.
  2. Server-side discovery pattern — Instead of a client querying the service registry, it makes a request to a DNS name, which resolves to a request router that queries the registry and loads balances requests. The AWS Elastic Load Balancer (ELB) is an example of a server-side discovery router. A client sends HTTP/TCP requests to the ELB, which load balances traffic among a set of EC2 instances. An ELB also acts as a service registry. Instances are registered with the ELB either explicitly via an API call or automatically as part of an auto-scaling group.

Benefits of Platform-based service discovery

  • The deployment platform handles all aspects of service discovery.
  • Neither the services nor the clients contain any code for service discovery.
  • Service discovery is available to all services and clients, regardless of the language in which they are written.

Drawbacks of Platform-based service discovery

  • Only services that have been deployed using the platform can be discovered.

References

--

--

--

“Walking on water and developing software from a specification are easy if both are frozen”

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

All about Front-end & Back-end development!

Kafka + Apache Spark Streaming Example on AWS Free Tier

W3C, IDPF Merge to Make Ebooks Smarter

Common Steps in Page Speed Optimization

Productivity tips for senior developers.

What is Justified Stable Model Constraint Query-Driven Answer Set Programming?

Nomi’s First Project and The Feynman Technique

Sneak Peek into Haptik’s Engineering Culture | Haptik Tech Blog

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Neeraj Kushwaha

Neeraj Kushwaha

“Walking on water and developing software from a specification are easy if both are frozen”

More from Medium

Microservices Cross-Cutting Concerns Design Patterns

Software Architecture — How headless scaleable microservice can be designed

Micro Service Architecture — Design Patterns (Decomposition Pattern)

Microservices