Skip to main content

What does the term "single source of truth" mean?

"Single source of truth" is a principle where certain data is stored in only one place, and every part of the application reads from exactly that place.


Why it's needed:

  • So there are no discrepancies between different copies of the same data.
  • So that all updates are centralized and controlled.
  • To make the application easier to debug and maintain.

Example:

If the user is stored in a component, in a service, and in local storage, sooner or later you will forget to update one of them. But if the entire user object is stored only in AuthService.user$, and every component reads from there alone, everything stays under control.


In Angular:

  • A BehaviorSubject in a service is a common "single source of truth"
  • The Store in NgRx is a global, formal single source of truth for the whole application

Conclusion: A single source of truth is the one place where the real data lives, and everything else just looks there. That means fewer bugs and more predictability.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.