7. Use a Single Source of Truth
Storing the same data in multiple places breeds bugs. Why one source of truth — often the URL — keeps your app clean, predictable and shareable.

A common problem in software development is storing the same information in multiple places — which inevitably leads to inconsistencies. The data gets out of sync, causing strange behavior and hard-to-track bugs.
Keeping data in sync across an application is tricky. What source should be leading? What happens if data is unexpectedly updated in one place but not the other? How do you prevent infinite loops when changes automatically trigger updates elsewhere?
🧠 The solution: Use a Single Source of Truth.
Make sure there's only one place where a specific piece of information lives. Everywhere else, just refer to that single source. It keeps things clean, predictable, and bug-free.
📦 A simple example
Let's say you have a component that loads an image. It can be in one of several states:
idleloadingloadederror
You could track this using four separate booleans: isIdle, isLoading, isLoaded, hasError. But that easily leads to contradictory states — like isLoading and isLoaded both being true because you forgot to update one of them.
✅ A better approach is to use a single status variable with a clear value like "idle", "loading", "loaded", or "error". All other values are derived using getters.
This way, you only need to update one value (status) — and the rest of your application can safely rely on the derived getters.
🌐 The URL as the ultimate source
In large applications, things get more complex. A single variable often won't cut it. That's when state management libraries come in — and they're great. But even then, choose one source to be the truth.
In web apps, my favorite Single Source of Truth is: the URL.
Whenever possible, I try to store state in the URL. It offers several great options:
/post/1234→ the opened post/products/sneakers→ the selected category/search?query=term→ the search term
💡 Benefits:
- You can deep link to specific states
- Users can bookmark or share them
- No session required
- State survives page refresh
- Better SEO
- The browser's history and back button work by default
- And: very handy during development!
But here's the key: make sure the URL is leading. Let your application respond to changes in the URL — not the other way around.
So when navigating within your app, only update the URL, and let everything else follow from that. It simplifies your architecture and improves the user experience.
🔄 Beyond the code
Single Source of Truth isn't just for your codebase.
I've seen plenty of projects where the ticketing system, UX docs, design files, and copy docs all said different things. Nobody knew which one was correct.
So: agree on which source is leading for what information. Always refer to that source — and make sure it's kept up to date.
🚀 TL;DR
- Choose one source for your data
- Reference it everywhere else
- Save yourself (and your team) a lot of frustration
📌 This is part of my weekly series, Developers Tiles of Wisdom. Follow me for more insights on writing better code and building better teams.
What's your experience with having (or missing) a Single Source of Truth? Ever had to clean up a project that got out of hand?
👇 I'd love to hear your story or your favorite solution to this.
Need help setting up a solid architecture for your application? I'd be happy to help — just reach out.


