Microservices Service Discovery and Registry Questions and Answers 1 β Questions and Answers
Question 1: A team is deploying microservices in a container orchestration environment like Kubernetes. When a client service needs to communicate with a provider service, it sends a request to a stable virtual IP address managed by the platform. The platform then routes this request to a healthy instance of the provider service. Which service discovery pattern does this scenario describe?
- Client-Side Discovery
- Server-Side Discovery (Correct answer)
- Self-Registration
- Third-Party Registration
Correct answer: Server-Side Discovery
This scenario describes Server-Side Discovery. The client sends a request to a logical endpoint (the Kubernetes Service's stable IP), and the platform's networking layer (acting as a server-side proxy/load balancer) is responsible for discovering a healthy service instance and forwarding the request. The client is completely abstracted from the complexity of looking up individual service instances.
Question 2: What is the primary responsibility of a service registry in a microservices architecture?
- To route incoming client requests to the appropriate service instance.
- To maintain a dynamic, up-to-date list of available service instances and their network locations. (Correct answer)
- To implement the circuit breaker pattern for fault tolerance.
- To manage distributed transactions across multiple services.
Correct answer: To maintain a dynamic, up-to-date list of available service instances and their network locations.
The core function of a service registry is to act as a database or a 'phone book' for services. Its main job is to track which service instances are running and where they can be reached (IP address and port). Routing, circuit breaking, and transaction management are separate concerns handled by other components like load balancers, API gateways, or specific patterns.
Question 3: Which of the following is a key characteristic of the client-side service discovery pattern?
- It simplifies client logic by offloading routing to a central load balancer.
- The client application is completely unaware of the service registry.
- The client directly queries the service registry to get a list of service instances. (Correct answer)
- It is the default pattern used by container orchestrators like Kubernetes.
Correct answer: The client directly queries the service registry to get a list of service instances.
In the client-side discovery pattern, the client application is responsible for interacting directly with the service registry. It queries the registry to obtain a list of available provider service instances and then uses a load-balancing algorithm to select one to connect to. This places more logic on the client compared to the server-side pattern.
Question 4: A potential disadvantage of the self-registration pattern is that it:
- Tightly couples the service code with the service registry. (Correct answer)
- Requires a centralized registrar component to manage all services.
- Cannot be used in modern containerized environments.
- Is less resilient than third-party registration.
Correct answer: Tightly couples the service code with the service registry.
In the self-registration pattern, the microservice itself contains the logic to register with and send heartbeats to the service registry. This couples the service's business logic with the specific concerns and client libraries of the service discovery infrastructure, making it harder to change the registry technology later.
Question 5: An organization is building a microservices platform using a tool like Netflix Eureka. Each service instance, upon startup, is responsible for registering its own network location with the registry and sending periodic heartbeats to indicate it is healthy. What is this registration approach called?
- Proxy-based Registration
- Third-Party Registration
- Self-Registration (Correct answer)
- DNS-based Registration
Correct answer: Self-Registration
This scenario describes the self-registration pattern. The service instance itself takes on the responsibility of managing its lifecycle within the service registry, including registration on startup and sending renewals. Tools like Netflix Eureka are commonly used to implement this pattern.
Question 6: In the context of service discovery, what mechanism is commonly used by a service registry to remove unhealthy or terminated service instances from its list of available endpoints?
- API Gateway rate limiting
- A distributed transaction coordinator
- A publisher/subscriber message queue
- A health check mechanism, such as TTL (Time To Live) heartbeating (Correct answer)
Correct answer: A health check mechanism, such as TTL (Time To Live) heartbeating
Service registries must ensure their data is accurate and current. They achieve this through health checks. A common method is for service instances to send periodic heartbeats to the registry. If the registry doesn't receive a heartbeat within a configured Time To Live (TTL), it assumes the instance is unhealthy or has terminated and removes it from the pool of available instances.
A team is deploying microservices in a container orchestration environment like Kubernetes.
When a client service needs to communicate with a provider service, it sends a request to a stable virtual IP address managed by the platform.
The platform then routes this request to a healthy instance of the provider service.
Which service discovery pattern does this scenario describe?