top of page

Hash Collisions in Data Vault: How to Check for Them and What to Do

Writer: Rhys Hanscombe
Rhys Hanscombe
11 minutes ago
4 min read

Data Vault 2.0 joins its tables on hash keys. You hash each business key once in staging, and every hub, link and satellite joins on the result. Each table can then load on its own. Then someone in a design review asks: what if two keys give the same hash?


A member brought that worry to the Data Community forum. The thread has been viewed close to 2,900 times.


The problem: two keys, one hash

The member gave a simple case. Customer 123 and customer 456 come out with the same hash key, even with SHA-256. Now two customers share one hub row, and their history mixes. How do you spot it, and how do you fix it?


What members recommend


Keep the risk in proportion

The first reply was calm. A collision on a business key hash is very unlikely. One member compared the odds to a meteor striking two data centers at once. The same member later pointed out that the known MD5 and SHA-1 collisions came from crafted inputs, such as images. Business keys look nothing like that.


The AutomateDV docs give a rough line. Once a table holds more than a few billion rows, there is a chance of a clash. The docs add that the SHA options can lower that risk on large data sets.


Choose your hash and stick to it

Pick the algorithm before you build. One member uses SHA-256. Another warned that SHA-2 costs more compute on very large loads. Whatever you pick, use it everywhere. Changing it later means reloading the vault.


Treat business keys before you hash

A member checked that the original poster had trimmed keys and stripped spaces first. A stray space gives the same key a second hash, so tidy keys the same way every time. A common routine is to:

  1. Turn the key into text, so 1001 and "1001" give the same hash.

  2. Trim spaces.

  3. Change it to upper case.

  4. Turn empty strings into nulls.

  5. Join the parts of a multi-part key with a fixed separator.


Check for collisions on a schedule

A long-time member described two kinds of check:

  • Before the load. Compare each new pair of hash key and business key with what is loaded. Also look for one business key with two hash keys in staging.

  • After the load. From time to time, test that you can rebuild the source from the vault.


He suggested running them during a build's warranty period.


Have a fix ready

Another member pointed to the approach in Dan Linstedt's Data Vault 2.0 book. If a collision appears, reverse the business key and hash that instead. "ABC123" becomes "321CBA", which gives a new hash. Add a flag column to the hub so you know which rows used the reversed key. Staging can work out both hashes up front, so the fix is ready if you need it.


Or skip hashing

One member argued for not hashing at all. Cast the business key to binary and join on that. There are no collisions, it often takes less space, and it needs less compute. The trade-off is that your join keys vary in length.


A simple way to apply it

  1. Pick one algorithm for the whole vault. Note the choice and the reason.

  2. Standardize keys before hashing. Use the same routine in every staging model.

  3. Add a collision check. Join new staging rows to the hub on hash key where the business keys differ. Alert on any match.

  4. Plan the fix. Agree now whether you would reverse and rehash, or switch a hub to binary keys.

  5. Log it if it happens. One member's advice was to document it and publish what you find.


Using AutomateDV? It uses MD5 by default. You can switch to SHA-1 or SHA-256 with one setting. It also trims, upper-cases and casts keys before hashing, and stores the result as binary. See the hashing guide.


Frequently asked questions


Can SHA-256 hash keys collide in Data Vault?

In theory, yes. Members of the Data Community forum see it as very unlikely for business keys. The AutomateDV docs say the chance of a clash appears once a table holds more than a few billion rows.


How do you detect a hash collision?

Join new staging rows to the hub on the hash key and look for rows where the business keys differ. You can also check that each business key in staging has only one hash key.


What should you do if a hash collision happens?

One option from the Data Vault 2.0 book is to hash the reversed business key for the clashing row and flag it in the hub. Another is to use the business key itself, cast to binary, as the join key.


Join the conversation

This post sums up a real thread on the Data Community forum. Read the full thread to see the full debate.

Data Community has more than 4,000 members. It has run since 2018, with monthly meetups and a forum where members share what works on real builds.

Join Data Community and join the forum to ask the questions your design reviews raise.

bottom of page