Scrivio Interview library
DesignIntermediate7 min read · updated 12 November 2026

Design configuration and secrets management for Spring Boot services on Kubernetes, where some values change at runtime and secrets must rotate.

Static configuration comes from ConfigMaps, either as environment variables or as mounted files read with spring.config.import=configtree:. Secrets come from a vault or a cloud secret manager, mounted or fetched at startup, and never live in the image or in git. For values that change at runtime I prefer a redeploy, because refresh mechanisms do not rebind every bean, and I rotate database credentials with a period where both old and new credentials are valid so connection pools can reconnect. Every service validates its configuration at startup and fails fast.

Why this question is asked

Configuration and secrets cause a surprising share of outages and security incidents: a wrong value pushed to production, a password committed to a repository, a rotated credential that breaks every pod at 2 a.m. Interviewers ask this design question to see whether we can separate the different kinds of values, choose how each reaches the application, and handle change and rotation safely. In this answer, we will sort values into kinds, deliver static configuration from ConfigMaps, deliver secrets from a secret manager, decide how to handle runtime changes, design credential rotation, and add startup validation.

1Three Kinds of Values

Not all configuration is the same, and treating it the same is where designs go wrong. Static configuration, such as URLs of other services, timeouts and pool sizes, changes rarely and only through a release. Dynamic configuration, such as feature flags or rate limits, may need to change in minutes without a deployment. Secrets, such as database passwords, API keys and signing keys, must be protected and must change on a schedule or after a leak.

Each kind gets its own path into the service, because each has different needs for review, speed and protection.

Where each kind of value lives
KindExampleSourceHow it changes
Static configpayments.timeout=2sConfigMap from gitNew rollout
Dynamic configcheckout.newFlow=onFeature flag serviceAt runtime, audited
Secretdatabase passwordVault or cloud secret managerRotated with overlap
Separate paths for separate needs.

2Static Configuration From ConfigMaps

A ConfigMap is a Kubernetes object that holds key-value data or files. It can reach a Spring Boot application in two ways. As environment variables, which relaxed binding maps to properties, for example PAYMENTS_TIMEOUT to payments.timeout. Or as mounted files: each key becomes a file in a directory, and Spring Boot's configtree import reads that directory, using the file names as property names and the contents as values.

YAML
# ConfigMap mounted at /etc/config: files named payments.timeout, payments.base-url
# application.yml
spring:
config:
import: "optional:configtree:/etc/config/"
# inside the container
$ cat /etc/config/payments.timeout
2s
# environment.getProperty("payments.timeout") -> 2s

The ConfigMap itself is generated from files in git, so every change is reviewed. I would also add a hash of the ConfigMap's content to the pod template, which tools like Kustomize and Helm can do, so that changing the configuration rolls out new pods in a controlled rolling update instead of silently changing files under running ones.

3Secrets From a Secret Manager

Secrets never belong in the container image, where anyone who pulls the image can read them, or in git, where they stay in history forever. Kubernetes Secrets on their own are only base64-encoded, so they need encryption at rest and tight access controls, and in many organisations the source of truth is a vault, such as HashiCorp Vault, or a cloud secret manager, such as AWS Secrets Manager.

There are two common delivery patterns. The platform syncs or mounts the secret into the pod, for example with the External Secrets Operator or the Secrets Store CSI driver, and the application reads it as a file through configtree, exactly like static configuration. Or the application fetches it at startup through Spring Cloud Vault or Spring Cloud AWS, which add the secrets as a property source. Either way, the application references the secret by name, and access is granted to the service's identity, not to people.

Java
# Secret mounted by the CSI driver at /etc/secrets: files spring.datasource.username, spring.datasource.password
spring:
config:
import:
- "optional:configtree:/etc/config/"
- "configtree:/etc/secrets/" # not optional: missing secrets must stop startup
# spring.datasource.password is now set; it never appears in the image or in git

4Runtime Changes: Redeploy or Refresh?

It is tempting to change values in running pods. Spring Cloud offers a refresh mechanism: after a refresh event, beans in @RefreshScope are recreated and @ConfigurationProperties beans are rebound. But not every bean rebinds. A value injected with @Value into a normal singleton keeps its old value, a DataSource keeps its pool settings, and an HTTP client built at startup keeps its timeouts. So after a refresh, some parts of the service use the new value and some the old one, which is confusing and hard to test.

