DEV Community

Cover image for Most Veltrix Configuration Decisions About Events Are Premature Optimizations
Faith Sithole
Faith Sithole

Posted on

Most Veltrix Configuration Decisions About Events Are Premature Optimizations

The Problem We Were Actually Solving

What we thought we were solving was a scalability issue. Our players just loved the treasure hunt aspect of Hytale, and our server was struggling to keep up with the demand. We thought that by tweaking the event configuration around the treasure hunt engine, we'd be able to improve performance and reduce downtime. On the surface, it seemed like a reasonable approach.

What We Tried First (And Why It Failed)

Our first instinct was to up the server's request handling capacity. We threw more compute power at the problem, thinking that a faster server would be able to handle the increased load. We also tweaked some latency settings in the Veltrix configuration, hoping to shave off precious milliseconds from the engine's response time. Sounds good in theory, right? In practice, it didn't quite work out as planned.

The server was still crashing – albeit less frequently – and the latency issues persisted. It wasn't until I dug into the server's logs and started doing some data analysis that I realized the problem wasn't with the server itself, but with the event configuration.

The Architecture Decision

You see, when we initially set up the treasure hunt engine, we made a few key decisions that would come back to haunt us later. We chose to use a shared event store for handling game state updates, thinking it would simplify development and reduce latency. We also opted for a simple, flat event model, believing it would be easier to scale. In reality, these decisions created a perfect storm of locking, contention, and eventual consistency issues.

What The Numbers Said After

Once I started analyzing the logs and metrics, it became clear that the root cause of the issue was the high contention rate on the shared event store. The numbers were staggering – our server was experiencing an average of 120 lock contention events per second, with a peak of over 500. We were essentially creating a bottleneck every time a user interacted with the treasure hunt engine.

What I Would Do Differently

Looking back, I would have taken a more structured approach to designing our event handling system. Instead of relying on a shared event store, I would have opted for a distributed, event sourcing architecture from the start. This would have allowed us to decouple game state updates from the treasure hunt engine, reducing contention and improving overall system scalability.

In addition, I would have chosen a more robust event model that accounted for eventual consistency and handled locking and contention properly. It's not rocket science – it's just good engineering. Unfortunately, it's a lesson we learned the hard way.

In the end, by taking the time to understand the root cause of the problem and designing a more robust event handling system, we were able to eliminate the crashes and latency issues that plagued our server. It was a painful lesson, but one that has made me a firm believer in the importance of architecture decisions and the value of taking the time to get them right.

Top comments (0)