Spring Cloud Config — Part 1

Ritesh Panigrahi
3 min readJul 24, 2021

--

In this article, we will understand

  1. What is Spring Cloud Config?
  2. Its 2 components — Config Server and Client.
  3. Why do we need a Config Server?

In Part 2, we will implement all this knowledge acquired in this article.

What is Spring Cloud Config?

Spring Cloud Config provides server-side and client-side support for externalized configuration in a distributed system. With the Config Server, you have a central place to manage external properties for applications across all environments.

Not clear with the definition?

Let us take an example. Suppose you are working on a project that currently has 3 different microservices A, B, and C, there is no such thing called Spring Cloud Config till now, and everything is working fine.

One fine day there comes a requirement that we need to change the database username for all the services from USERX to USERY.

So what we will do, update the application. properties or application.yml for each of the microservice and build all the 3 services again and deploy them to a specific environment.

Isn’t it an inefficient task to build all the 3 services for just some property change? Spring Cloud Config Server is the one that solves this problem.

We will create another microservice that will take care of all the configurations for all the other services, whenever required that service is generally called Spring Cloud Config Server.

So, till now what we have seen is Spring Cloud Config has 2 components:-

  1. Spring Cloud Config Server (It will provide properties to all other services. We will understand in detail further)
  2. Spring Cloud Config Client (All the other microservices which require properties from the config server will be the clients)

Now comes the question of how does config service( Spring Cloud Config Server) get the properties for all other services?

Spring Cloud Config Server can get the properties for all services either from any database or any of the version control systems (GIT).

So we can just create a git repository and place the properties files for all the services.

Now, whenever there is a need to change properties for one or more services we need to just push the changes to the git repository and Spring Cloud Config Server will always look at the git repository to get the configs.

Now again there might be a question - Since we are changing the code (in the git repository which Spring Cloud Config Server is looking) don’t we have to build?

First of all the git repository only contains properties file for each service so there is no point of build for that repository.

(Note we have not changed the code of Spring Cloud Config Server, but for the git repository which contains the properties)

Flow diagram

This was it for this article, I hope you might have got a basic understanding of Spring Cloud Config and Config Server.

In the next article, we will practically understand all the concepts my creating a Git-backed config server and another simple service which will act as a client.

Thanks for reading..!!

Happy Learning.

Do mention in comments, if you have any doubts.

--

--