The Simplest Way to Make Haproxy and Jetty Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Using haproxy and jetty together routes incoming web traffic to fast Java backend servers. HAProxy balances the load at the edge while Jetty runs your core web apps. Teams choose this pair to handle high traffic volumes without dropping user requests. HAProxy takes the public hit and checks which backend nodes are awake. Jetty stays inside the private network and focuses on running Java code. This split keeps your system fast, safe, and easy to scale under load. How traffic flows between hapr

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.

Using haproxy and jetty together routes incoming web traffic to fast Java backend servers. HAProxy balances the load at the edge while Jetty runs your core web apps.

Teams choose this pair to handle high traffic volumes without dropping user requests. HAProxy takes the public hit and checks which backend nodes are awake. Jetty stays inside the private network and focuses on running Java code. This split keeps your system fast, safe, and easy to scale under load.

How traffic flows between haproxy and jetty

A user sends a web request to the public IP address of HAProxy. HAProxy checks the request, handles TLS keys, and picks a healthy Jetty server. Then HAProxy sends the plain or encrypted traffic over a private network path. Jetty reads the request, runs the Java app logic, and returns the response.

To keep user details intact, HAProxy adds forwarding headers to each request. These headers hold the real client IP address and the original web protocol. You must set up Jetty to read and trust these forwarded headers. Otherwise, Jetty logs every single request as coming from the HAProxy server address.

Log in checks and role checks can happen at both layers. HAProxy can block bad traffic at the edge or verify client certificates first. Jetty then checks app roles and user sessions before it reads database records. When both tools share clear trust rules, requests move fast and stay safe.

Common failure modes and how to fix them

Many teams leave Jetty ports open to the whole internal network by mistake. Any server on the network can then bypass HAProxy and hit Jetty directly. You should lock down firewall rules so Jetty only accepts traffic from HAProxy. This network rule forces every call through your main front door.

Shared admin accounts and broad service tokens also create big risks for teams. Engineers often log in to Jetty boxes with one shared root key to debug issues. When someone changes a setting or breaks a rule, the logs show nothing useful. Instead, give each team member a unique role with small, clear permissions.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Timeout mismatches between the two tools cause dropped calls and angry users. If HAProxy closes idle links before Jetty finishes a task, users see errors. If Jetty drops links too fast, HAProxy might send traffic to a closed socket. Match your timeout values across both tools and test them under heavy load.

Keeping health checks and logs clean

HAProxy needs a fast way to check if each Jetty node is ready. Do not point health checks at heavy pages that run big database queries. Build a small status page in Jetty that returns a simple okay code. This keeps health checks light and stops HAProxy from overloading your backend apps.

Good logs help you fix bugs fast when production traffic spikes. Make sure HAProxy and Jetty use the same clock time and request IDs. HAProxy can tag each incoming call with a unique trace value in a header. Jetty can read that tag and write it into every local app log line.

Also watch out for sensitive data in your web server logs. Standard log formats might save query parameters that hold emails or phone numbers. Masking rules can rewrite matched fields like card numbers or national IDs in results. This keeps your central log files clean and safe for engineers to read.

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

Where should we handle TLS encryption with HAProxy and Jetty?

Most teams end public TLS at HAProxy to save CPU power on Jetty nodes. If your private network requires encryption, use internal certs between HAProxy and Jetty too.

Why does Jetty show the HAProxy IP address in all access logs?

Jetty logs the direct caller IP by default unless you enable forwarded header support. Turn on the forwarded request customizer in Jetty so it reads client headers from HAProxy.

How do we stop HAProxy from sending traffic to a restarting Jetty node?

Set up an HTTP health check in HAProxy that polls a Jetty status URL. Tell Jetty to return an error status code right before it begins a shutdown.

The query runs. The emails stay hidden.