An Azure Cosmos DB database is used to track inventory for a company. Queries are most often based on date received, serial number, or both.
You need to horizontally partition data to optimize both read and write operations.
What should you do?
You should use a synthetic partition key based on the date and a precalculated suffix based on serial number. A Cosmos DB partitions data into logical horizontal partitions based on partition keys. The best practice is to use a partition key that has a large number of unique values. This helps distribute data and the workload evenly across partitions.
Using a key based on the date and a precalculated suffix based on serial number meets the goal of spreading data across multiple logical partitions, which helps to optimize write performance. Using the values that are primarily used for queries helps to improve read performance.
You should not use a synthetic partition key based on the date and a random suffix. This would spread the data across multiple partitions but does not help with data reads because you do not know the value used when generating the key.
You should not use either just the date or just the serial number. Using just the date means that you would have more entries in each partition and would help with queries based on date only, not serial number. A partition key based on serial number would distribute the data but would not help optimize reads using a date in the query.