I have some data (list of parameters) that should be shared across the backend and the frontend. The changes are really infrequent, and changes usually mean a redeploy. Currently, it is stored in the DB, some tables have foreign keys on it. By extending the functionality we had to keep adding new and new properties on these objects, to be able to filter on a certain set of them. Since these properties are often overlapping, it is a huge mess now. Recently I had the idea of storing these params in a language independent descriptor file (JSON/toml/yaml) in a separate repository, and distribute a js module for the frontend and a python module for the backend from this configuration. The parameters can be added to lists, so the problem of the overlapping properties would be solved, I could just add them to lists in the descriptor file. The foreign key is not really a big deal, the DB querying can be done with a text/enum field. The only thing is that the related entries won't be removed, a custom migration needed.

Benefits: - Fewer requests from the client - I think it'd be easier to store and group them

Drawbacks: - Perhaps it'd be a bit harder to understand how this thing works and what changes have to be made to extend this functionality.

Since things go in the other direction usually (people move stuff to the DB instead of removing from there), I'd like to ask if anyone did something similar and if it is a good idea or not?

I think it is irrelevant, but the frontend is written in Angular 1.x and the backend is Django + Python.


I would move away from DB storage if only because if you have a yaml/json configuration file in your project, it isn't obvious that they can and will be regenerated completely in future versions. It only adds confusion ultimately. Alternatively, drop the project local yaml/json configurations in favor for only DB storage.

The project should have a single obvious source for the configuration, whether that be the DB or local yaml/json file or even a yaml/json file in a separate repository. If anything, when the project starts up, it can perform optimization logic first time around, such as generating a yaml file from the database upon runtime or generating a json frontend version of the yaml backend configuration. Better still if you can use only json that can potentially work both backend and frontend with no added changes.

Otherwise, the risk is that a developer adds a new feature in your program which depends on a new configuration that the developer added to the local yaml/json configuration within the project. It works until you regenerate the configuration file and send it to production and then it doesn't. ;)

In other words, there should be only one persistent copy of the configuration saved to the repository or saved on the database, but not more than one to avoid confusion. From there you can choose to optimize a local configuration if one isn't found first time the program runs if you like.

Hope that helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.