I’ve an elixir and a few other applications in production, static configuration in the form of environment variables has been the norm for a while however most of our configurations now requires to be dynamic, changing environment variables require a restart of the application.
I was wondering if there’s a better way to store configuration in such a way that changes to the configuration can easily be propagated to application, I know of etcd but was wondering if that will fit into elixir.
Secondly I’ve been thinking about using
ets and refreshing the cache from time to time by monitoring my postgres table for changes.
I know postgresql comes with
NOTIFY - how easy will it be to integrate this with
ECTO to achieve dynamic configurations.
I’m a little bit lost from your question. There are more questions here and problematic combination with them.
Yes, you can use ets. Also you can use just GenServer and store it in memory. Some guy from the community create some hex package with nice GenServer logic of configuration, but I can not find it now. But it will work only with your applications, or you will have to change way how your external dependencies/apps load configuration.
You have some information in this post also
Postgrex has support for it https://hexdocs.pm/postgrex/Postgrex.Notifications.html It depends on your use case, you can use this with combination of some cache logic. For example Cachex
But combination of running application configuration with dynamic database data changes can be hight way to hell ( I don’t think it will be so good as this song)
You can use application environment as a “cache” so that should not be a problem. About dynamic configuration per se it depends:
- When is the configuration value read. Some applications (for example
logger) read the configuration only on application startup and changing it afterwards is often more troublesome than just changing application env, some values aren’t changeable at all.
- How often will the configuration value change. For example if you dynamically generate DB connection credentials (for example via Vault) it will be handled differently than for example external service pooling timeouts.
- How quick you need to update the configuration to conform to the external source. Sometimes pooling will be enough, in other cases you will need to listen for the changes.
Of course you can use
NOTIFY from the PostgreSQL, but not always you need to. You can also use Distributed Erlang to distribute configuration changes, you can use Mnesia cluster for that, you can build your own propagation setup, the possibilities are endless there, and it always depend on what and how you want to change your configuration.
To clarify my earlier question, I’m just looking for a way to store configuration that can be propagated to my Elixir app anytime the configuration changes - something around observable pattern.
I outlined my thoughts with respect to possible solutions.
So GenServer if it’s not a lot of data and DB as persistent storage. GenServer’s state is made for it.