I am using Durable Objects to make a service for an app since my model allows me to instantiate a DO

I am using Durable Objects to make a service for an app since my model allows me to instantiate a DO per user, this way I don't run into the 10GB limit a single D1 database would have. The only issue is that some power users will definitely exceed this limit and I'll have to shard the data across multiple instances.

When writing to the underlying SQL database I don't know how much space the inserted data will take up. I would like a way to:

  1. start something like a transaction;
  2. attempt to insert data;
  3. if succeeded, return;
  4. if failed (due to storage cap), rollback, and move to next shard.
I have the sharding figured out. I'm missing the rollback/transaction and knowing what error is thrown by DO. I know from reading somewhere that for D1 it's a D1_ERROR but even that is not documented.

I really would like not to have a "attempt to write, if it's 0.9GB move to another shard just in case" scenario.
Was this page helpful?