Link Search Menu Expand Document

Have admin editable platform settings from the start

Don't only avoid magic numbers but avoid constants entirely.

Magic numbers are bad

There are bound to be a lot of magic numbers that control various aspects of how the application functions. They might control the number of categories that are to be shown in the top bar or how many hours to wait before the admin is alerted that an order is still unfulfilled.

They’ll probably be organized neatly into constants.

As the application grows, the number of these constants grows with it.

But constants are bad too

As different parts of the application are being experimented on, the constants will have to be adjusted. They will have to be changed in code and deployed.

For people who understand and decide on these numbers, having to request these changes becomes a chore and prevents them from making quick experimental changes.

For instance, they might want to experiment on order duration just within the next week’s promotional period.

So, make them application settings instead

Therefore it’s beneficial to give control of magic numbers to users who are most affected by them. It makes their work easier and quicker and frees up dev time.

You create a page that has all the editable settings where each entry might look like this:

You assign permissions to users that give them access to groups of settings. For instance, “can change buyer side settings”. As you evolve, you can create more detailed permissions.

Having settings, instead of constants, helps the tech team as well. Consider a constant that controls how many push notifications can be sent at once. Firebase used to allow only 500 messages at once but now allows 1000. A constant would require a deployment, but a setting could be immediately changed.

But make sure to cache them

A potential issue with this is that the settings have to be kept in a database. It would be very inefficient if every page load needed to hit the database to load settings. Instead, these settings must be kept in memory. You can roll a custom solution easily, but a lot of frameworks have existing plugins for this. Rails, for instance, has the Rails Settings Cached gem.

Related Lessons


Suggest an improvement to this page (me@ognjen.io)