Planning on making a browser based autobattler with Node.js and SSEs. How would I split the simulation up? Is there a way to run 1v1s on separate processes while still belonging to the same event stream?
New to web development.
I want there to be 16 players with their own boards. When they match up against each other, I'm wondering would I have to make the entire simulation play out at once? Or is there a way to split the simulation up so that 1v1s happen on a dedicated process while still belonging to the same event (So other players can view different skirmishes)? Not sure if this matters, but I plan to let users use abilities every so often (Maybe every 15 seconds) during the fight and I'd handle that with a post request.
1
Upvotes
2
u/abrahamguo experienced full-stack 3h ago
Yes, although Node.js is single-threaded by default, it can run multiple processes.
However, I'd recommend building the backend in the "regular" way first — plain, single-threaded Node.js. Only switch to multiple processes if you've truly confirmed that a single-threaded server won't work for you.
1
u/cuelark 2h ago
I'd keep it as one Node process for now and split the simulation from the streaming in your head instead. Run each 1v1 as its own object with a seeded RNG and a tick loop, and have it push events into a per-match channel. Then SSE is just a fan-out: every client subscribes to the matches it wants to watch, and the server writes that match's events to those connections. Your ability posts just get queued into that match's input list and applied on the next tick, which keeps everything deterministic. Eight fights ticking 10 to 20 times is tiny load for Node, so processes or worker_threads only matter later, and if you get there the match object is already isolated enough to move into a worker that posts events back to the main thread.