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

    albert

    12/16/2022, 8:18 PM
    Then how does the Workers Runtime know where to send requests made using the stub?
  • b

    brett

    12/16/2022, 8:19 PM
    It's either embedded in the ID (newUniqueId) or we use a hash mod
  • b

    brett

    12/16/2022, 8:19 PM
    Objects can be relocated, which requires leaving behind a pointer. But we don't just distribute every ID's location everywhere
  • a

    albert

    12/16/2022, 8:27 PM
    That works for newUniqueId, but I don't think it explains idFromName. The information that "brett" was created in e.g. ARN must somehow be pushed to other colos.
  • a

    albert

    12/16/2022, 8:28 PM
    If you know (from any colo) that a non-EU object exists elsewhere, would you not be able to know the same for an EU object?
  • b

    brett

    12/16/2022, 8:29 PM
    We don't know that, we just know which colo to contact to see if it does (the hash mod noted above)
  • b

    brett

    12/16/2022, 8:29 PM
    Because everyone contacts the same colo for that object
  • a

    albert

    12/16/2022, 8:33 PM
    Is the colo that you contact the same colo that would create the object if it doesn't exist?
  • a

    albert

    12/16/2022, 8:34 PM
    Does that mean idFromName objects are not necessarily created in the closest DO-capable colo?
  • b

    brett

    12/16/2022, 8:35 PM
    That's right, that way 2 people around the world can ask for an object at the exact same time and end up at the same place in the same object
  • b

    brett

    12/16/2022, 8:35 PM
    Kinda, yeah. They are immediately relocated to the nearby colo, they leave behind a pointer. That's the "cached lookup" we have to do that we talk about for
    idFromName
  • b

    brett

    12/16/2022, 8:36 PM
    But info about that object is only in those 2 colos now (and also, Jurisdictional objects stay within their Jursidiction)
  • a

    albert

    12/16/2022, 8:42 PM
    Thanks for taking time to explain some of the architecture DOs - it makes a lot more sense now. This also explains why names can't be unique across jurisdictions. It is because names hashed with EU jurisdiction map to a different (and smaller) pool of colos, so the "colo to contact" would very likely be different than if not using a jurisdiction. Have I got it right?
  • b

    brett

    12/16/2022, 8:47 PM
    Close, there's a little more, this probably warrants a blog post at some point
  • a

    albert

    12/16/2022, 8:48 PM
    Please do! Would be very interesting to read about 🙂
  • a

    Alexander.Xtreme

    12/16/2022, 9:11 PM
    In that sense its faster for us to cache a DO Id on kv, than to invoke it with id from a known name. The same regarding creating using newUniqueId. The problem is the consistency of that creation... The things you explained are indeed relevant. But if we are using some kind uuid to referend the DO, if its local to a jurisdiction, we have to store the jurisdiction, the uuid and the DO id.
  • c

    ckoeninger

    12/16/2022, 9:15 PM
    if you're ok with using an opaque id, why would newUniqueId not work for you? jurisdictions for those have been available for quite some time, https://developers.cloudflare.com/workers/runtime-apis/durable-objects/#restricting-objects-to-a-jurisdiction
  • b

    brett

    12/16/2022, 9:24 PM
    > In that sense its faster for us to cache a DO Id on kv, than to invoke it with id from a known name. Not sure I follow, we cache the relocation, so it's at worst equal to KV (faster really, for reasons)
  • a

    Alexander.Xtreme

    12/16/2022, 9:27 PM
    Thanks! I do appreciate you corrected me on this.
  • a

    Alexander.Xtreme

    12/16/2022, 9:27 PM
    I misunderstood, I thought the way you handled all that routing was worse, than having the value cached on the kv.
  • a

    Alexander.Xtreme

    12/16/2022, 9:28 PM
    Therefor my current design is correct, my previous understanding is correct.
  • a

    Alexander.Xtreme

    12/16/2022, 9:29 PM
    My use case is to call from the worker a known DO server, that I expect to be in the closest colo. At the moment, I'm creating using the known name, but as you explained it bounces a bit, till it gets closer.
  • a

    Alexander.Xtreme

    12/16/2022, 9:31 PM
    I'm not, because with an opaque id, I had a consistency issue on creation, like you already handle for me... 🙂
  • c

    ckoeninger

    12/16/2022, 9:32 PM
    what consistency issue on creation are you talking about?
  • a

    Alexander.Xtreme

    12/16/2022, 9:38 PM
    Well, if I have a worker starting in Portugal for instance, and I need to create the DO that will manage stuff for Portugal, its created in Madrid actually, Spain. But when the worker gets triggered, nothing prevents another worker to be triggered at the same time, as in both are going to try to create that DO for Portugal. If I used an opaque id, I could have concurrency issues placing on the kv "Portugal->Opaque Id", that is why I created with IdFromName
  • a

    Alexander.Xtreme

    12/16/2022, 9:40 PM
    That's precisely the issue brett explained quite well why they used that hash mod algorithm to make it deterministic where the do gets "located"
  • c

    ckoeninger

    12/16/2022, 10:05 PM
    ah, so KV consistency issues. If what you're basically saying is opaque IDs are inconvenient because you have to store them somewhere - I'd agree with you.
  • c

    ckoeninger

    12/16/2022, 10:05 PM
    KV isn't the only place to store them though
  • d

    Deleted User

    12/17/2022, 1:02 AM
    TIL I don't need service bindings to call a DO from another worker
  • d

    Deleted User

    12/17/2022, 1:03 AM
    cuts my requests in half yay
1...460461462...567Latest