Search code examples
software-design

Keep business variables which should define by admin


I have multi-vendor project which some variables should set by admin, For instance when User wants to pay his/her cart, fee should be specify and it defined by admin of system. (And it could be change passing of time.) So what's the best approach for keeping this variables?

Note:
I'm running server with Nodejs and I use MongoDB as database.

I have following ideas which has pros and cons in my opinion:

  • Save these variables in document (in database), which I guess it's not good since I have to for each payment (or other actions which need these variables) send request to database. These variables seems to be fixed and can change after a while. I mean it's not like a user profile information which could change frequently and when user wants to see his/her profile request should send to database. (further more it's just seems not good create new collection for storing just a document)
  • Save this in .env file (as environment variables) and I think we keep configuration variables in this file (application layer, not keeping the variables for business) and also updating this file is not good as database.

Please aware me if I make a mistake or there is common way which I don't know. (Also I searched for that and I couldn't find any proper keyword : ( )


Solution

  • My approach has been the following:

    • If the values can be updated by business administrator in normal course of operation - then they should have Admin UI and be stored in the database. Fees are a good example.

    • If the values hardly ever change; or changed by IT staff - put them in the configuration file. Endpoint of Vendor API, or mail server configuration would go there.