| published by | simha srivatsa |
|---|---|
| in blog | Instawork Engineering |
| published date | 2024-06-28 |
| original entry | Overcoming database bottlenecks: A Journey with ProxySQL |

Startups grow fast, and scaling infrastructure to keep up can be challenging. As companies expand, efficiency, scalability, and reliability become crucial for smooth operations and meeting market demands. This blog post will discuss how ProxySQL, an advanced MySQL proxy server, helped us manage our SQL traffic and connections as we scaled.
Instawork faced a critical growth stage two years ago that began to strain our infrastructure. As our traffic peaked, it led to too many MySQL connections and frequent alerts because our Django app created a new database connection for every HTTP request.
MySQL’s blocking I/O and thread-per-connection model became a bottleneck as connections increased, making a strong connection pooling mechanism essential.
We had a primary database and multiple replicas, but without load balancing, traffic was uneven and resources were underused.
To solve our immediate problems, the most important features we cared about were connection pooling and load balancing. Any additional features were a bonus. We evaluated a few options that could meet our requirements against the list of features.

After careful consideration, ProxySQL stood out as the best option. It gave us what we wanted but had other features like query routing, caching and transaction support. We realised that transaction awareness is also a critical feature for an SQL proxy. All queries inside a transaction block must execute on the primary database, which ProxySQL gave us out of the box. Additionally, it had good community support to assist us when needed, making it an obvious choice
The next step was to integrate ProxySQL into our stack which uses the AWS Elastic Container Service (ECS).
We evaluated a few deployment options for ProxySQL within ECS:
We decided to start with the sidecar approach because of its simplicity. It allows us to explore ProxySQL’s functionalities thoroughly and understand its impact on our systems without making big changes to our infrastructure.
Integrating ProxySQL as a sidecar brought a mix of enhancements and some practical challenges. Here’s what we observed on production after routing our application’s database traffic through ProxySQL.
The Challenges:
After three months, it was clear that using ProxySQL brought big advantages, but the challenges made us think about switching to a clustered approach.
Here’s how we set up a ProxySQL cluster on ECS.

Cluster Configuration on ECS
Gains:
Drawbacks:
Despite the minor drawback, this setup proved more reliable because it performed better under peak and critical traffic.

Over the past two years, ProxySQL has been a great tool for managing our database traffic. We haven’t seen an alarm for excessive connections since then. It has also safeguarded our application from incidents like replica crashes. Additionally, it has streamlined our operations by helping with zero-downtime database upgrades and general database management.
Thank you for following our journey with ProxySQL. We truly appreciate your interest and hope that these insights have been helpful. Stay tuned for Part 2, where we will dive deeper into the techniques we used for administering and monitoring a ProxySQL cluster. See you soon!
Overcoming database bottlenecks: A Journey with ProxySQL was originally published in Instawork Engineering on Medium, where people are continuing the conversation by highlighting and responding to this story.