Service Mesh introduction
Вставка
- Опубліковано 2 гру 2024
- Service mesh
Service mesh is an infrastructure layer used to manage service-to-service traffic through the capabilities provided by a set of sidecar proxies.
It solves the traffic management challenges for microservice applications and manages service communication.
Let us take an example
Service A was expecting a response from Service B through an API call. Service B may be down or facing a heavy load, or there can be a network failure, so immediate response was not sent back to Service A.
It can be handled in 3 different ways
1. Write a logic in Service A to try calling the API of Service B in a loop for 3 times. Add a delay of 2 seconds between calls. We can write a for / while loop and add this functionality to code.
2. Use a library and declaratively to handle the retry and delay functionality
In java, we can use spring framework @Retryable annotation
@Retryable(value = MyNetworkException.class, backoff = @Backoff(delay = 2000))
public String fetchRemoteData() {
// Network call that might fail
return "Data";
}
3. Use service mesh and declaratively define this logic, out side the application code. Add the configuration related to retry in the mesh, and the service proxy will automatically retry when the request fails according to this configuration.
-route:
-destination:
host: upstream-service # Route the request to the upstream service
retries: # Retry 3 times with a timeout of 2 seconds per retry
attempts: 3
perTryTimeout: 2s
Cloud Native Technology: Provide nonfunctional requirements to the infrastructure and let the application focus on business logic.
#microservicesarchitecture #cloudnative