Prefer web socket method DO vs Worker for sources #65
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
Originally all web socket communication was handled via the Durable Object and its hibernation API. Then with the introduction of external data sources we abstracted the web socket communication to live more ephemerally on the Worker and we removed the socket handler on DO's. Now... we're bringing it back!
Why?
Web socket connections on the durable object can handle state between requests. Allowing web sockets to be handled at this level will provide additional flexibility for developers interfacing via Starbase plugins to achieve their goals.
Should all web sockets move to Durable Objects?
TLDR; I don't believe so.
For externally connected databases we use web sockets via the Worker instead of the Durable Object. Could a case be made that handling state between multiple web socket messages makes sense for these data sources? Sure. But at the moment we would need to then also migrate all of our code of how we communicate with those data sources to being inside a DO and that comes with downside. The upside of communicating with an external data source via a Worker is the worker is on the edge and acts as a node en route to the destination. If we were to move it to a Durable Object, there are far fewer global nodes, less possibilities with throughput (RPS), and overall would likely slow down those responses overall.
Tasks
/socket
requests use Durable Objects web sockets/socket
requests use Workers web socketsexecuteTransaction
in a DO was not returning resultsVerify
Before
After