Spring Cloud Config Refresh Interview Questions and Answers
Master Spring Cloud Config Refresh with interview questions covering @RefreshScope, Spring Cloud Bus, Actuator Refresh, runtime configuration updates, Kafka, RabbitMQ, refresh events, and production best practices.
Spring Cloud Config Refresh Interview Questions and Answers
Introduction
One of the biggest challenges in enterprise applications is changing configuration without restarting services.
For example:
- Increase logging level
- Change feature flags
- Update API endpoints
- Modify timeout values
- Enable maintenance mode
- Update business rules
Without Config Refresh, every configuration change requires:
- Restarting services
- Downtime
- Rolling deployments
- Possible service interruptions
Spring Cloud provides runtime configuration refresh, allowing applications to pick up new configuration dynamically.
The major components are:
- Spring Cloud Config Server
@RefreshScope- Spring Cloud Bus
- Kafka/RabbitMQ
- Spring Boot Actuator
Config Refresh Architecture
flowchart LR
GitRepository --> ConfigServer
ConfigServer --> CustomerService
ConfigServer --> PaymentService
ConfigServer --> LoanService
SpringCloudBus --> Kafka
Kafka --> CustomerService
Kafka --> PaymentService
Kafka --> LoanService
Q1. What is Config Refresh?
Answer
Config Refresh allows a Spring Boot application to reload configuration without restarting.
Benefits
- Zero downtime
- Faster updates
- Dynamic feature toggles
- Improved operational flexibility
Typical use cases
- Logging level updates
- Feature flags
- Timeout changes
- External API URLs
Q2. Why do we need Config Refresh?
Without Config Refresh
flowchart LR
ConfigurationChange --> RestartService
RestartService --> Downtime
With Config Refresh
flowchart LR
ConfigurationChange --> RefreshEvent
RefreshEvent --> UpdatedConfiguration
Applications continue serving requests while configuration is updated.
Q3. What is @RefreshScope?
@RefreshScope tells Spring to recreate a bean whenever configuration changes.
Example
@RefreshScope
@RestController
public class
ConfigController{
}
Only beans annotated with @RefreshScope are recreated during a refresh.
Q4. How does Config Refresh work?
Refresh Process
- Configuration changes in Git.
- Config Server loads updated configuration.
- Refresh event is triggered.
- Spring recreates
@RefreshScopebeans. - Updated values become available.
Refresh Flow
sequenceDiagram
Developer->>Git: Commit Configuration
Git->>Config Server: Updated File
Config Server-->>Application: Refresh Event
Application->>RefreshScope Bean: Recreate Bean
Bean-->>Application: Updated Configuration
Q5. What is /actuator/refresh?
Spring Boot Actuator exposes a refresh endpoint.
Example
POST
/actuator/refresh
This endpoint
- Reloads configuration
- Recreates
@RefreshScopebeans - Applies updated values
For security reasons, it should not be publicly exposed.
Q6. What is Spring Cloud Bus?
Spring Cloud Bus distributes configuration changes across multiple services.
Supported message brokers
- Kafka
- RabbitMQ
Instead of refreshing every service manually,
one refresh event updates the entire system.
Bus Architecture
flowchart LR
ConfigServer --> SpringCloudBus
SpringCloudBus --> Kafka
Kafka --> CustomerService
Kafka --> PaymentService
Kafka --> LoanService
Q7. How does Spring Cloud Bus work?
Workflow
- Configuration changes in Git.
- Refresh endpoint is called.
- Config Server publishes a refresh event.
- Kafka/RabbitMQ broadcasts the event.
- Every service refreshes automatically.
Event Flow
sequenceDiagram
Developer->>Git: Commit
Developer->>Config Server: Refresh
Config Server->>Kafka: Publish Refresh Event
Kafka->>Customer Service: Refresh
Kafka->>Payment Service: Refresh
Kafka->>Loan Service: Refresh
Q8. Which properties can be refreshed?
Refreshable examples
- Logging levels
- Feature flags
- Business limits
- API URLs
- Timeout values
- Cache duration
Not refreshable
- Server Port
- JVM Heap Size
- Bean Definitions
- Application Dependencies
These require application restart.
Q9. What are common production challenges?
Possible issues
- Refresh storms
- Refresh failures
- Message broker downtime
- Bean recreation delays
- Configuration inconsistency
Solutions
- High Availability Kafka
- Retry mechanisms
- Monitoring refresh events
- Secure Actuator endpoints
Q10. Config Refresh Best Practices
Use Git for Configuration
Maintain version history.
Secure Refresh Endpoints
Protect Actuator endpoints with Spring Security.
Use Spring Cloud Bus
Avoid manual refresh on every service.
Refresh Only Required Beans
Use @RefreshScope selectively.
Monitor Refresh Events
Track successful and failed refresh operations.
Banking Example
flowchart TD
GitRepository --> ConfigServer
ConfigServer --> SpringCloudBus
SpringCloudBus --> Kafka
Kafka --> CustomerService
Kafka --> PaymentService
Kafka --> LoanService
CustomerService --> UpdatedConfiguration
PaymentService --> UpdatedConfiguration
A single configuration change updates all services without restarting them.
Common Interview Questions
- What is Config Refresh?
- What is
@RefreshScope? - How does Config Refresh work?
- What is
/actuator/refresh? - What is Spring Cloud Bus?
- Why use Kafka with Config Refresh?
- Which properties can be refreshed?
- What cannot be refreshed?
- Production challenges?
- Config Refresh best practices?
Quick Revision
| Topic | Summary |
|---|---|
| Config Refresh | Reload configuration at runtime |
| @RefreshScope | Recreate bean after refresh |
| Actuator Refresh | Trigger configuration reload |
| Spring Cloud Bus | Broadcast refresh events |
| Kafka | Distributed refresh messaging |
| RabbitMQ | Alternative message broker |
| Git | Configuration source |
| Refresh Event | Notify services |
| Dynamic Config | Update without restart |
| Secure Endpoints | Protect refresh APIs |
Config Refresh Lifecycle
sequenceDiagram
Developer->>Git Repository: Commit Configuration
Git Repository->>Config Server: Updated Files
Administrator->>Actuator: POST /refresh
Actuator->>Spring Cloud Bus: Publish Event
Spring Cloud Bus->>Kafka: Broadcast Event
Kafka->>Customer Service: Refresh Bean
Kafka->>Payment Service: Refresh Bean
Kafka->>Loan Service: Refresh Bean
Services-->>Users: Updated Configuration
Production Example – Banking Payment Platform
A banking platform needs to increase the payment timeout from 5 seconds to 10 seconds during peak traffic.
Traditional Approach
- Update configuration.
- Restart every service.
- Perform rolling deployment.
- Risk temporary service disruption.
Spring Cloud Refresh Approach
- Configuration updated in Git.
- Config Server loads the new value.
- Administrator triggers a refresh event.
- Spring Cloud Bus publishes the event through Kafka.
- Every Payment Service instance refreshes its
@RefreshScopebeans. - New requests immediately use the updated timeout without restarting the application.
flowchart LR
GitRepository --> ConfigServer
ConfigServer --> SpringCloudBus
SpringCloudBus --> Kafka
Kafka --> PaymentService1
Kafka --> PaymentService2
Kafka --> PaymentService3
PaymentService1 --> UpdatedTimeout
PaymentService2 --> UpdatedTimeout
PaymentService3 --> UpdatedTimeout
This architecture enables zero-downtime configuration updates across all running microservices.
Key Takeaways
- Spring Cloud Config Refresh allows applications to apply configuration changes without restarting.
@RefreshScoperecreates beans so they use updated configuration values.- The
/actuator/refreshendpoint triggers runtime configuration reloads and should be secured in production. - Spring Cloud Bus distributes refresh events across multiple services using Kafka or RabbitMQ.
- Configuration changes stored in Git can be propagated automatically throughout the microservice ecosystem.
- Runtime-refreshable properties include logging levels, feature flags, timeout values, and external endpoints, while server ports and JVM settings require a restart.
- Refresh events should be monitored and secured to avoid accidental or malicious configuration changes.
- Config Refresh improves operational efficiency, reduces downtime, and simplifies configuration management in enterprise Spring Cloud applications.