So for static configuration I prefer a redeploy: a rolling update with the new ConfigMap goes through readiness checks, can be rolled back, and leaves every pod in a known state. For values that truly must change in seconds, I would use a feature flag service built for that, where the code asks for the value each time it needs it, rather than relying on refresh across the whole context.

5Rotating Database Credentials Without Downtime

Rotation breaks things when the old password stops working at the moment the new one appears, because every pod's connection pool still holds connections opened with the old one and may need new connections at any time. The safe design gives both credentials a period of overlap.

Step throughRotation with an overlap period
Secret managerDatabasePod (HikariCP)
create password v2; v1 still valid
deliver v2 (mounted file or fetch)
new connections use v2
old v1 connections retire after maxLifetime
after the overlap, revoke v1
only v2 connections remain

6 messages in order. Play them, or step through them one at a time.

Both credentials work until every pod has moved to the new one.

Notice that connections opened with the old password keep working until they are closed, so HikariCP's maxLifetime, for example 30 minutes, decides how quickly a pod moves fully to the new credential. The overlap period must be longer than the time to deliver the new secret plus maxLifetime. Vault's database secrets engine follows the same idea with dynamic credentials: each instance gets its own user with a lease, and renews or replaces it before expiry.

6Validating at Startup and Failing Fast

The last piece is making bad configuration visible before it serves traffic. Every service binds its settings with @ConfigurationProperties and @Validated, so a missing URL, a negative timeout or an unknown enum value stops startup with a clear message. Because the readiness probe never passes, the rolling update stops at the first new pod, and the old pods keep serving. A typo becomes a failed deployment, not an outage.

Java
@Validated
@ConfigurationProperties("payments")
record PaymentsProperties(@NotNull URI baseUrl, @NotNull Duration timeout) {}
# payments.base-url missing ->
# APPLICATION FAILED TO START ... payments.baseUrl: must not be null

7Follow-up questions

Should applications read secrets from environment variables?

It works, and it is common, but files are usually safer. Environment variables can leak through process listings, crash reports, debugging endpoints and child processes, and they cannot change without restarting the container. Mounted files can be restricted by file permissions and updated in place by the CSI driver, although the application still has to reconnect to use them.

What happens to @Value fields after a refresh?

If the bean is a normal singleton, nothing: the field was injected once at creation. Only beans in @RefreshScope are recreated, and @ConfigurationProperties beans are rebound by Spring Cloud's rebinder. This partial behaviour is the main reason I prefer redeploying for configuration changes.

How do you rotate a secret that a third-party API key represents?

The same way when the provider allows two active keys: create the new key, deliver it, wait until every pod uses it, then revoke the old one. If the provider allows only one key, we schedule the change for a quiet period and make the switch quick, with clear monitoring of authentication errors.

8Conclusion

In this answer, we designed configuration and secrets management for Spring Boot on Kubernetes. Static values come from ConfigMaps generated from git, read as environment variables or with configtree, and change through a rolling update. Secrets come from a vault or cloud secret manager by name, never from the image or git. We prefer redeploying over runtime refresh because not all beans rebind, rotate database credentials with an overlap period sized against the pool's maxLifetime, and validate configuration at startup so bad values fail fast.

What to say in the interviewAbout 90 seconds aloud

Open with

I would split values into three kinds. Static configuration like URLs, timeouts and pool sizes lives in git, becomes a ConfigMap, and reaches the app either as environment variables or as mounted files that Spring Boot reads with spring.config.import configtree.

Then, if they want more

I add a content hash to the pod template so a config change triggers a normal rolling update. Secrets live in Vault or a cloud secret manager, never in the image or git.

They are mounted by the CSI driver or the External Secrets Operator, or fetched at startup with Spring Cloud Vault or Spring Cloud AWS, and access is granted to the service identity.

For runtime changes I prefer redeploying, because refresh only rebinds some beans: @RefreshScope beans and configuration properties change, but @Value fields in singletons, the DataSource and HTTP clients keep the old values. Things that really must change in seconds go into a feature flag service.

For database credentials I rotate with an overlap: create the new password while the old one still works, deliver it, let HikariCP retire old connections through maxLifetime, then revoke the old password after a period longer than delivery plus maxLifetime. Vault's dynamic database credentials follow the same idea with leases.

Finally, every service binds config with @ConfigurationProperties and @Validated so bad or missing values stop startup, and the rolling update halts before anything breaks.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Design configuration and secrets management for Spring Boot services on Kubernetes...": https://scrivio-interview-library.netlify.app/spring-boot/production-operations/06401f8b37/