Let’s take a closer look at your employeeNumber
example. What does “unique” mean?
First, let’s assume you have two companies, each with one (distinct) employee. Is there any reason they couldn’t both say this is employee #1? I’d say no. In that sense, employeeNumber
on its own is not unique. From a “global” perspective, there is no uniqueness requirement.
Now, if you have two employees in the same company, you do want them to have different numbers. So from the perspective of a given company, employeeNumber
must be unique.
Say you’re a part-time worker. You work for two companies. Is it a problem if you get issued the same number in both? Would you report it? As the employee, you know of both companies. From the perspective of the employee, employeeNumber
does not need to be unique.
So here’s one way to think of the maintainer: it’s the perspective from which the key must be unique.
Now let’s assume we have four companies (A, B, C, D) making joint ventures. The contract looks something like:
template JointVenture
with
investors: [Party]
ventureId: Text
where
signatory investors
key (investors, ventureId): ([Party], Text)
maintainer key._1
In case you’re not familiar with the notation here, this means we can have any number of parties signing this contract and they’re all both signatories and maintainers.
Now, if A and B do a joint venture and call it “monkey” and then C and D separately make a joint venture and also want to call it “monkey”, should they be allowed to? Arguably yes, because there is no way for C or D to be aware of the deal between A and B. So, again, there is no global uniqueness.
If A and B make a deal and call it “yellow”, then B and C make a deal and want to call it “yellow” too, should this be allowed? Again, yes, because there’s no reason to force B to tell C they already have a separate deal with the same name.
But if A and B now want to make a third deal, it makes sense that they should call it something other than either “monkey” or “yellow”, as that would be confusing.
So, now, we can refine this idea of maintainer a little bit more: the set of maintainers (which must be parties) is the context in which the key is unique.
This is already necessary in a non-distributed context in order to maintain privacy. But it is indeed much more important in a distributed context: who would you ask to in order to check global uniqueness? You wouldn’t necessarily know everyone. So having a set of “responsible parties” as part of the key means when you have a key you know who to ask for the corresponding contract: the maintainers.
If you want a correlation with the database world, just imagine there is a separate table for each set of maintainers, and the unicity constraint is applied on that table.