The Simplest Way to Make Haproxy and Tcp Proxies Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Teams use haproxy and tcp proxies together to route raw network traffic to backend servers. This pairing balances high traffic loads and keeps internal database ports hidden from the public web. Many apps need fast, stable links to databases and message queues. Standard web routers only understand web traffic, so they fail on raw data streams. By combining these tools, your team can direct packets across private networks with speed and control. This guide shows how data moves through these laye

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

Teams use haproxy and tcp proxies together to route raw network traffic to backend servers. This pairing balances high traffic loads and keeps internal database ports hidden from the public web.

Many apps need fast, stable links to databases and message queues. Standard web routers only understand web traffic, so they fail on raw data streams. By combining these tools, your team can direct packets across private networks with speed and control. This guide shows how data moves through these layers and how to fix common security gaps.

How data and logins flow through haproxy and tcp proxies

When a user or app starts a session, the request hits the outer load balancer first. This first layer checks the source IP address and looks at the target port number. It does not open the packet to read the database query or app command inside. Instead, it picks a healthy backend node and forwards the raw stream down the line.

Downstream tcp proxies take that stream and pass it to the final database or service. Because these tools work at the transport layer, they just move bytes back and forth. The client app still has to log in directly to the target database using a key. The network layer only decides if the packet can cross the wire to reach the host.

To keep traffic safe, teams set up mutual TLS between the outer balancer and inner nodes. Client certificates prove that traffic comes from a trusted source before any database login begins. Health checks run on a timer to test if backend ports still answer new requests. If a node fails a check, the router stops sending traffic to that dead address right away.

Common failure modes with shared keys and blind logs

Relying only on transport rules creates big blind spots for security and ops teams. Because raw routers only see IP addresses and ports, they cannot tell who ran a query. Logs only show bytes sent, bytes read, and how long the link stayed open. If someone drops a table, the network log will not show the SQL command used.

Teams often make this worse by giving every developer the same shared database password. When everyone logs in through the same network port with one key, accountability disappears. You cannot tie a bad write back to a single person on your team. Rotating that shared key also breaks scripts and apps across the whole company at once.

End-to-End Encryption + HAProxy Security: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Wide network paths create another big risk when teams open whole subnets to save time. If an attacker gets onto one app server, they can reach every database behind the router. To fix this, lock down network rules so each app only reaches its own target port. Create separate database roles for each service and give each role only the read or write rules it needs.

Setting up clear timeouts and health checks

Long-lived links can hang when a firewall drops idle packets without telling either side. When this happens, the app thinks the link is alive, but queries just stall out. Set clear idle timeout rules on both the outer balancer and the inner routing nodes. Keep these timers shorter than the firewall timeout so the router closes dead links cleanly.

Good health checks also stop traffic from hitting broken or booting backend servers. Simple port checks only prove that a machine is on, not that the service works. Set up your load balancer to wait for a real response byte before marking a node healthy. Drain active links before you shut down a node for updates so user queries never drop mid-flight.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.

First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

Why do raw transport routers miss database query logs?

Transport routers work at layer four and only read IP addresses and port numbers. They pass encrypted or raw byte streams straight through without opening the app payload inside.

Set your load balancer timeout lower than your cloud firewall timeout and turn on keepalive packets. This tells both sides to check the link often and close dead sockets cleanly.

Can we use client certificates to restrict who reaches a port?

Yes, you can require mutual TLS on the front listener to check client certificates first. The router drops any traffic that lacks a valid signed cert before forwarding a single byte.

The query runs. The emails stay hidden.