Using feature flags
A feature flag is a technique to enable or disable certain functionalities in code during runtime without deploying new code. This helps developers to toggle different features in production at a much faster rate. For example, if a company has incorporated Stripe and PayPal payment gateways for payments in their app, but for some reason Stripe is down, then the team can quickly change their payment gateway to PayPal without any code change or deployment. This is very common for critical systems and also while building new systems.
In the following example code, we are storing the payment gateway configuration in our KeyValueStore
database table. This helps us to control the payment gateway at runtime. KeyValueStore
is a database model that is stored in the common/models.py
file:
class KeyValueStore(models.Model): key = models.CharField(max_length=255, unique=True) value = models.JSONField() ...