DEV Community

Cover image for First Reverse Proxy Built with Zig
Ali Amer
Ali Amer

Posted on

First Reverse Proxy Built with Zig

The first-ever reverse proxy built with Zig. If you're a developer, sysadmin, or just someone interested in optimizing web traffic handling, Cloud Cup may be your new favorite tool. It's lightweight, fast, and built to scale. And it's open-source!

In this blog, I'll walk you through Cloud Cup’s architecture and the challenges I faced while building it. I’ll also talk about how you can help shape the future of this project, suggest new features, and contribute. I am just getting started, and your feedback and support can make all the difference.
What is Cloud Cup?

What is Cloud Cup?

Cloud Cup is a reverse proxy and load balancer designed with simplicity and performance in mind. It helps route traffic between clients and backend servers, distributing the load evenly to avoid overloading any single server. But here’s the twist – Cloud Cup is built using Zig, a low-level language known for its performance and control over memory usage.

Unlike traditional reverse proxies, which can be heavy on resources, Cloud Cup is lightweight, optimized for speed, and easy to configure. I believe it’s the next big thing in reverse proxies, and I want you to be a part of it.

Architecture

Cloud Cup’s architecture is designed to be as efficient and scalable as possible, and it revolves around the Master-Worker pattern. Let’s break it down:

Master Process

The master process is the heart of Cloud Cup. Here's what it does:

  1. Configuration Management: The master process validates and applies configurations at startup, ensuring that everything is set up correctly before launching workers.

  2. Dynamic Hot Reloading: Through the CLI tool (called cupctl), Cloud Cup can hot reload its configurations without needing to restart the entire system. This allows for seamless updates and scaling on the fly.

  3. Worker Management: The master spawns multiple worker processes and ensures that they are always running. If a worker crashes, the master immediately spawns a replacement.

  4. CLI Listener: The master also manages the command-line interface, which lets you interact with Cloud Cup, run diagnostics, and apply updates.

Worker Process

The worker process is responsible for handling actual network traffic:

  1. Shared Port, Independent Threads: All workers listen on the same port, and the kernel manages the traffic distribution between them. Each worker has its own epoll instance for highly efficient I/O handling.

  2. Concurrency with Thread Pool: Each worker has a dedicated thread pool for handling requests concurrently, making Cloud Cup highly scalable and responsive.

  3. Configuration Updates: The workers dynamically receive updates from the master process, so configuration changes are applied across all workers instantly and consistently.

Challenges I Faced

Building Cloud Cup wasn’t without its challenges. Since I'm working with Zig, a language that is still relatively new in the ecosystem, I faced a steep learning curve when it came to optimizing networking performance and ensuring memory safety. But I was determined to keep the project lightweight, efficient, and easy to use.

Some of the challenges I overcame include:

  • Memory Management: Zig’s manual memory management gave us more control, but also required careful handling to avoid memory leaks or crashes. I've worked hard to ensure that Cloud Cup’s memory footprint remains minimal while still delivering high performance.

  • Concurrency and Scalability: I wanted Cloud Cup to handle heavy loads without sacrificing performance. Building the master-worker architecture allowed us to handle traffic distribution efficiently while maintaining responsiveness.

But I'm not done yet! I'm actively working on adding more features and improving performance even further.

How Can You Contribute?

As Cloud Cup is still in its early stages, I’d love your help! Whether you're a developer, tester, or just someone who wants to try out new software, you can contribute in many ways:

  • Feature Requests: Is there something you’d love to see in Cloud Cup? I'm listening! Submit your ideas, and I will review them.

  • Bug Reports: Encountered a bug? Let me know so I can fix it. Your feedback helps make Cloud Cup better for everyone.

  • Code Contributions: If you’re interested in contributing code, check out GitHub repo. I'd be happy to accept pull requests for new features or bug fixes.

  • Suggestions: Have suggestions on how I can improve documentation or features? Drop me a message. I want to make Cloud Cup as user-friendly as possible.

You can find all the information you need for contributing in our CONTRIBUTING.md file.
What’s Next?

I'm just getting started with Cloud Cup, but I already have big plans for future updates. In the next releases, I'm planning to improve:

  • Performance: Always looking to make Cloud Cup even faster!
  • Features: More advanced load balancing options and enhanced configuration management.
  • Documentation: I am committed to improving the docs, making it easier for developers to get started with Cloud Cup.

If you're passionate about reverse proxies, load balancing, or just want to see Cloud Cup grow, consider supporting me on our Patreon. Every bit of support helps me keep building and adding new features.

I Need Your Feedback!

I want to make Cloud Cup the best reverse proxy tool out there, and for that, I need your feedback. Whether it’s a suggestion for a new feature, an improvement to the documentation, or a bug you’ve encountered, I want to hear from you.

You can reach out via:

I am really excited about Cloud Cup, and I hope you’ll join me on this journey. Help me build the future of reverse proxies, one feature at a time!

Thanks for reading, and I can’t wait to hear what you think!

Github: https://github.com/cloud-cup/cloud-cup
DOC: https://cloud-cup.netlify.app/

Top comments (0)