Configuration Externalization — Design Pattern : An Overview

Problem

Abhinav Vinci
3 min readMay 1, 2024

An application typically uses one or more infrastructure (database server..) and 3rd party services ( email, messaging … )

  • How to enable a service to run in multiple environments without modification?
  • A service must run in multiple environments — dev, test, qa, staging, production — without modification and/or recompilation

Solution

Externalize all application configuration like database credentials , env settings. On startup, a service reads the configuration from an external source.

https://learn.microsoft.com/en-us/azure/architecture/patterns/external-configuration-store

External Configuration, or Configuration Externalization, is a design pattern where the configuration settings of an application are stored outside the codebase, typically in external configuration files or centralized configuration services.

  • This pattern allows for the separation of configuration concerns from the application code, making it more flexible, scalable, and easier to manage.
content/patterns/configuration-patterns/externalized-configuration-store-pattern.html

Key principles and benefits of Configuration Externalization pattern:

1. Separation of Concerns: Developers can focus on writing code, while operations or configuration managers can handle tweaking settings without modifying codebase.

2. Dynamic Loading , No re-deployement needed: Modify application settings without redeploying entire application. The application should be designed to load configuration settings dynamically during runtime. This enables changes to take effect immediately without requiring a restart of the application.

3. Security: Sensitive information such as API keys, database credentials, or other secrets should be kept separate from the codebase. External configuration mechanisms provide features for securing sensitive information. This ensures that sensitive information such as passwords or API keys are properly encrypted or stored securely.

PS : Plan for Versioning and Auditing: For larger systems, it’s beneficial to implement versioning and auditing mechanisms for configuration changes. This allows tracking of who made changes and when, which can be useful for troubleshooting and compliance purposes.

Common ways to implement Configuration Externalization :

  • Configuration Files: External configuration files, in formats like JSON, YAML, or properties files, are a common approach. These files can be read by the application at runtime, allowing for easy modifications without code changes.
  • Environment Variables: This is particularly useful for containerized applications or those deployed in cloud environments.
  • Configuration Servers: Dedicated configuration servers, such as Spring Cloud Config Server or HashiCorp Consul, provide a centralized way to manage and distribute configurations across multiple services.
  • Database-based Configuration: Configuration settings can be stored in databases, allowing for dynamic updates and a central location for configuration management.

Popular tools for configuration externalization:

1. Consul: Consul is a service mesh solution that includes a distributed key-value store. It can be used to store configuration data centrally and provide dynamic configuration updates to applications.

2. etcd: Similar to Consul, etcd is a distributed key-value store that can be used for configuration management. It is often used in Kubernetes clusters.

3. Apache ZooKeeper: ZooKeeper is a centralized service for maintaining configuration information, naming... It is commonly used in Apache Hadoop

Spring Cloud Config: Spring Cloud Config provides server and client-side support for externalized configuration in a distributed system. It supports storing configuration data in various backends like Git, Subversion, HashiCorp Consul, or Vault.

4. HashiCorp Vault: Vault is a tool for managing secrets and sensitive data securely. It can be used to store and retrieve configuration settings, including encryption keys, database credentials, and API tokens.

5. GitHub, GitLab..: Version control systems like GitHub, GitLab can be used to store configuration files alongside application code. This approach allows for versioning, collaboration, and auditability of configuration changes.

6. Kubernetes ConfigMaps and Secrets: In Kubernetes clusters, ConfigMaps and Secrets can be used to store configuration data and sensitive information, respectively.

tldr: By adopting the Configuration Externalization pattern, applications become more flexible, easier to maintain, and can be configured for different environments without code modifications.

In next blog :

  • Drawbacks of Configuration Externalization ?
  • Archiecture ? Components ?
  • When exactly to use Configuration Externalization ?
  • Configuration Externalization Best practices / common mistakes
  • How to choose a configuration platform. ?

--

--