Cross-cutting concerns for microservices
Pattern ¡ Chapter 9
Cross-cutting concerns for microservices
Section titled âCross-cutting concerns for microservicesâIn a monolith, a cross-cutting concern is built once and reused everywhere. In a microservice architecture, each service is independently deployable and self-contained, so a naive approach re-implements every concern in every service â prohibitively expensive when a system has hundreds of services and new ones are created constantly. Two patterns address this.
Microservice chassis
Section titled âMicroservice chassisâA framework that provides cross-cutting concerns for all microservices, so creating a new service stays fast and the team can focus on core concerns.
- Common concerns a chassis handles: logging, externalized configuration, metric reporting/instrumentation, service registration and discovery, health checks, tracing.
- Examples: Spring Cloud, Microdot, Gizmo, Go kit, Dropwizard.
- Doesnât have to be open-source/third-party â an in-house framework tailored to your stack works too. The point is a reusable framework so concerns arenât implemented repeatedly.
Sidecar pattern
Section titled âSidecar patternâMicroservices allow polyglot development (multiple languages, runtimes, frameworks, datastores). That makes maintaining a cross-cutting library per language a duplication and maintainability problem. The sidecar pattern solves it.
- Cross-cutting logic runs in its own process/container (a sidecar / sidekick container) attached to the primary application and running alongside it â like a motorcycle sidecar.
- The sidecarâs language/framework can differ from the primary appâs, so you donât re-implement each concern per language in a heterogeneous environment.
- Primary and sidecar share the same resources (e.g. a health-monitoring sidecar can watch the primaryâs system resources).
- Useful when the sidecar is owned by another team/organization â you can still use it without controlling its implementation.
- IPC between the two should use a language- and framework-agnostic mechanism. Communication is fast (same host) but carries overhead vs. in-process calls; a chatty, fine-grained interface where performance is critical makes the sidecar a poor fit.
Citations
Section titled âCitationsâ- Software Architectâs Handbook (Packt, 2018), Ch.9 âCross-cutting concerns for microservicesâ, pp. 727-731.