Video in progress

Reference data like currency rates, tariffs and the list of branches is needed by dozens of services. Where do you store it and how do you distribute it?

Each reference dataset has a single owner who writes and versions it. The others don't call it synchronously on every request; they take it through events or a snapshot and keep a local copy. What matters: when a change takes effect (an effective date) and which version a calculation used are recorded.

📖 Answer

Three common mistakes:

  • every service maintains the reference data by hand in its own application.yml or DB: a month later, 5 services have 5 different tariffs;
  • every service calls reference-service on every request: if it goes down, the whole system goes down, even though the data changes once a day;
  • hardcoding in a shared library: redeploying 20 services for a tariff change.

This is how I build it:

  1. The owner. Currency rates belong to treasury, tariffs to pricing, branches to branch-registry. Each provides its own reference data through an API and events. A shared "reference-service" is only for data that truly has no owner and is simple (like a list of countries).

  2. Distribution. A change is written to a compacted Kafka topic (the key is the tariff code). On startup, a consumer reads the topic from the beginning, loads a full copy into memory or a local table, then receives changes. Even if the owner goes down, consumers keep working with the last known version. For small, rarely changing data, a simpler option is a versioned snapshot (JSON in object storage or an API with an ETag) and periodic refresh.

  3. Versioning by time. A tariff changes tomorrow at 00:00. If services apply the change the moment it arrives, for a few seconds around midnight different services calculate with different tariffs. So the record carries validFrom/validTo, and the service takes "the tariff for that date", while the change itself can be distributed in advance.

record Tariff(String code, BigDecimal rate, Instant validFrom, Instant validTo, long version) {}
  1. Leaving a trail. A calculation result stores which tariff version it was made with (tariffVersion = 17). That is the answer to "why was this customer charged this much?".

  2. Quality. A wrong change to reference data (a rate with a misplaced decimal point) breaks the whole system instantly. So changes follow a four-eyes principle, with validation (a warning if the rate differs from yesterday's by more than 20%) and fast rollback.

For money-related data like currency rates, there is one more question: how long may a consumer work with a stale copy? If the limit is exceeded (say the rate is more than 1 hour old), halting the operation may be safer than continuing with a stale rate.