Video in progress

Should things like retry, mTLS and tracing be done with a decorator inside the library, or through a sidecar/service mesh?

A sidecar is independent of language and framework, and the platform team manages it from one place. A library knows the business context: which request is idempotent, which error is transient. I leave the transport level (mTLS, connections, basic metrics) to the mesh, and semantic decisions (retry, fallback) to the application.

📖 Answer

A sidecar (ambassador) is a proxy next to each pod, for example Envoy. It intercepts outgoing and incoming traffic. It is really a decorator at the network level: the application makes ordinary HTTP calls, and the proxy adds TLS, retry, timeouts and metrics to them.

The strengths of a sidecar:

  • Java, Go and Python services get the same policy;
  • mTLS certificates can be rotated without redeploying the application;
  • traffic splitting (canary) and fault injection happen at the platform level.

The strengths of a library (Resilience4j, Spring's RestClient interceptors, Micrometer):

  • can POST /payments be retried? The proxy doesn't know that, the application does;
  • fallbacks, such as returning from a cache or a default value, exist only in the application;
  • business attributes (orderId) and span names in traces belong to the application;
  • debugging is easier: everything is in one process and one log.

Turning on both at once is a typical mistake. The mesh retries 3 times, the application retries 3 times too: 9 requests. Timeouts have to line up as well: if the application timeout is larger than the mesh timeout, the mesh cuts it first and the application gets an unexplained 503.

This is usually how I split it:

  • mesh: mTLS, connection-level timeouts, golden signal metrics, traffic management, and retry only on connection errors (connect-failure, reset), when the request was never sent;
  • application: business retry (with an idempotency key), circuit breaker, fallback, business tracing.

Don't forget the cost of a mesh either: extra memory and latency on every pod, and one more complex piece of infrastructure. In a system with 10 services, a well-tuned shared library is often cheaper. With hundreds of services and several languages, a mesh starts to pay off. Ambient (sidecar-less) meshes are lowering the cost, but that doesn't change the direction of the decision.