orleans icon indicating copy to clipboard operation
orleans copied to clipboard

DynamoDB grain storage suggestion

Open bill-poole opened this issue 3 years ago • 2 comments

It seems from looking at the code that the DynamoDBGrainStorage provider stores the grain type as the table "sort key", which leaves the sort key unavailable for uses as described here.

I wouldn't have thought there would be any benefit to using the grain type as the sort key because I don't imagine there would ever be a need to query across the state of all grains with the same ID across all grain types.

I think it would be better to include the grain type in the "partition key" - i.e., something like {service-id}_{grain-type}_{grain-id}. Note that the partition key is currently formatted as {service-id}_{grain-id}.

A sort key attribute/field name could then be configurable with a setting on the storage provider. If configured, then the identified attribute/field would map to the sort key column.

bill-poole avatar Jul 26 '22 18:07 bill-poole

What do you envision using the sort key for? I've certainly thought about doing something like; however, querying against the sort key still requires knowing the partition key. We ended up using GSIs instead so that wasn't a requirement.

jsteinich avatar Jul 29 '22 14:07 jsteinich

I think the sort key is useful for parent-child relationships, where a parent grain needs to query the DB for a list of its child grains. But for this use case, the child grains would need to have a composite key uniquely identifying the grain. i.e., the child grain's partition key would need to be the parent grain ID, with the child grain's ID being a composite of the parent's grain ID and the sort key attribute.

So I guess it isn't a straightforward as just identifying an attribute to use for the sort key...

bill-poole avatar Jul 29 '22 15:07 bill-poole