Junior — Middle
Explain the concept of service discovery in microservice architecture and why it is needed.
sobes.tech AI
Answer from AI
Service Discovery in a microservices architecture is a mechanism that allows services to automatically find each other on the network without the need to hard-code addresses.
Why is this needed:
- Microservices can dynamically scale, start, and stop, changing their IP addresses and ports.
- For services to interact, they need to know where other services are located.
- Service discovery helps increase system fault tolerance and flexibility.
Typically, a central service registry (such as Consul, Etcd, or built-in solutions) is used, where services register at startup and from where they get information about other services.
Example: Service A wants to call Service B. Instead of knowing B's IP, Service A queries the registry, gets the current address of B, and makes the request.