Back to Projects
Rex Server – Reverse Proxy & Load Balancer
Completednode.jsexpresstypescript+3 more

Rex Server – Reverse Proxy & Load Balancer

Technical deep‑dive for Rex Server, a Node.js-based reverse proxy and load balancer using master-worker clustering and YAML configuration.

Timeline

7 days

Role

Full Stack

Team

Solo

Status
Completed
Documentation
View Docs

Technology Stack

node.js
express
typescript
yaml
reverse-proxy
load-balancing

Key Challenges

  • Minimizing latency while proxying API and static requests across worker processes.
  • Designing a scalable master–worker cluster capable of automatically redistributing traffic when workers crash or restart.
  • Ensuring zero downtime during worker restarts and avoiding thundering-herd problems.
  • Building a custom routing engine that supports wildcard patterns, nested paths, and priority-based matching.
  • Handling tens of thousands of open HTTP connections efficiently without memory leaks.
  • Implementing robust YAML configuration validation and auto-reloading without breaking active requests.

Key Learnings

  • Deep understanding of Node.js event loop internals, worker_threads vs cluster module, IPC channels, and message passing.
  • Building high-performance HTTP reverse proxies using Node’s low-level http module instead of frameworks.
  • Optimizing network I/O, streaming responses, handling backpressure, and preventing stalled pipelines.
  • Implementing a master server architecture: worker lifecycle management, watchdog timers, and crash recovery.
  • Understanding Linux-level networking concepts like file descriptors, socket reuse, and connection draining.
  • Designing CLI tools using Node’s fs + YAML parsing + shell command orchestration.

Rex Server – Reverse Proxy & Load Balancer

Rex Server is a Node.js-based reverse proxy and load balancer distributed as an npm package. It uses a master–worker architecture for concurrency and reliability.

Features

  • Reverse proxying
  • Load balancing
  • Static file serving
  • YAML-based configuration
  • CLI workflow
  • Auto worker restart

Installation

npm install -g rex-server

Initialize:

rex --init

Config Example

server:
  instances:
    - port: 80
      public: "/absolute/path/to/public"
      routes:
        - path: "/api"
          destination: http://localhost:3000
        - path: "/*"
          destination: http://localhost:5173
workers: auto

Master–Worker Design

  • Master supervises workers
  • Workers handle requests
  • Auto‑restart on crash
  • Multi‑core utilization

CLI

rex --init
rex load rex.config.yaml
rex start
rex stop
rex stop -p <PID>

Routing Behavior

Example:

  • /api → backend API
  • /* → frontend fallback

Use Cases

  • Lightweight reverse proxy
  • Dev environment routing
  • Static hosting + backend APIs
  • NGiNX alternative for JS environments

Conclusion

Rex Server offers an easy, developer‑friendly way to run proxies and load balancers entirely in Node.js.

Design & Developed by Raghvendra Misra
© 2025. All rights reserved.