0

I have a spring boot rest service where configuration values are stored in git and fetched using a config server. Deployment is done in a docker swarm cluster where this service would run across multiple containers. So one thing I had to keep in mind is that when actuator's refresh endpoint is called, it refreshes all the containers for this service seamlessly and not just any random container. This is quite an obvious ask I believe.

I can implement updating the config values for a service as and when it's config changes in git using a message broker. However, that would take time and time is not with me at the moment.

I have come up with two quick solutions and would like your help based on your experience as to which one is better than the other. Keep in mind that both work and I tested them both.

Solution 1 Create a scheduler using @Scheduled in the Application.java and keep pinging actuator's refresh endpoint every 5 seconds. I think this is really expensive and resource intensive in production.

Solution 2 Call actuator's refresh endpoint in the controller method itself. This way, I called refresh endpoint on demand and don't keep polling it like solution 1 and be wasteful. It will also ensure that whatever container is picked for servicing a request, it refreshes itself as refresh endpoint call would refresh the properties referred by that container only.

Do you have any preference on one over the other ? Do you see any pros and cons with these solutions ? which one would you pick and why ?

Please let me know what your thoughts are.

Hary
  • 1,127
  • 4
  • 24
  • 51
  • you could have a look at [spring-cloud-configuration](https://cloud.spring.io/spring-cloud-config/) – Dirk Deyne May 01 '18 at 12:39
  • How exactly is that solving my use case ? – Hary May 01 '18 at 13:10
  • "Spring Cloud Config provides server and client-side support for externalized configuration in a distributed system." Isn't that what you try to achieve? – Dirk Deyne May 01 '18 at 13:38
  • Yes and no. Major part of the problem is a service running in multiple containers. So every container needs to be refreshed which doesn't happen out of the box using spring cloud. Having said that, if you read my post carefully, I am using spring cloud. However, I need someone who is an expert on this to weigh my 2 implementations that satisfy the need of refreshing every container for that service – Hary May 01 '18 at 15:05

1 Answers1

0

This sounds like an interesting problem. Also, like you pointed out Solution1 is resource intensive and should not be used in production. If you are running out of time, I would suggest you go ahead with Solution2, its smarter than the prior.

However, I think the optimal way to solve this problem can be using webhooks in github. This way github will make an API call to your predefined endpoint when a specific event is generated. Events are the core of Github Webhooks. Here is the list of all github events. Choose the one that best suits your requirement. https://developer.github.com/webhooks/#events

Pranjal Gore
  • 532
  • 5
  • 14