The Importance of Single Source of Truth

Alex Rios
3 min readNov 10, 2020

--

There is a joke that goes: “A man with a watch knows what time it is, but a man with two watches is never sure.” Every day, curious and concerned citizens read news articles and blog posts to learn about the real world. Such information has been condensed by journalists or bloggers who have done their due diligence by researching a particular subject. This subject in question, which serves as tangible evidence and which can be cross-referenced by third parties to confirm its authenticity, is what we understand as being a source of truth.

In the computer world, maintaining something as abstract as “truth” is a matter of design practice. For the inexperienced coder, it is possible to find their application referencing information in different places and obtaining inaccurate data as a result. A computer is agnostic about the data that it receives and displays. Thus, it is the duty of the programmer to set fail-safe measures to prevent these unforeseen consequences from happening.

Demonstration

When a customer enters a restaurant, it is possible for them to order several meals. A waiter is responsible for documenting the order and delivering the meal to the customer. Coincidentally, a restaurant can host many customers, with different orders, which will then be fulfilled by many waiters.

In Ruby terms, we would define a class that will contain all the customer instances:

Another class that will contain all the waiter instances:

The orders class will keep track of all the order instances:

It is through the orders class where we can establish a connection between waiters and customers. An instance of the order class gets initialized with a customer, a waiter, and the meal total. All the new order instances get collected into a class array.

With the orders class, a restaurant is able to keep a tally of the interactions between any customer and waiter, as well as the monetary earnings in any given day. It is safe to say that, in this application, we can establish that our orders class is the single source of truth.

With this in mind, we can use the orders class to access any number of orders that a customer instance has made, a well as a list of all the waiters that have attended said customer.

Similarly, a waiter instance can use the orders class to select the number of orders that the they have fulfilled, as well as obtain a list of all the customers that they have served.

Sources:

--

--