There is no point doing the work from
There is no point doing the work from the worker since you will hit huge latencies. You worker could be on one side of the world and your DO on the other.
If you want remote access to SQLite, might as well use D1 and get the other niceties too.
Each
await stub.something()
you call is a roundtrip. You can pipeline several together if you design your DO class properly but even that's very limited.
The power of DOs is to have the logic inside the DO so that you can do very very fast access to storage.4 Replies
Oh, okay. Makes sense, but also a tad bit disappointing.
In my initial experiments with something similar to the code I proposed, I didn't see more latency than the SQL queries, but maybe the DO and the worker was on the same machine. I was hoping to use it like Turso's "embedded replica sync", and that the DO would "follow" (for lack of a better word), the worker (or at least some replica would). But it does make sense, and maybe I can structure my application a bit better, by just rethinking it a bit. Testing it again, confirms what you are saying. Now they are clearly far away from each other.
In my initial experiments with something similar to the code I proposed, I didn't see more latency than the SQL queries, but maybe the DO and the worker was on the same machine. I was hoping to use it like Turso's "embedded replica sync", and that the DO would "follow" (for lack of a better word), the worker (or at least some replica would). But it does make sense, and maybe I can structure my application a bit better, by just rethinking it a bit. Testing it again, confirms what you are saying. Now they are clearly far away from each other.
You can use the CDN Cache API, or workers KV to cache things globally for your workers to access faster if needed, but it depends on your use-case if it's better than just going to the DO.
Yeah, I'll have a think about what I really need. For now, I'll probably just continue using D1. What I really liked about DO SQlite, and the reason for this exploration, was that I was able to extremly easy have a multi tenant solution, where they were also isolated from each other. Which was (is) perfect for the business requirements.
I'll explore some more! Thank you for your input! 🙂
Based on your multi-tenant requirements, I think you are on the right track with DOs. Consider moving all of the compute into the DO, where the Worker layer just becomes a proxy.