Designing a library for reading layered application settings in Java

Photo: Clock mechanism
“Photo by Sigmund on Unsplash

The first version

  • if a prop is required or optional
  • if it has a default value
  • if it represents a secret (in which case extra care needs to be taken)
  • a description of what the property is used for, aiding with documentation

The architectural problem

How would a better implementation look like?

Glossary of terms

  • source: where a key=value pair originates from
  • prop: an object that can return a type cast value for its registered key
  • registry: an object that keeps track of all sources and props
  • layers: a mechanism that helps to establish the priority in which sources own a particular key
  • effective value: the final value of a key, taken from the source that owns it

Design considerations

var prop1 = new StringProp("my.key");
var prop2 = new StringProp("my.key");
var prop1 = new DurationProp("my.key");
var prop2 = new LongProp("my.key");
var prop3 = new StringProp("my.key");
var prop = new DurationProp("my.key");
Duration result = prop.get();
Long seconds = result.toSeconds();
String stringValue = result.toString();
  • effectively deal with ownership transitions in quick succession
  • flag when this behavior occurs so that a human operator can investigate the correctness

Conclusion

  • setting up a GitHub repository
  • configuring a build system
  • configuring a CI/CD pipeline
  • writing performant, well-tested code
  • pushing releases to a public Maven repo (e.g., Maven Central)
  • formatting the code to a common standard
  • linting the code
  • benchmarking and documenting a performance baseline
  • and others

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mihai Bojin

Mihai Bojin

164 Followers

Software Engineer at heart, Manager by day, Indie Hacker at night. Writing about DevOps, Software engineering, and Cloud computing. Opinions my own.