Introducing FLOP
I recently updated my resume with some new projects I have been working on. I realized they were all written in Python. This was mainly out of necessity for the nature of the project as they were on tight time constraints and Python is fundamentally a rapid development language. As such, I realized I need to create a project using my favorite language, java!
Introducing FLOP! Flop is short for Flexible Load Optimizing Proxy. It will essentially function as a balancer and implement some useful algorithms needed in a web context.
What is a Load Balancer?
Overview
A load balancer does exactly what you think: it balances a load. In this context, they dynamically distribute traffic across a resource network. Imagine if this blog was extremely popular and I hosted the site myself. Lets say my site was getting 10,000 connection requests per hour. If I had two servers, each capable of handling 5,000 requests per hour, I would need a way to split the traffic between the two so one didn't get overloaded. That is where a load balancer comes in. It ensures that everyone trying to access the site gets a fast and smooth experience. If one server went down, the load balancer would instantly see this and redirect all traffic to the healthy servers.
Think of a load balancer as a traffic cop directing cars on a busy highway. Instead of cars, it is directing website visitors and other digital traffic. Its job is to make sure that no single lane (server) gets jammed and that everyone reaches their desired destination quickly, efficiently, and without any slowdowns.
Load balancers, like a traffic cop, have many different strategies for directing this traffic. They might send it to the server with the fewest active connections, or the one responding the fastest. They always try to route to the server with the best performance.
This technology is present everywhere on the internet. For example, Netflix has over 300 million users. They don't have just one server handling everyone streaming at once. They are spread across many servers all over the world. If one server goes down, all traffic is routed to another, and so on. This is one of those technologies you are using without even realizing!
How Does it Work?
Another good real-world analogy for a load balancer is a restaurant. Typically, a restaurant is structured like so:
- Host: greets guests and directs them to an available server
- Server: takes a customer's order and delivers their food
- Manager: keeps track of who's available and how busty they are
In this project, the code is structured just like this restaurant.
The Host
At the highest level, we have the host, housed within our LoadBalancer.java
class. This is the main entry point of the system. It receives incoming "guests" (requests) and chooses which server should handle them.
The Servers
Our servers are represented by the BackendServer.java
class. Each instance corresponds to a real backend server and keeps track of its address and status.
The Routing Strategy
Next, we have to define rules for how the load balancer chooses which server to give requests. For now, I am implementing a "Round Robin Router," which picks servers one by one in a repeating cycle. There are many different algorithms that accomplish this, but this one is a good for a beginner like myself.
The Health Inspector
Similar to how restaurants get audited by the health department to ensure they are operating in a safe manner, our servers have to be audited to ensure they are healthy. HealthChecker.java
does this. it periodically checks on the servers, and if one crashes or becomes slow, it stops sending traffic to it until it is back up. This is imperative for continual operation.
The Employee Roster
Finally, we have the "employee roster." servers.json
serves as as list of servers that the load balancer can send traffic to.
Summary
FLOP is a realistic simulation of a modern web load balancer, built from scratch in Java. It demonstrates:
- Networking
- Concurrency
- Object-oriented design
- Systems design
It is my way of getting deeper into Java while learning more about how the internet works!
Thanks as always for reading, and stay sharp!