This is the ninth installment in our series on microservices architecture patterns. In previous posts, we've explored topics such as synchronous and asynchronous communication, process orchestration, and fault tolerance. If you're looking for a comprehensive overview of how to design, deploy, and operate microservices professionally, we recommend reviewing the earlier posts:

  1. Microservices Architecture Patterns: What Are They and What Benefits Do They Offer?
  2. Architecture Patterns: Organization and Structure of Microservices.
  3. Architecture Patterns: Microservices Communication and Coordination.
  4. Microservices Architecture Patterns: SAGA, API Gateway, and Service Discovery.
  5. Microservices Architecture Patterns: Event Sourcing and Event-Driven Architecture (EDA).
  6. Microservices Architecture Patterns: Communication and Coordination with CQRS, BFF, and Outbox.
  7. Microservices Patterns: Scalability and Resource Management with Auto Scaling.
  8. Architecture Patterns: From Monolith to Microservices

In today’s modern IT landscape, microservices have become one of the preferred strategies for designing and scaling complex applications.

This article focuses on a key architectural pattern: Externalized Configuration, and we’ll explore:

The eCommerce context is ideal to illustrate this pattern, just like in the rest of our series, since it involves multiple domains and specialized services: a product catalog, order module, payment service, logistics service, and more. Each of these has its own dependencies, configurations, and exposed APIs consumed by other modules.

Challenges of Configuration Management in a Microservices Environment

Before diving in, let’s reinforce why this pattern is essential in microservices architecture:

With this context in mind, let’s break down the pattern and how to implement it—with a strong technical focus.

Externalized Configuration

Externalized configuration structure in microservices

*Storage doesn’t need to be cloud-based.

1 Pattern Fundamentals

Externalized configuration is based on the principle that all variable or sensitive service information should live outside the binary itself. That means credentials, payment gateway tokens, dependency URLs, or business parameters should not be embedded in the source code or internal config files—they should be injected at deploy time, or ideally, managed by a separate service.

2 Key Benefits

  1. Security and Governance
  1. Deployment Flexibility
  1. Maintainability and Scalability

3 Methods to Externalize Configuration

Broadly speaking, there are three common approaches: environment variables, external files, and centralized configuration services. Let’s examine each in more detail.

  1. Environment Variables

Docker: When launching a container with docker run, we can define:

docker run -d \
  -e DB_USER=admin \
  -e DB_PASS=secret123 \
  -e SPRING_PROFILES_ACTIVE=prod \
  --name orders-service \
  myrepo/orders-service:latest

Here, DB_USER and DB_PASS are read within the service using System.getenv(), or via properties in Spring Boot (spring.datasource.username=${DB_USER}, etc.)

Kubernetes: a ConfigMap is used for generic variables and a Secret is used for credentials or sensitive values.

Here’s an example of a Deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: orders-service
spec:
  replicas: 2
  selector:
    matchLabels:
      app: orders-service
  template:
    metadata:
      labels:
        app: orders-service
    spec:
      containers:
      - name: orders-service
        image: myrepo/orders-service:latest
        env:
          - name: DB_USER
            valueFrom:
              configMapKeyRef:
                name: orders-config
                key: db-user
          - name: DB_PASS
            valueFrom:
              secretKeyRef:
                name: orders-secrets
                key: db-pass

This way, each pod inherits the appropriate configuration.

Advantages:

Limitations:

Versioned external files

Another option is to store parameters in configuration files (YAML, JSON, Properties) located outside the service’s main folder, but still accessible at runtime.

For example, in application-prod.yml, we could have:

payment:
  provider: "Stripe"
  api-key: "sk_live_XYZ123"
catalog:
  url: "http://catalog-service:8080"

These files can be mounted as a volume in Docker containers, downloaded at deployment time from an independent Git repository (GitOps), and integrated with frameworks (Spring Boot allows importing additional files with spring.config.additional-location).

Advantages:

Disadvantages:

Centralized Configuration Services

For large microservice ecosystems, a configuration server becomes a key component. Some popular tools include:

Advantages:

Disadvantages:

3 Detailed example in an eCommerce with Spring Boot and Kubernetes

Imagine our eCommerce platform is made up of four microservices:

  1. Config Server:
server:
  port: 8888
spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/myorg/config-repo
          default-label: main
  1. Git repository “config-repo”:
catalog:
  db:
    url: "jdbc:postgresql://prod-db-host/catalog"
    user: "catalog_user"
    pass: "SuperSecretPass"
  cache-ttl: 300
  1. catalog-service (Spring Boot microservice)
spring:
  application:
    name: catalog-service
  cloud:
    config:
      uri: http://config-server:8888
      profile: prod
      label: main
  1. Deployment on Kubernetes:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: catalog-service
spec:
  replicas: 2
  selector:
    matchLabels:
      app: catalog-service
  template:
    metadata:
      labels:
        app: catalog-service
    spec:
      containers:
      - name: catalog-service
        image: myrepo/catalog-service:latest
        env:
          - name: SPRING_PROFILES_ACTIVE
            value: "prod"
          - name: SPRING_CLOUD_CONFIG_URI
            value: "http://config-server:8888"
  1. Configuration change:

This workflow is repeated for orders-service, payment-service, and so on, maintaining configuration in a central and version-controlled location. As the platform grows, this practice becomes essential for governance and security.

Benefits of Externalized Configuration

General Best Practices

Conclusions and Next Steps

Microservices architectures provide scalability and flexibility, but require solid management and validation practices to maintain consistency in a distributed environment. To build a more effective solution to common challenges, we suggest:

In the next post, we'll explore Consumer-Driven Contract Testing (CDCT). If you have any comments, we’d love to hear from you 👇.

Tell us what you think.

Comments are moderated and will only be visible if they add to the discussion in a constructive way. If you disagree with a point, please, be polite.

Subscribe