Unit 3.4: Load Balancing - Layer 4 (Network)
Introduction
Behind FinCorp's public edge sits a payment-switch service on the data LAN. It speaks its own TCP protocol with mutual TLS, and the risk office requires the certificates to stay on the servers that own them. No component in the middle may decrypt that traffic. This is the case for Layer 4: balance connections, check health, and leave the payload untouched.
This unit designs the NLB as the private balancer of the layered architecture and composes it with the ALB from Unit 3.3. It ends by building the private NLB in fc-prod-fra-core.
1. Layer 4 Mechanics and Design
1.1 What the NLB Does
The NLB provides connection-based Layer 4 balancing for TCP. It is a proxy: client connections terminate at the balancer and map 1:1 to connections the balancer initiates to the targets, which is called two-arm load balancing. It performs destination NAT (DNAT) to map clients to targets; Source NAT (SNAT) is not supported, so targets cannot initiate connections through it.
The NLB distributes any TCP-based traffic, including HTTP and HTTPS, but its rules and health checks are strictly TCP-based. It cannot route on a URL, and it has no HTTP health check. Encrypted traffic passes through as TCP, so the backend keeps the certificate and completes the TLS handshake itself. That is exactly what end-to-end encryption and non-HTTP protocols need.
The NLB has a single listener interface that can carry multiple IPs with different forwarding rules. Its listener is public, with a reserved public IP, or private, on a private network for east-west traffic. On the target side, the backend presents a private IP to targets as the source of client traffic, derived from the target network's mask and set to x.x.x.225 by default. Multiple backend IPs can be configured with different rules.
1.2 Algorithms, Stickiness and Weights
Each forwarding rule selects an algorithm: Round Robin, Least connections, Random or Source IP. Independently of the algorithm, the NLB keeps active sessions mapped to the same targets (sticky sessions by source IP affinity) for as long as the TCP sessions stay active.
The choice matters for TLS on the backend. With Least connections, successive requests of a client may reach different backends, and if each backend holds a different certificate for the same domain, for example from separate Let's Encrypt setups, TLS handshakes can fail. Select Source IP to keep a client on one server, or use the same certificate on all backend instances.
Weights turn the NLB into a canary tool. Traffic is distributed in proportion to each target's weight relative to the combined weight of all targets; the default is 1 and the maximum 256. A new build registered with weight 1 next to two existing targets with weight 19 receives about 1 in 39 new connections. Raise its weight step by step while the flow logs and the service's own metrics stay clean.
1.3 Health Checks and Timeouts
Health checks are per forwarding rule and TCP-based. The following defaults apply:
| Setting | Default | Meaning |
|---|---|---|
| Client timeout | 50000 ms | Inactivity time before the NLB breaks an established client connection |
| Connection timeout | 5000 ms | Maximum wait for a server response before the server is considered unhealthy |
| Target timeout | 50000 ms | Maximum wait for a response during a health check |
| Retries | 3 | Attempts before a target is marked unhealthy |
As shown above, the defaults suit long-lived connections. For a payment switch with short transactions, tighter connection and target timeouts shorten detection, at the price of more false positives under load. A TCP check proves that the port accepts connections, not that the service is correct; pair it with application monitoring (Unit 7.2).
1.4 Composition and Its Controls
The ALB and NLB can be stacked for sequential traffic balancing. FinCorp's path is a public ALB on fc-edge that terminates customer TLS and routes by path, stateless portal servers on fc-app, and a private NLB whose listener sits on fc-app and whose backend sits on fc-data. The data LAN keeps no internet access element.
Network Security Groups attach to VMs and NICs, not to the balancers. The NLB comes with basic firewall rules applied automatically from its forwarding rules, which cannot be changed, and additional firewall rules belong on the NICs of the targets. The data-tier NSG therefore allows the service port from the NLB backend address only (Unit 3.2). For evidence, flow logs on the target NICs record what reaches the data tier; flow logs on the NLB itself cover its public interfaces, and access logging is available for newly created NLBs in non-US data centers once central logging is enabled.
| Option | Advantages | Disadvantages | Best for |
|---|---|---|---|
| Private NLB | TCP pass-through, certificates stay on targets, low overhead | No URL routing, TCP health checks only | Databases, brokers, custom TCP protocols, end-to-end TLS |
| Private ALB | HTTP routing and HTTP health checks east-west | Terminates TLS; billed per forwarding rule | Internal HTTP APIs that need path routing |
| Direct LAN access | No balancer cost | No health-based failover; clients track server addresses | A single target or a cluster with its own failover |
Pricing follows the same model as the ALB: 0,02 € per hour per rule for the first five forwarding rules, 0,01 € for each additional rule, and no processing fee. A contract holds five NLBs by default, adjustable through IONOS CLOUD Support. The NLB is maintained every Monday between 02:00 and 04:00 local time, with an interruption of up to 5 seconds.
DCD Implementation Walkthrough
You will add a private NLB between fc-app and fc-data in fc-prod-fra-core, balancing the payment switch on fc-data-01 and fc-data-02. The NLB needs its targets provisioned already.
Prerequisites: the servers and LANs from Unit 3.1, provisioned; fc-nsg-data from Unit 3.2; a free address between .2 and .9 on fc-app for the listener.
Build goal: Build a private Layer 4 balancer in front of the data tier.
Steps (in the Data Center Designer):
- Open
fc-prod-fra-coreand drag the NLB element into the Workspace. - Connect the Northern Interface (the listener) to the
fc-appLAN and the Southern Interface (the backend) to thefc-dataLAN. - In the Settings tab, enter the Name
fc-nlb-data. In Primary IPv4, enter the planned private listener address from .2 to .9 directly, or leave it Automatic to receive a private address on provisioning. - In the Forwarding rules tab, select + Add forwarding rules. Enter a Name, select Algorithm Source IP, keep Protocol
TCP, choose the Listener IP and the service's Listener Port, and select Create. - Select Add target. Choose the Target IP of
fc-data-01, the Target port, Weight1and Proxy Protocolnone, and select Add Target. Repeat forfc-data-02. - Select Settings next to Health Check and set Client timeout, Connection timeout, Target timeout and Retries for the service.
- Open the Private IPs tab. Keep the default backend address
.225onfc-dataunless it conflicts; to change it, remove the address first and add the new one in CIDR notation matching the target network's mask. - Provision the changes. Afterwards, confirm that the source in
fc-nsg-datais the backend address shown in Private IPs.
Common mistakes:
- Expecting the NLB to terminate TLS or route by URL. It forwards TCP; use the ALB for HTTP logic.
- Choosing Least connections in front of servers with different certificates for the same name. Use Source IP or one certificate.
- Allowing client addresses in the data-tier NSG. The targets see the NLB backend address.
- Placing a server on
.225of the target LAN. - Expecting data servers to reach the internet through the NLB. It does not support SNAT; use the NAT Gateway (Unit 3.6).
Summary
The NLB is the Layer 4 half of the layered design. It proxies TCP connections to healthy targets with sticky sessions, weights and four algorithms, and leaves the payload and its certificates on the backend. FinCorp stacks a public ALB in front of a private NLB, keeps the data LAN without internet access, and filters the targets against the balancer's backend address.
Key Points:
- The NLB is a TCP proxy with DNAT to targets and no SNAT; rules and health checks are TCP only.
- Use the NLB for non-HTTP protocols and end-to-end TLS; the backend keeps the certificate.
- Weights from 1 to 256 set proportional shares, which makes canary releases a weight change.
- Targets see the backend address, by default
.225; NSGs on the targets allow that address.
Important Terminology:
- Two-arm load balancing: a proxy design with one interface facing clients and one facing targets, each connection mapped 1:1.
- Source IP affinity: keeping a client's active TCP sessions on the same target.