https://discord.cloudflare.com logo
Join Discord
Powered by
# durable-objects
  • g

    Greg Brimble | Cloudflare Pages

    04/04/2021, 10:35 AM
    @User @User @User Little bit of info here: https://discord.com/channels/595317990191398933/783765338692386886/811239747581509683 And a totally undocumented and not-at-all ready for open-source implementation here: https://github.com/glenstack/do/tree/main/src/data
  • l

    lar

    04/04/2021, 10:46 AM
    Thank you! Even just seeing that the graphql-tools packages are compatible with workers is a big help.
  • g

    Greg Brimble | Cloudflare Pages

    04/04/2021, 11:05 AM
    No worries ๐Ÿ˜Š sorry I couldn't give it to you in a more polished manner.
  • g

    Greg Brimble | Cloudflare Pages

    04/04/2021, 11:05 AM
    Let me know if you take it any further!
  • s

    Subh

    04/04/2021, 1:24 PM
    Hey guys! I am working on a POC, was wondering if you think it would be to crazy usecase on DO or not.
    Copy code
    User
       - Albums
               - Posts
    A user can have N numbers of Albums and Post.
  • g

    Greg Brimble | Cloudflare Pages

    04/04/2021, 1:44 PM
    If you need posts to be immediately available after publication, then yeah, you could build that in DO. But if you'd be happy with a small amount of time after publication before showing a post, then I think you could also build that in KV.
  • g

    Greg Brimble | Cloudflare Pages

    04/04/2021, 1:46 PM
    Deletions in both KV and DO can be a pain, so if you need to be able to delete data, I'd give that a bit of thought as well. Edit: DO is actually fine with deletions. Forgot about the new
    deleteAll()
    .
  • s

    Subh

    04/04/2021, 1:53 PM
    I completely agree with deleting part with KV. I using KV for https://cool.bio takes long for sure. Few things on that. 1. If I had to queries, how complex it will get? I mean I was looking at the docs, didn't really understand this part. For example, if I had to get just 1 month's posts 2. How would you structure the data for this? I am asking this because I am not able to visulation how to, probably I dont know enough about DO.
  • s

    Subh

    04/04/2021, 1:56 PM
    I need to look at @User example to understand more how is he keeping the monthly data in statusflare :p
  • v

    vans163

    04/04/2021, 2:05 PM
    What's the recommended way to read data out a DO?
  • e

    eidam | SuperSaaS

    04/04/2021, 2:05 PM
    I tried to start writing our case down but it would take a while to give you enough context about statusflare ๐Ÿ˜„ I will start with a suggestion to decouple the data to collections - in statusflare there is DO namespace for account monitors, DO for account incidents, and another DO for something else is coming soon ๐Ÿ™Š How many albums and posts the user might have, how big you expect the object keys gonna be? I actually dont query time-based, I query all of them and then just filter based on what I want to return (as its super tiny dataset)
  • v

    vans163

    04/04/2021, 2:05 PM
    Say if its 90/10 read/write workload. Theres no way to read without blocking the DO?
  • v

    vans163

    04/04/2021, 2:05 PM
    When you need a nonconsistent read
  • k

    Kevin W - Itty

    04/04/2021, 2:07 PM
    Cache with KV and let users read from that
  • k

    Kevin W - Itty

    04/04/2021, 2:07 PM
    Let authors read from DO
  • s

    Subh

    04/04/2021, 2:07 PM
    Interesting. Do the writing please ๐Ÿฅบ It will help. I need to do small stuffs first to get the idea first. I guess its just difficult for me to visualize this ATM.
  • g

    Greg Brimble | Cloudflare Pages

    04/04/2021, 2:08 PM
    To start basic... You'd probably have three DO classes: one for each of "User", "Album" and "Post". You'd probably want to use the
    newUniqueId()
    generation for each of the instances of those classes. Depending on how you're doing auth, you'd probably 'enter' through
    User
    , which on it, lists the IDs of `Album`s that it owns. (Same for `Album`s โ†’ `Post`s).
  • g

    Greg Brimble | Cloudflare Pages

    04/04/2021, 2:10 PM
    Since you can list keys on a DO instance, I'd personally go with User:123456 has keys:
    Copy code
    firstName โ†’ Greg
    lastName โ†’ Brimble
    album:78327 โ†’ 78327
    album:25627 โ†’ 25627
    And then do
    state.storage.list({ prefix: "album:" })
    which will return the list of album keys. Then you can just
    env.Album.get(id)
    .
  • v

    vans163

    04/04/2021, 2:11 PM
    Wouldnt this run up a crazy bill? 4xcharges? 1x worker. 1x userdo, 1xalbum do, 1x postdo?
  • s

    Subh

    04/04/2021, 2:11 PM
    What if I have 1M posts? Can one DO keep all of them?
  • v

    vans163

    04/04/2021, 2:11 PM
    So 4 requests
  • g

    Greg Brimble | Cloudflare Pages

    04/04/2021, 2:11 PM
    Depends on what you're calling crazy.
  • v

    vans163

    04/04/2021, 2:12 PM
    Like I wanted to have a model where every user is a DO object and other DOs communicate with a users DO
  • v

    vans163

    04/04/2021, 2:12 PM
    But the billing model makes this unfeasible
  • s

    Subh

    04/04/2021, 2:12 PM
    Please tell me there's a way to put
    state.storage.list({ prefix: "album:", date: "startFrom" })
    or something similar to quary?
  • g

    Greg Brimble | Cloudflare Pages

    04/04/2021, 2:13 PM
    https://developers.cloudflare.com/workers/runtime-apis/durable-objects#transactional-storage-api
  • v

    vans163

    04/04/2021, 2:13 PM
    Example a user can have their balance update multiple times a minute. Each balance update would incur a request charge to the DO
  • v

    vans163

    04/04/2021, 2:13 PM
    Even tho the request itself is super tiny
  • g

    Greg Brimble | Cloudflare Pages

    04/04/2021, 2:14 PM
    I don't think there's any limit to the number of key-values in a DO, but @User might know more than I.
  • g

    Greg Brimble | Cloudflare Pages

    04/04/2021, 2:14 PM
    But my design above isn't storing all posts in a single DO, each post is it's own DO.
1...434445...567Latest