Service Discovery

In more traditional distributed systems, services run at fixed, well-known locations, and there are generally fewer dependent or collaborating services. A microservices-based application often runs a large number of services in an environment where the service locations and instances are very dynamic. As we discussed in the resource scheduling section, services are often deployed in a shared cluster of virtual machines. Services are scaled up or out across a cluster of resources to meet the demand. Nodes come and go, and services are reallocated to optimize resource usage. Services provisioned in these environments require some mechanism to enable them to be easily discovered for requests to be sent to them.

Our services will need to communicate with each other, and inbound requests into the system need to be routed to the appropriate services. For this we simply maintain a list of services and their locations, so that we can look up the endpoint location when we need to call it. This is referred to as service discovery, which can be implemented a number of different ways, using a growing number of technologies.

Figure 5.5 shows a conceptual service discovery service with service announcement and lookups.

Image

FIGURE 5.5: Service discovery announcement and lookup

Service Discovery Components and Flow:

Announcements: Every service instance registers with the service discovery registry and can be responsible for sending updates at regular intervals: “Hello, I’m a ‘Catalog Service’ and I’m ready for requests at IP address N.N.N.N on port NNN,” and might subsequently send a follow-up: “Hi, I’m still here and healthy.”

Registry: Manages the list of service instances by service and can perform routine service checks or remove a service instance form the list if it does not check back in, assuming it is no longer with us. “Are you still healthy, ‘Catalog Service’?” “200 I’m still healthy.”

Lookups: When the “Order Service” needs to call a “Catalog Service,” it will get a list of healthy “Catalog Service” instances to send the request to. “Give me a list of ‘Catalog Services.’” Maybe the list is cached in the node for some time and then load balanced across the list of “Catalog Service” instances to distribute the load.

This is generally how service discovery works, even though there are a number of different ways to implment this, and always some trade-offs that need to be considered. Let’s have a closer look at sevice registration, lookup, and service discovery stores.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.86.183