InterviewSolution
| 1. |
How will you implement service discovery in microservices architecture? |
|
Answer» Servers come and go in a cloud environment, and new instances of same services can be deployed to cater increasing load of requests. So it becomes absolutely essential to have service registry & discovery that can be queried for finding address (host, port & protocol) of a given server. We may also need to locate servers for the purpose of client-side load balancing (Ribbon) and handling failover gracefully (Hystrix). Spring Cloud solves this problem by providing a few ready-made solutions for this challenge. There are mainly two options available for the service discovery - Netflix Eureka Server and Consul. Let's discuss both of these briefly: Netflix Eureka Server Eureka is a REST (Representational State Transfer) based service that is primarily used in the AWS cloud for locating services for the purpose of load balancing and failover of middle-tier servers. The main features of Netflix Eureka are:
Spring Cloud provides two dependencies - eureka-server and eureka-client. Eureka server dependency is only REQUIRED in eureka server’s build.gradle
On the other hand, each microservice need to include the eureka-client dependencies to ENABLES eureka discovery. build.gradle - Eureka Client (to be included in all microservices) compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'). Eureka server provides a basic dashboard for monitoring various instances and their health in the service registry. The ui is written in freemarker and provided out of the box without any extra CONFIGURATION. Screenshot for Eureka Server looks like the following. It contains a list of all services that are registered with Eureka Server. Each server has information like zone, host, port, and protocol. Consul Server It is a REST-based tool for dynamic service registry. It can be used for REGISTERING a new service, locating a service and health checkup of a service. You have the option to choose any one of the above in your spring cloud-based distributed APPLICATION. In this book, we will focus more on the Netflix Eureka Server option. |
|