A proxy is a server software, typically installed in a separate machine, that forwards requests to servers on behalf of clients. When the proxy is in the local network of the client, it’s called simply proxy or forward proxy. If it is in the local network of the server, it’s called a reverse proxy. Proxies can add functionality to a system without having to change or even notify clients and servers.
What is a database proxy?#
A database proxy is a type of reverse proxy tailored to databases. It takes requests from clients like web applications and forwards them to a database server using configurations that are specific to databases. An intelligent database proxy understands SQL and is able to make decisions on how to treat requests based on configurable rules. This understanding of the database protocols and languages allows database proxies to add functionality, mainly in four categories:
- High availability. For example, automatic failover and transaction replay.
- Scalability: The ability to transparently add or remove nodes in the database cluster without having to reconfigure or restart an application.
- Integrations: For example, import or export data from and to Kafka topics or connect apps developed with a NoSQL database connector to SQL backends.
- Security: For example, establishing query y result limits or automatic data masking.
What are the advantages of database proxies?#
The main advantage of using a database proxy is that it isolates the database topology from application configuration:
- Developers don’t need to know about replicas or cluster nodes
- It all looks like a standalone database instance to developers
- DBAs can add or remove replicas and cluster nodes when needed
- No need for developers to implement things like load balancing or data masking
- Fewer code results in faster development, less maintenance, and greater reliability
- DBAs can make changes without interrupting applications
- They are transparent and hidden from application configuration
- Completely hide failures
- No need for developers to create new connections or retry transactions
- No need for DBAs to perform a manual failover after being alerted
What are the disadvantages of database proxies?#
When evaluating database proxies, you should consider the following:
- A database proxy is a new element in the infrastructure
- It requires configuration (always use a database proxy that offers good configuration options)
- It can increment costs
- Licenses or cloud usage (check licenses before picking a database proxy)
If your application connects to a single database instance and doesn’t require things such as high availability or scaling, a database proxy introduces more complexity than needed. However, if you need other features such as automatic data masking or transparent integrations with Kafka or NoSQL protocols, a database proxy is useful even if there’s no need for high availability and scaling.
How to use a database proxy?#
A database proxy is installed on a machine and configured to monitor the database nodes and handle requests according to specific requirements. For example, MariaDB MaxScale can be used for transparent read-write splitting where SQL inserts, deletes, and updates are routed to primary (or master) nodes, and SQL selects to replica nodes enabling zero-downtime scale (both up and down). You can see this in action in this video: