Patrick (he/him)
Patrick (he/him)15mo ago

How are deno processes/isolates managed in Deploy?

Hi, I'm writing a multiplayer game in Deno and currently all of the game state is kept in module-scoped objects, there's no database or any other form of persistence, yet. It all works as expected when I'm developing locally, but sometimes when testing in Deno Deploy, it's as if there's multiple instances of the game running and which one I'm connecting to is random (using the same URL.) Does Deploy create multiple simultaneous isolates for the same deployment? Is the only solution to implement external storage and make that the source of truth?
14 Replies
Andreu Botella (they/them)
My understanding is that Deploy creates one isolate per edge server at a time, and it can kill them when they haven't been used for some time if you need to persist state, you would need to use some external database, or Deno KV
Patrick (he/him)
Patrick (he/him)15mo ago
well to clarify, it’s fine if it looses state after a certain period of inactivity. That’s more of a feature than a bug for me. What I’m describing happens within a short interval.
Andreu Botella (they/them)
well, that "some time" I mentioned could be as low as one minute apparently
Patrick (he/him)
Patrick (he/him)15mo ago
hmm yeah I guess that could be it. Though it doesn’t explain how the sometimes the state is reset, then on a subsequent page reload the old state is back. It seems to alternate between different instances also I think this window is more like a few seconds max
Andreu Botella (they/them)
maybe it could be that you're about halfway between two isolate regions, such that sometimes your requests go to one edge server and sometimes to a different one idk
Patrick (he/him)
Patrick (he/him)15mo ago
hmm that’s a compelling explanation. Seems like I need persistence
Andreu Botella (they/them)
also, even if your requests usually end up consistently on some edge server, they will be routed to a different one if that one is down so even then you can't rely on isolate-local state
Patrick (he/him)
Patrick (he/him)15mo ago
for anyone interested, this seems really useful and relevant for keeping the various region/isolates in sync https://deno.com/deploy/docs/runtime-broadcast-channel e.g. https://github.com/denoland/tic-tac-toe/blob/953417adef97e7c232ea4ddb4d9de0fba3392e76/utils/db.ts#L3
GitHub
tic-tac-toe/db.ts at 953417adef97e7c232ea4ddb4d9de0fba3392e76 · den...
A global, real-time multiplayer TicTacToe game for Deno 🦕 - tic-tac-toe/db.ts at 953417adef97e7c232ea4ddb4d9de0fba3392e76 · denoland/tic-tac-toe
Patrick (he/him)
Patrick (he/him)15mo ago
ok, this seems like a smoking gun to me. At least I can't think of any way to explain this other than that Deploy is running multiple instances of the app in the same region and routing between them randomly (or by some method I don't have any awareness or control over). The logs show info about clients connecting and disconnecting, along with the region and the timestamp. Each client is assigned a monotonically increasing identifier but yet I'm seeing a count that jumps from the 50s to 0 and back into the 50s.
ioB
ioB15mo ago
Deploy is running multiple instances of the app in the same region and routing between them randomly
yes?
Patrick (he/him)
Patrick (he/him)15mo ago
I guess I just wanted to confirm that this is normal
ioB
ioB15mo ago
Ah okay sorry, I was confused on the intention of your message I realize I should have read the rest of the thread 😅
Patrick (he/him)
Patrick (he/him)15mo ago
continuing this train of thought, as a half-baked idea: https://discord.com/channels/684898665143206084/1112472416854216835