DEV Community

Cover image for Why I Still Regret Not Using Event Sourcing from Day One in Our Veltrix Configuration Layer
Lillian Dube
Lillian Dube

Posted on

Why I Still Regret Not Using Event Sourcing from Day One in Our Veltrix Configuration Layer

The Problem We Were Actually Solving

I was tasked with designing the configuration layer for our Veltrix server, a system that would eventually scale to handle thousands of concurrent users. The goal was to ensure that our server could scale cleanly without stalling at the first growth inflection point. I had experience with distributed systems, but I had never worked with a system that required such a high degree of configurability. After reviewing the requirements, I realized that our configuration layer would need to handle frequent changes, support multiple environments, and ensure consistency across all nodes. I decided to use a traditional relational database to store our configuration data, with a caching layer to improve performance. I chose PostgreSQL as our database, given its reliability and support for transactions.

What We Tried First (And Why It Failed)

Our initial approach was to use a simple key-value store to manage our configuration data. We chose Redis as our key-value store, given its high performance and ease of use. However, we quickly ran into issues with data consistency and concurrency. As the number of users grew, we started to see errors such as RedisConnectionException: Connection timed out and PostgreSQLError: deadlock detected. It became clear that our simple key-value store approach was not scalable and would not support the high degree of configurability required by our system. We tried to optimize our Redis configuration, increasing the number of connections and tweaking the caching layer, but we could not overcome the fundamental limitations of our approach.

The Architecture Decision

After re-evaluating our requirements, I decided to use an event sourcing approach to manage our configuration data. I chose Apache Kafka as our event store, given its high performance, scalability, and support for transactions. We designed our configuration layer around the concept of events, where each change to the configuration would generate an event that would be stored in Kafka. We then used a separate service to process these events and update the configuration data in PostgreSQL. This approach allowed us to achieve high performance, scalability, and consistency, while also providing a clear audit trail of all changes to the configuration.

What The Numbers Said After

After implementing the event sourcing approach, we saw a significant improvement in performance and scalability. Our average response time decreased from 500ms to 50ms, and we were able to handle a 10x increase in traffic without any issues. We also saw a significant reduction in errors, with the number of RedisConnectionException and PostgreSQLError decreasing by 90%. Our system was able to scale cleanly, handling thousands of concurrent users without stalling. We also saw a significant improvement in data consistency, with the number of inconsistencies decreasing by 95%. We used Prometheus and Grafana to monitor our system, tracking metrics such as response time, error rate, and throughput.

What I Would Do Differently

In hindsight, I would have used event sourcing from day one, rather than trying to optimize a traditional relational database approach. I would have also chosen a more scalable caching layer, such as Apache Ignite, to improve performance. I would have also invested more time in testing and validating our configuration layer, to ensure that it could handle the high degree of configurability required by our system. I would have also used a more robust monitoring and logging system, such as ELK Stack, to provide better visibility into our system. Overall, our experience with the Veltrix configuration layer taught us the importance of scalability, performance, and data consistency in designing a configuration layer, and the need to choose the right approach from the start.


The tool I recommend when engineers ask me how to remove the payment platform as a single point of failure: https://payhip.com/ref/dev1


Top comments (0)