Java Layer 4 LB
A custom Java NIO TCP Layer 4 load balancer that forwards raw bytes between clients and backend servers using a single-threaded selector loop.
The Narrative
Engineered a TCP Layer 4 load balancer using Java NIO to manage non-blocking I/O and multiplexing across a single-threaded Selector event loop.
Implemented deterministic backend routing algorithms, including IP Hash and Round Robin, alongside passive health checking and cooldown tracking.
Optimized proxy throughput by designing a bidirectional byte forwarding architecture that leverages reusable zero-copy direct memory buffers.
Built out robust operational features including structured event logging, periodic metric telemetry, and graceful JVM shutdown coordination.
Tags
Links
System Highlights
NIO Concurrency
Single-threaded Java NIO Selector handles OP_ACCEPT, OP_CONNECT, and OP_READ efficiently.
Load Balancing
Supports both IP Hash and Round Robin distribution with intelligent unhealthy node skipping.
Zero-Copy Memory
Bidirectional byte forwarding utilizes reusable direct buffers to minimize GC overhead.
Observability
Integrated structured event logs and real-time counter metrics for connection and throughput analysis.