Kim Lindhard
Making the implicit explicit

Where to store static data

Many systems make use of data that doesn’t change very often, maybe once every 5 years, once a year or once a month; this data is referred to as static data. We can store this data in many ways, depending on our needs and the tradeoffs we are willing to accept. The following decision tree illustrates a very simple approach to placing your static data in the most optimal place in your system.

Where to store static data

Independent service

Build either a single service for static data or a service for each type of static data you have to get a single source of truth that consumers can query.

Advantages

Drawbacks

Configuration files

Create configuration files that can be loaded into the services that contain your static data.

Advantages

Drawbacks

Shared library

Place the static data in a library that can be linked by any assembly needing the data. The library can be distributed via a package manager like Npm, Yarn or NuGet.

This works well if you have small volumes of data and you can live with different assemblies having different versions of the data.

Advantage

   The package manager will make the version of the static data each assembly visible.

Drawbacks

Duplicate code

Write the static data as code in each assembly that needs access to it. Copy/paste between each solution in the same programming language.

Advantages

Drawbacks

Conclusion

None of the described patterns fit every case; they each come with advantages and drawback, I suggest you focus on how often the data changes and how many places it will be used when making a decision on what pattern to use when storing static data.

Source

The patterns described above comes from Sam Newman’s excellent book Monolith to Microservices where he goes deeper into the pros and cons of each pattern plus another pattern (shared schema) to solve the challenge. He addresses a lot of issues we face when transforming monolith systems into microservices.