Cross cutting concerns Flashcards
Cross cutting concerns
Microservice chassis
Externalized configuration
Microservice chassis: context
When you start the development of an application you often spend a significant amount of time putting in place the mechanisms to handle cross-cutting concerns. Examples of cross-cutting concern include:
- Externalized configuration - includes credentials, and network locations of external services such as databases and message brokers
- Logging - configuring of a logging framework such as log4j or logback
- Health checks - a url that a monitoring service can “ping” to determine the health of the application
- Metrics - measurements that provide insight into what the application is doing and how it is performing
- Distributed tracing - instrument services with code that assigns each external request an unique identifier that is passed between services.
Even though in a monolith application this first configuration is insignificant as a spend of time. In a microservice architecture there will have many services, this time must be taken in account.
Microservice chassis: forces
Creating a new microservice should be fast and easy
When creating a microservice you must handle cross-cutting concerns such as externalized configuration, logging, health checks, metrics, service registration and discovery, circuit breakers. There are also cross-cutting concerns that are specific to the technologies that the microservices uses.
Microservice chassis: solution
Build your microservices using a microservice chassis framework, which handles cross-cutting concerns
Microservice chassis: example
Examples of microservice chassis frameworks:
Spring Boot and Spring Cloud
Dropwizard
Gizmo
Microservice chassis: result
The major benefit of a microservice chassis is that you can quickly and easy get started with developing a microservice.
Microservice chassis: drawback
You need a microservice chassis for each programming language/framework that you want to use. This can be an obstacle to adopting a new programming language or framework.
Microservice chassis: related
Microservices - this pattern motivates the need for the Microservice Chassis pattern
Self Registration - the microservice chassis is often responsible for registering the service with the service registry
Client-side discovery - the microservice chassis is often responsible for client-side service discovery
Circuit Breaker - the microservice chassis framework might implement this pattern
Distributed tracing - the microservice chassis framework might instrument the code
Externalized configuration: context
An application typically uses one or more infrastructure and 3rd party services. Examples of infrastructure services include: a Service registry, a message broker and a database server. Examples of 3rd party services include: payment processing, email and messaging, etc.
Externalized configuration: problem
How to enable a service to run in multiple environments without modification?
Externalized configuration: forces
A service must be provided with configuration data that tells it how to connect to the external/3rd party services. For example, the database network location and credentials
A service must run in multiple environments - dev, test, qa, staging, production - without modification and/or recompilation
Different environments have different instances of the external/3rd party services, e.g. QA database vs. production database, test credit card processing account vs. production credit card processing account
Externalized configuration: solution
Externalize all application configuration including the database credentials and network location. On startup, a service reads the configuration from an external source, e.g. OS environment variables, etc.
Externalized configuration: examples
Spring Boot externalized configuration reads values from a variety of sources including operating system environment variables, property files and command line arguments. These values are available within the Spring application context.
Externalized configuration: result benefits
The application runs in multiple environments without modification and/or recompilation
Externalized configuration: issues
How to ensure that when an application is deployed the supplied configuration matches what is expected?