Sobes.tech
Senior

Tarrifs are embedded in the code. How can you change or add tariffs without modifying the code and redeploying?

sobes.tech AI

Answer from AI

To modify or add tariffs without changing code and deploying, you can move them to configuration files or external data sources. For example:

  • Store tariffs in a database and load them dynamically at application startup or on demand.
  • Use configuration files (JSON, YAML) that can be changed without recompilation.
  • Connect to a configuration management system or feature flags.

Example of loading tariffs from a JSON file:

class TariffService {
    private Map<String, Tariff> tariffs;

    public void loadTariffs() throws IOException {
        ObjectMapper mapper = new ObjectMapper();
        tariffs = mapper.readValue(new File("tariffs.json"), new TypeReference<>() {});
    }

    public Tariff getTariff(String id) {
        return tariffs.get(id);
    }
}

Thus, to change a tariff, simply update the tariffs.json file without recompilation and deployment.