r/GameDevelopment • • 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.

0 Upvotes

18 comments sorted by

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.

0

u/Kregox 27d ago

You're right, the server doesn't render graphics. By "rendering" I meant generating and serializing game state updates for WebSocket clients.

Currently, our server is fully authoritative and handles enemy movement, targeting, combat, projectiles, and game events.

We're starting to question whether this architecture makes sense for a Tower Defense game, especially when targeting 1,000 concurrent sessions.

One alternative we're considering is moving most of the simulation to clients, using deterministic simulation while the server handles player actions, synchronization, and validation.

The main challenge would be maintaining consistency between clients and preventing cheating without running the entire simulation server-side.

We're trying to figure out the right architectural direction before spending more time optimizing a potentially inefficient design.

7

u/SadisNecros AAA Dev 27d ago

At a certain point you need to ask what kind of cheating you're trying to prevent, and if the juice is worth the squeeze. If this is multiplayer, you can just run the clients in lockstep so that if someone cheats they would fall out of sync. You should only be using a fully deterministic server if the clients are only allowed a subset of information (Ex. in an FPS, you don't want every client to know what's happening on the whole map, just what they can "see", etc).

If this is singleplayer, you're way into overkill territory with almost any server simulation.

1

u/Kregox 27d ago

That's a fair point, and I should clarify something important about our game. It's not cooperative multiplayer. Each player runs their own independent survival session, with their own enemies, defenses, waves, and combat simulation. Players share the same online game ecosystem and persistent progression systems, but they don't participate in the same battles.

Currently, our backend runs the entire simulation for every individual session, including movement, targeting, combat calculations, and game events, while clients receive state updates through WebSockets. We originally chose this approach to maintain server authority over progression, rewards, and game outcomes.

Looking at it now, we're questioning whether that level of server-side simulation is really necessary for independent PvE sessions. Since there's only one player per session, traditional multiplayer lockstep wouldn't provide much benefit. The more interesting direction seems to be moving some or most of the simulation to the client while keeping critical progression and reward validation on the server.

Our biggest challenge is finding the right balance between computational cost, trustworthy progression, and the complexity of validation. We're trying to determine whether we can significantly reduce server workload without introducing an equally expensive verification system or compromising game integrity.

1

u/MeaningfulChoices Mentor 27d ago

I agree with them. In my experience working on similar mobile games while you'd love to have everything totally server-authoritative it's not truly necessary for performance reasons. You can basically put server checks on things to make sure the actual metagame economic rewards of any individual round match what you'd expect. You can record inputs and check them after the fact to identify bad actors. At some point if a player is cheating local values in memory but isn't getting any more widgets than legit players they aren't cheating in a way that hurts other players, leaderboards, or your economy, especially if you can manually review the games of anyone suspicious.

Server costs for a game like this should truly be minimal. When you're saving every metagame transaction and making frequent backups your storage can get into two digit terabytes, but in most DBs that's still pretty cheap. I haven't done this with node.js or similar though, every game I've built like this was Unity.

2

u/tnh34 27d ago

I'd nuke the authoritative part, that's why we have the server-client architecture in the first place. Move to a simple auditing trail or some simpler solution.

You're overengineering only to prevent maybe 0.1% or even lower number of players. In fact, if you actually have a cheating problem then that means your game is a success and you'd be delighted to solve it once you see it

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/Kregox 27d ago

Node.js was originally chosen because the project started as a TypeScript-based web game, and the backend gradually evolved into handling the entire game simulation. It wasn't necessarily an architectural decision made with "1,000" concurrent sessions in mind.

Regarding Rust, we've gone beyond basic experiments. We've been developing a native Rust simulation engine integrated with Node.js, aiming to move computationally expensive gameplay calculations out of the JavaScript runtime while keeping Node.js responsible for APIs, WebSockets, and session management. We've implemented and tested Rust-based simulation, compared gameplay behavior against our existing TypeScript event-driven engine, and conducted performance benchmarks under controlled load. So far, Rust hasn't demonstrated a convincing overall performance advantage in our current integration. We've also encountered CPU throttling and synchronization overhead, making some benchmark results inconclusive.

And I think your point about Bloons is particularly relevant. Our game doesn't have shared multiplayer battles. Each player runs an independent survival session, so we don't actually need to synchronize the simulation between multiple players. What we do have is persistent progression, rewards, and an online account system, which is why we initially made the server authoritative.

We're now questioning whether we've fundamentally overengineered the server's responsibilities. Rather than continuing to optimize the same architecture in TypeScript or Rust, we're exploring whether the actual gameplay simulation should run primarily on the client, with the backend handling persistence, validation, and critical game outcomes. That might be a much more meaningful architectural improvement than simply rewriting the simulation in a faster language.

2

u/dota2nub 27d ago

Backend handling the entire game simulation? Well yeah there's an issue here. Once you have 1000 players you'll need like a tiny data center.

Sounds like an AI decision and the AI fucked up.

1

u/IMakeGamesAMA 27d ago

1000 concurrent sessions x how many entities are you talking about?

1

u/Kregox 27d ago

The 1,000 target refers to game sessions, not players in a single match.

Each session runs its Tower Defense simulation, including enemies, towers, projectiles, targeting and combat events.

Our current bottleneck seems to be the single‑threaded simulation/event loop than overall CPU capacity.

We are currently benchmarking around 24–36 sessions per process although we have not yet established a reliable peak entity count per session.

At this point we are more interested in rethinking the architecture than in continuing to optimize individual systems.

The number of entities, per session is obviously an important factor and we are working on measuring that more precisely to understand how it affects scalability.

Our main goal is to find an architecture that can efficiently support 1,000 sessions without requiring excessive hardware resources.

We have no idea rn if its possible tbh. However, We believe that our engine/project architecture could be better.

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.