-
-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider eventual consisteny in TODO example #42
Comments
There will be synchronization issues if UserA and UserB are writing into the same key, but that doesn't happen in this example. The example is setup in a way so that UserA only deals with UserA's todos (eg, That said, if UserA adds multiple todos in close succession, then that may cause replication issues within the This This updated, hypothetical export async function list(username: string): Promise<Todo['uid'][]> {
const prefix = key_owner(username) + '::';
const keys = await TODOS.list({ prefix, limit: 10 });
// The current example returns Array<Todo['uid']>
// So stopping here, but could do Promise.all(/* key lookup */)
// strip prefix; eg `key_item - (key_owner + '::') = uid`
return keys.map(key => key.substring(prefix.length));
}
DOs are still in beta & worktop (purposefully) doesn't integrate with or support them yet. This is to avoid early/unnecessary breaking API changes while DO-things continue to finalize. |
Hi @lukeed thanks for the write-up. Indeed, the list is scoped to the user. Great tip with the Do you plan to support the |
|
Yup. PR in the works for all metadata-stuff. Was a busy week so havent had time to finish it up yet. |
After several weeks working with Cloudflare workers, I just realized how the KV storage behaves from an application perspective. As mentioned in the documentation reads and write are eventually consistent.
Ref: https://developers.cloudflare.com/workers/runtime-apis/kv#reading-key-value-pairs
This means we can't write based on a previous read state. In the TODO example, we will lose data when multiple users create TODO's in the time range of the synchronization between the edges.
I opened this issue to communicate that circumstance a bit deeper. Durable Objects will solve it but I'm surprised that they can only hold 32KiB 😕
The text was updated successfully, but these errors were encountered: