I try hard to design the DO parts of the

I try hard to design the DO parts of the system so that don't need any external fetches, mostly not for cost reasons but because it breaks the DO concurrency model. In the rare cases where I just couldn't design around that, I offload it to a Worker (sometimes through a Queue) who will "respond" by calling back to the DO when it has the answer. The "address" of the caller is passed along and used to get the "response" back to where it originated. JSON-RPC is really nice for this because it doesn't rely upon HTTP Request-Response. Rather it uses an id, so the "response" can come much later and be heavily interleaved with other "requests". You can do JSON-RPC all the way from the browser through multiple server-side hops (Browser to Worker to DO to Queue to Worker to ExternalService to DO and then back to Browser) over HTTP, WebSockets, or Cloudflare native RPC depending upon which is best for that particular hop. You don't pay for time in a browser that a Promise is unresolved, and this architecture essentially moves all of the waiting there.
Was this page helpful?