The Identity of an Item

The partition key and the id of an item, together, constitutes the identity of an item.

That means if you change the partition key or the id, you are actually creating a new item and not really changing the old item at all.

In Gyxi, you have your main data, which is where you originally save it. This is where the real identity of your data is and here the combination of the partition key and the id must absolutely be unique and must never change. If you think the id may possibly change, then this is not really an id. Instead use something like a GUID as an id and keep your other property under another name.

However, the advantage of having something as an id is that you can look up with it incredibly fast. It doesn’t require any search of any kind, directly or indirectly, you simply grab an item where it is and it takes literally less than 5 milliseconds (+ latency, overhead etc).

This is why views are important. It lets you fulfil two conflicting requirements:

  • Make sure the combination of your partition key and your id is absolutely unique and is never changed.
  • Make sure you can quickly find items by a certain property which may not be the same as the id.

For example, let’s say you want to find people by their email. This is very natural. But at the same time, you don’t want the email to be the id because people may change their id.

In this case you should create people using a global unique identifier (GUID) as the id and then add the email to a normal email property.

Then you create a view. The view would not require any other property than “idBy”: “email”.

This will simply create a copy of all your data, but using the email as an id. It preserves the id of your original data, which is unique, but it allows you to fetch users using your email incredibly fast. Fetching an item from a view is as fast as fetching an item from your base data.

And what if you want to find the GUID by the Email? Well, that is why you should include all data in your object AND then your chosen identifier in the id property. So your “person” object should look like this:

      “id”: “12345-abcde-6789-etc”,
      “email”: “”,
      “uniqueId”: “12345-abcde-6789-etc”

And then the data in your view will look like this:

      “id”: “”,
      “email”: “”,
      “uniqueId”: “12345-abcde-6789-etc”

This allows you great flexibility in making other views and making sure all your data is at your fingertips, exactly where you want it.

Business Registration Number DK28916779