Finding a Partition

A good strategy for your document database is to have a sort of hierarchy for your data, starting with your root data, which you use to partition.

An example might be that your application has a number of “accounts”, where each account is perhaps a customer, and you never or rarely want to query data across two accounts.

In that case you will start by making a type called “account” and you put all your accounts in this table under the “null” region. You probably do not want to partition this by the account itself, because it will make it difficult for you to retrieve a list of accounts. You can only retrieve a list of data within one partition at a time.

Then under each account, you have different data. For example, let’s say you have some people associated with your accounts, then you should create a type called “person”.

This type is partitioned by account and makes it easy to find people associated with an account.

This way of making a hierarchy is a good structure. Here is an example of what that may look like.

“account” type

PartitionKey Id
null Northwind
null Contoso
null Acme

“person” type

PartitionKey Id
Northwind James Smith
Northwind Jack Johnson
Acme Bugs Bunny

Now, imagine you did you not have the “account” type. How will you know which “person” data you have? In order to list data, you are required to supply a partition as part of your query. How would you know which partition to send if you did not have the “account” type? The answer is that there is no way to know and effectively your data would be lost forever.

Gyxi provides a Plan B

Although the structure described above is highly recommended, Gyxi does have a Plan B for you to use if you cannot find a partition. Under the API Reference, you can find an endpoint that will list partitions under a certain type for you.

This call is relatively slow and should be used as part of troubleshooting, ad-hoc calls, maybe in an admin area. It should not be used as part of your central business logic. For that, you should establish a structure as outlined above.