lambrospetrou / durable-utils

Utilities for Cloudflare Durable Objects and Workers
MIT License
6 stars 0 forks source link

Sharded DO v1 #3

Open lambrospetrou opened 3 weeks ago

lambrospetrou commented 3 weeks ago

Implement a utility class to abstract away sharded Durable Objects.

For example, I want to use N DOs instead of 1, where N is known upfront and will never change (for the initial version).

The utilities should allow reads/writes into a specific shard based on a shardKey: string, but also reads without specifying any shard key and in that case the aggregated results from all shards should be returned.

This can be done entirely with library code that will run in a Worker, I don't think I need to wrap custom logic on a DO.

Why

Goals

  1. Each shard (single DO) owns and manages the data for all shardKey values that hash into that shard.
  2. Initial version is fixed N shards to avoid rebalancing with shards being removed or added (once we have more utilities to facilitate this we can extend it).
  3. The reads operations across all shards should provide some kind of streaming or iteration to ease consumption of all the data.