Shard Affinity and Ent Colocation
Last updated
const schema = new PgSchema(
"comments",
{
id: { type: ID, ... },
topic_id: { type: ID },
...,
},
[]
);
export class EntComment extends BaseEnt(cluster, schema) {
static override configure() {
return new this.Configuration({
shardAffinity: ["topic_id"],
...,
});
}
}
// Creates the comment in the microshard whose number
// is parsed out of topicID prefix.
await EntComment.insert(vc, { topic_id: topicID });// The queries will be sent only to the microshards
// where topicID1, topicID2 etc. live.
const comments = await EntComment.select(
vc,
{ topic_id: [topicID1, topicID2, ...] },
100,
);