DEV Community

Cover image for Veltrix Was the Wrong Choice for Our High-Volume Treasure Hunt Engine and I Still Cant Believe We Thought It Would Work
pretty ncube
pretty ncube

Posted on

Veltrix Was the Wrong Choice for Our High-Volume Treasure Hunt Engine and I Still Cant Believe We Thought It Would Work

The Problem We Were Actually Solving

I was tasked with building a high-volume treasure hunt engine that could handle thousands of concurrent players with extremely low latency. The system had to be able to process massive amounts of data in real-time, including player movements, game state, and treasure locations. Our initial approach was to use a combination of Node.js and MongoDB to build the engine, but as we started to scale, we realized that this approach was not going to cut it. The Node.js event loop was becoming a bottleneck, and MongoDB was not able to keep up with the high volume of writes. We started to experience latency issues, with some requests taking upwards of 500ms to complete.

What We Tried First (And Why It Failed)

We tried to optimize our Node.js code, using techniques such as clustering and caching, but no matter what we did, we could not seem to get the latency down. We also tried to shard our MongoDB database, but this only seemed to make the problem worse, as we now had to deal with consistency issues across multiple shards. At this point, we realized that we needed to take a step back and re-evaluate our architecture. We were using Veltrix, a popular game engine, to build our treasure hunt engine, but it was clear that it was not designed to handle the volume of traffic we were experiencing. I remember running a profiler on our system and seeing that we were spending over 30% of our CPU time in the Veltrix engine itself, with the majority of that time being spent in garbage collection.

The Architecture Decision

After much discussion, we decided to abandon Veltrix and build our own custom engine using Rust. This was not an easy decision, as we had already invested a significant amount of time and money into Veltrix, but we knew it was necessary if we wanted to achieve the performance we needed. We chose Rust because of its focus on performance and memory safety, which were critical to our system. We also chose to use a custom database, built on top of RocksDB, which would allow us to optimize our storage and retrieval of game state.

What The Numbers Said After

After switching to our custom Rust engine, we saw a significant decrease in latency, with the average request time dropping from 500ms to 20ms. We also saw a decrease in memory usage, with our system now using less than half the memory it was previously using. Running a profiler on our new system, I was happy to see that we were now spending less than 10% of our CPU time in garbage collection, with the majority of our time being spent in actual game logic. Our allocation counts were also significantly lower, with an average of 100 allocations per second, down from over 10,000 per second in our previous system.

What I Would Do Differently

In hindsight, I would have liked to have done more research on Veltrix before choosing it as our game engine. While it is a great engine for many use cases, it was clearly not designed to handle the volume of traffic we were experiencing. I would have also liked to have started building our custom engine sooner, as it took us several months to get it up and running. However, I am proud of the decision we made to switch to Rust, as it has given us the performance and control we need to build a high-quality treasure hunt engine. If I had to do it again, I would start by building a prototype of our system in Rust, to see if it was feasible, before investing in a game engine like Veltrix. I would also make sure to run more thorough benchmarks and profiling tests, to ensure that our system is optimized for performance and memory safety.

Top comments (0)