Microservice Patterns
Microservice Chassis and Service Template
Give every service the same production-ready foundation — logging, metrics, tracing, health checks, config, timeouts — through a shared chassis library and a template for new services, so safe defaults are the default.
What you will learn
- Explain the cross-cutting concerns every service needs.
- Distinguish a chassis (shared library/platform) from a service template (starting point).
- See how one missing default can take a product down.
- Keep the chassis thin and versioned so it does not become a coupling point.
Before you start
Overview
Car makers build many models on one chassis: brakes, airbags and wiring are designed and tested once. Nobody wants each model's team to reinvent the brakes — and forget them on one model.
Every service needs the same plumbing: structured logging with trace ids, metrics, tracing, health and readiness endpoints, configuration and secrets, HTTP clients with timeouts and retries, graceful shutdown. A microservice chassis packages these as a shared library or platform defaults (e.g. a company Spring Boot starter). A service template is a repository you copy to start a new service with the chassis, build pipeline, Dockerfile and dashboards already in place.
Run it
Three teams' services feed one product page. In A each team wired its own HTTP client and one forgot a timeout; in B all use the chassis defaults. The shared database slows down at t = 10 s.
What belongs in the chassis
- Observability: JSON logs with trace ids, RED metrics, tracing exporters, standard dashboards.
- Resilience: HTTP/gRPC clients with timeouts, retries with budgets, circuit breakers — on by default.
- Operations: liveness/readiness endpoints, graceful shutdown, configuration from the external store.
- Security: token validation, mTLS, safe serialisation, dependency scanning in the template's pipeline.
- Not business logic or shared domain models — those couple services together.
A company starter
@AutoConfiguration
@EnableConfigurationProperties(ChassisHttpProperties.class)
public class ChassisHttpAutoConfiguration {
@Bean
@ConditionalOnMissingBean
RestClientCustomizer chassisTimeouts(ChassisHttpProperties props, ObservationRegistry observations) {
return builder -> {
HttpClient http = HttpClient.newBuilder().connectTimeout(props.connectTimeout()).build(); // default 1 s
JdkClientHttpRequestFactory factory = new JdkClientHttpRequestFactory(http);
factory.setReadTimeout(props.readTimeout()); // default 2 s
builder.requestFactory(factory).observationRegistry(observations); // metrics + trace spans
};
}
}Trade-offs
| Benefits | Costs | |
|---|---|---|
| Consistency | Every service is observable and resilient from day one. | Teams depend on the chassis team's release cadence. |
| Speed | New services start in minutes from the template. | Templates drift: services copied a year ago miss later improvements. |
| Polyglot | One well-supported stack is easy to operate. | Each extra language needs its own chassis — or sidecars. |
Production considerations
- Track chassis versions per service and automate upgrades (Renovate, Dependabot).
- Make the safe option the default and the unsafe one explicit (e.g.
timeout: nonemust be written out). - Test the template continuously by generating a service from it in CI.
- Treat the chassis as a product with documentation, changelog and support.