WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

RESTful Web Services · Advanced · question 58 of 100

What is the role of the Config Server in microservices architecture?

📕 Buy this interview preparation book: 100 RESTful Web Services questions & answers — PDF + EPUB for $5

In microservices architecture, configuration management can be a complex task as the number of services and instances increase. The Config Server is a component of the Spring Cloud framework that provides centralized configuration management for microservices-based applications.

The Config Server stores the configuration of all services in a centralized location, which can be versioned and backed up. Each service can then access its configuration from the Config Server, instead of managing its own configuration files. The Config Server uses Git as the default source for configuration files, but other sources like databases and file systems can also be used.

The Config Server also supports dynamic configuration updates, which means that services can dynamically refresh their configuration without restarting. This allows for more flexible and dynamic configuration management in a microservices architecture.

Here’s an example of how to configure a service to use the Config Server in Spring Boot:

    @SpringBootApplication
    @EnableDiscoveryClient
    @EnableConfigServer
    public class ConfigServerApplication {
        
        public static void main(String[] args) {
            SpringApplication.run(ConfigServerApplication.class, args);
        }
    }

In this example, the @EnableConfigServer annotation enables the Config Server in the Spring Boot application. The @EnableDiscoveryClient annotation enables the service to register with a service registry like Eureka, which is often used in microservices architecture.

To access the configuration from the Config Server, a service can use the Spring Cloud Config Client, which provides a REST API to retrieve configuration properties. Here’s an example of how to use the Config Client in Spring Boot:

    @SpringBootApplication
    @RestController
    public class MyServiceApplication {
        
        @Autowired
        private ConfigurableApplicationContext context;
        
        @GetMapping("/config")
        public String getConfig() {
            String myProperty = context.getEnvironment().getProperty("my.property");
            return "My property value is: " + myProperty;
        }
    }

In this example, the ConfigurableApplicationContext is injected into the service, which allows access to the configuration properties. The getProperty method is used to retrieve a specific property, which in this case is my.property.

Overall, the Config Server plays an important role in managing configuration in a microservices architecture, providing a centralized location for configuration and dynamic updates to improve flexibility and scalability.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic RESTful Web Services interview — then scores it.
📞 Practice RESTful Web Services — free 15 min
📕 Buy this interview preparation book: 100 RESTful Web Services questions & answers — PDF + EPUB for $5

All 100 RESTful Web Services questions · All topics