CQRS and Database Replication for High-Load Backend

Sumary

Indastry:iGaming
BeFund servise:Backend architecture optimization
Technologies:Laravel, PHP, MySQL, MariaDB, PostgreSQL, CQRS, Redis, queues, database replication, SQL optimization, monitoring
Terms:14 days
Cost:By overall rating

About the client

Unfortunately, under the terms of the non-disclosure agreement (NDA), we cannot disclose the name of the client company and specific features of the project. However, by mutual agreement, we are able to publicize the general provisions of the project and some key solutions. In the case of your cooperation with BeFund, all issues regarding the publicity of information will be discussed individually.

What`s the problem?

About situation:

The primary database handled all application workloads, including write operations, user activity, reporting, administrative queries, scheduled jobs, and background workers.

As traffic increased, read-intensive operations began competing with business-critical transactions for the same database resources. This affected overall system performance and reduced the ability to scale the platform efficiently.

The client required an architecture that would reduce pressure on the primary database while maintaining data consistency and supporting future growth.

The goals of project:

âžœSeparate read and write workloads
âžœReduce load on the primary database
âžœImprove the performance of read-heavy operations
âžœOptimize SQL queries for large datasets
âžœImprove database indexing strategy
âžœIntroduce database replication
âžœMove non-critical processing to background workers
âžœMonitor replication health and database performance

Solution by BeFund

We implemented a database architecture based on the CQRS (Command Query Responsibility Segregation) pattern together with database replication.

Write operations continued to be processed by the primary database to ensure transactional consistency. Read-heavy workloads, including reporting, administrative dashboards, and analytical queries, were redirected to read replicas.

This separation reduced contention between transactional and analytical workloads while improving overall database performance.

The implementation also included SQL query optimization, index tuning for frequently accessed data, and background processing for operations that did not require immediate execution.

CQRS architecture

The backend was redesigned to clearly separate command and query responsibilities.

Commands responsible for creating, updating, and deleting data were processed through the primary database.

Queries used for reporting, dashboards, search, and administrative functionality were executed against replicated databases whenever possible.

This architecture reduced competition for database resources and allowed each workload to be optimized independently.

Database replication

Database replication was introduced to distribute read operations across replica instances.

The replication architecture provided:

  • A dedicated primary database for transactional writes;
  • Read replicas for reporting and analytical queries;
  • Separation of business-critical and reporting workloads;
  • Improved database availability;
  • Better utilization of infrastructure resources;
  • F foundation for future horizontal scaling.

Replication health and synchronization status were continuously monitored to detect delays and maintain reliable data access.

Database optimization

To improve overall performance, the project included several optimization activities:

  • Optimization of SQL queries;
  • Review of execution plans;
  • Index tuning for frequently used filters and joins;
  • Optimization of large tables;
  • Reduction of unnecessary database requests;
  • Background processing for long-running operations.

 

These improvements reduced query execution time and minimized unnecessary load on the primary database.

Result

The platform achieved significantly better database performance under high load.

By separating read and write operations, transactional workloads were isolated from reporting and administrative queries. Read replicas handled the majority of heavy query traffic, reducing pressure on the primary database.

The implemented architecture provided:

  • Lower load on the primary database;
  • Faster execution of read operations;
  • Safer execution of reporting and administrative queries;
  • Improved system stability during peak traffic;
  • Better database resource utilization;
  • Improved scalability of backend services;
  • Continuous monitoring of replication health;
  • A solid foundation for future platform growth.

Additionally, we will highlight the achievements in stability under load: business-critical transactions remained isolated from resource-intensive reporting and analytical workloads. And also in the scalability: the new architecture provides a scalable foundation for handling increasing traffic and future platform expansion.

CQRS implementation

Read and write operations were separated, allowing each workload to be optimized independently.

Database replication

Read replicas significantly reduced the load on the primary database while improving performance for reporting and administrative functionality.

Performance optimization

SQL optimization and indexing improved response times for large datasets and frequently executed queries.

Take a look