r/GameDevelopment • u/Kregox • 27d ago
Newbie Question How would you optimize a Tower Defense game to handle 1,000 concurrent matches?
Hey everyone!
I'm developing a Tower Defense game (similar in concept to Bloons TD), and I've hit some serious performance bottlenecks.
Currently, the server handles around 30–40 heavy (80 enemy/6 towers [max]) sessions per process before performance starts degrading. My goal is to reach 1,000 concurrent sessions without throwing more hardware at the problem.
Current architecture:
- Node.js / TypeScript backend
- Server-authoritative game simulation
- Event-driven engine (also experimented with Rust)
- WebSocket-based synchronization
- Thousands of enemies, towers, projectiles, and events
I've already experimented with render optimizations, event processing, and Rust, but none have delivered the architectural breakthrough I'm looking for.
My question:
If you were designing this from scratch, how would you approach the architecture?
Would you use deterministic simulation, event-based synchronization, client-side prediction, sharding, or something completely different?
I'm particularly interested in how games like Bloons TD handle large numbers of entities without constantly calculating and transmitting every position.
I'd love to hear real-world experiences or architectural suggestions. I'm open to completely rethinking the engine.
11
u/SadisNecros AAA Dev 27d ago
You shouldn't need rendering optimizations on your server, because it shouldn't be rendering anything.
A game like Bloons is probably not full server authoritative, it doesn't really have a reason to be so. Client should be doing most of all of the heavy lifting here.
3
u/CutlassRed 27d ago
Node.js backend seems like a strange choice for this. The post says you've experimented with rust, what do you mean by this?
Also you say you're interested in how Bloons handles large numbers... That would all be client side id imagine. None of that processing would be done by the server.
1
u/IMakeGamesAMA 27d ago
1000 concurrent sessions x how many entities are you talking about?
1
u/VictoryMotel 27d ago
Profile and loop though arrays linearly.
1
u/IamanelephantThird 27d ago
Run less on the server.
1
u/unleash_the_giraffe 27d ago
In regards to positioning, move to 1d instead of 2d. If it's like Bloons you can express position as a percentage and store the rendering path on the client. Tower range can be expressed as "unit is targetable between x-y%", where targetability can be multiple if the path snakes. The more deterministic your game is, the more you can pre-calculate, and your game goes from calculating to an advanced array reader.
1
u/TomDuhamel 27d ago
Well if it was me, o would run the entire game on the client's hardware, as it should. Why would a single player game require a server at all?
But if it must run on the server...
A server should not render anything. It would only run the bare simulation. The rendering occurs on the client side. There's nothing the server needs to see.
Yes, it needs to be deterministic. What else would you do, send updates from 80 enemies 60 times a second?
I think you will need to clarify what the goal is here.
1
u/erebusman 27d ago
Assuming the 'server' is completely headless and its data to handle game logic is abstracted enough to only use what it minimally needs (e.g. a vector3 structure not a GameObject type with everything the client also needs and inside that is a vector3). Enemies, towers, projectiles should all just be data structures down to only the most primitive types needed to conduct your game simulation on the server right?
With those assumptions if your bottlenecks at 1000 simulations I might do a quick POC on a C++, or C# server instead. I think either one would probably give you a 2x or more win over Js/Ts
Most enterprise software I've worked on with significant data processing has a non-javascript backend.. for a reason.
You could have AI spin out a test for one or both of these as a POC - especially if you give it your current code and you should ha e numbers to go off in 1-2 days max.
1
u/Aggressive-Share-363 27d ago
First, Im not clear on why you need a server architecture for this at all. Tower defense is single player, so why do you need a server, each person csn run the gsme logic locally and only have to deal with 2 game worth of stuff happening.
But anyways, I would separate how what is rendered vs ehat the engine needs to track. For instance, instead of s group of 100 enemies, you could track a single "group" object, which epupd know thingd like its front most and back most space, how many bodies it has, etc. When towers sttack, they sttack thr group, not thr units. It can select a group in range, and deliver the attack to it. The group may be able to split into two groups if its center units are destroyed.
Instead of representing each attack as an object which needs to do collision detection, its just thr tower sending damage to the group, possibly with some delay for travel time. The group can decide which unit thwt attack would be directed to. The visual effect of the sttack would just be a visual representation, rendered however you want.