Search code examples
javaspring-bootmicroservicesspring-cloud

What is the best way to store constant field in microservice architecture?


Many servers use the same constants, it is necessary to organize a centralized changing them. What is the best way to store constant parameters in microservice architecture.

For example, we store static final int MAX_PEOPLE_COUNT = 100; This field use different microservices. If we change this value, all microservices should see it.

It would be great to have also the versioning of the parameter values.


Solution

  • In case you are in the Spring ecosystem, the best way would be to use the Spring Cloud Config Server. You can readily and easily get the steps to setup a config server in the Spring Cloud Config Server guide and here too. The documentation is pretty much straightforward.

    You can even use Zookeeper as a centralized config service with Spring Cloud. More details on that in this article.