Durable Objects write cache - pricing and ordering

According to this blog entry, you can run a storage.put without await, and it will store writes in a write cache and flush them to disk later.

Some questions:

A. If I update the same key, do I get charged for every write operation even though I may be actually just updating the write cache before it is flushed to disk (which is the expensive part)?

E.g:

storage.put("x", 1);
storage.put("x", 2);
storage.put("x", 3);

Am I charged for 3 writes here or 1?

B. Is the ordering of writes preserved regardless of await? The blog mentions that you do not need await on writes, but only shows writes in a block of all non-await or all await calls.

E.g:

storage.put("1", 1);
storage.put("1", 1.1);
storage.put("1", 1.3);
await storage.put("2", 2);
storage.put("3", 3);
await storage.put("4", 3);

Is the order of writes preserved here? I ask because an async function typically implies the call to the function is concurrent, but I think put orders the calls by when they were called.

Thanks

A. requests that hit cache are billed the same, see Pricing · Cloudflare Workers docs

B. the cache will coalesce writes to the same key. If I’m misunderstanding the question, please say more about how you’d be observing ordering of writes.

2 Likes

As an example, is it possible that key "1" could be any of 1, 1.1, 1.3 depending on which of them reaches the storage backend first, or will they always be written in order?

If the order is not deterministic, then the final value after the tx could be any of them.

If the order is guaranteed, then it will only ever be 1.3 - the last write.

It will be 1.3

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.