Externalized configuration
Last updated
Last updated
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.
How to enable a service to run in multiple environments without modification?
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
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.
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.
The docker-compose.yml
file supplies its value as an operating system environment variable:
This pattern has the following benefits:
The application runs in multiple environments without modification and/or recompilation
There are the following issues with this pattern:
How to ensure that when an application is deployed the supplied configuration matches what is expected?
The service discovery patterns, [[Server-side service discovery]] and [[Client-side service discovery]], solve the related problem of how a service knows the network location of other application services
RegistrationServiceProxy
from the is an example of a component, which is written in [[Scala]], is configured with the variable user_registration_url
:
REGISTRATION-SERVICE
is the logical name of the service. It is resolved using .