Hi all,

This email presents my findings related to configuration packages in Golang
for the Apache Synapse project.

I've been exploring various libraries for managing configurations from
diverse sources and formats. I evaluated several options, including the
widely used spf13/viper <https://github.com/spf13/viper>, go-ini/ini
<https://github.com/go-ini/ini>, and  knadh/koanf
<https://github.com/knadh/koanf>.

After careful consideration and extensive evaluation, I propose adopting
the knadh/koanf <https://github.com/knadh/koanf> package as our primary
configuration management solution.

My primary reason for initially highlighting knadh/koanf over spf13/viper
stemmed from its superior build size efficiency. knadh/koanf significantly
reduces build sizes by minimizing unnecessary dependencies. This is a
crucial factor for our project, as it leads to smaller binaries, faster
deployment times, and reduced resource consumption. However, after further
investigation, I found that knadh/koanf addresses other limitations I
encountered not only with spf13/viper, but also with other libraries, such
as go-ini/ini, which lacks the ability to merge configurations from
multiple sources and live reloading.

To provide a more comprehensive comparison, I've outlined the key
differences between spf13/viper, go-ini/ini, and knadh/koanf in the table
below:
Feature/Metric spf13/viper go-ini/ini knadh/koanf Explanation/Benefit of
koanf
Build Size/Dependencies Larger, more dependencies Relatively small, but
limited functionality Smaller, fewer dependencies Core Benefit:
Significantly smaller binaries, faster deployments, reduced resource usage.
Configuration Sources Wide range (files, env vars, remote, etc.) Primarily
INI files Wide range (files, env vars, remote, etc.) Both viper and koanf
support common sources, but koanf's modularity allows for only the needed
providers. go-ini/ini is limited.
Configuration Formats YAML, JSON, TOML, INI, etc. INI YAML, JSON, TOML,
INI, etc. Both viper and koanf support common formats. go-ini/ini is
limited to INI.
Live Reloading (Watch) Limited/Requires External Libraries in some cases No
built in support. Built-in Watch() for many providers Key Benefit: Dynamic
configuration updates without restarts (e.g., log levels, feature flags).
go-ini/ini lacks this feature.
Simplicity/API Feature-rich, but can be complex Simple API, but limited
functionality Simpler, more focused API Easier to learn, use, and maintain,
especially for simpler configuration needs. go-ini/ini is simple, but lacks
features.
Performance Generally good, but can be slower due to overhead Relatively
fast, but limited use cases. Optimized for speed and minimal overhead Faster
configuration loading and access, especially important for high-performance
applications.
Extensibility Plugins/Customization possible, but can be complex Limited
extensibility Highly extensible through pluggable providers Key Benefit:
Modular design allows for easier integration of custom configuration
sources and formats.
Error Handling Can be verbose and sometimes complex Basic error handling More
straightforward and predictable Easier to debug and handle
configuration-related issues.
Community/Maturity Mature, widely used Mature, but specific use case Growing,
but still relatively newer Viper has a larger community, but koanf's design
offers significant advantages. go-ini/ini is mature, but for a specific use
case.
Use Cases General-purpose configuration management Primarily INI file
parsing Performance-sensitive, embedded, or microservice applications koanf
is better suited for resource-constrained environments and general purpose
use.
Code Structure Monolithic Simple, but limited Modular Allows for a more
maintainable code base.

As you can see, while spf13/viper is a mature and widely used library, and
go-ini/ini is excellent for simple INI files, knadh/koanf offers several
key advantages, particularly in terms of build size efficiency, live
reloading, simplicity, and performance. Its modular design allows for
greater flexibility and extensibility, making it an ideal choice for Apache
Synapse's configuration management needs.

I welcome your feedback and discussion on this proposal.

Thank you for your time and consideration.

Sincerely,

Thisara Weerakoon

Reply via email to