Follow along as we play “Survivor of the Wilderness” and explain how the peering algorithm behind Hive Video Optimization works, in terms anyone can easily understand.
What is an algorithm (simple explanation)
Suppose you’re not entirely familiar with the term “algorithm.” The first thing you’d do is probably look up its definition online, which would lead you to something like the following:
“In mathematics and computer science, an algorithm is a finite sequence of well-defined instructions, typically used to solve a class of specific problems or to perform a computation. Algorithms are used as specifications for performing calculations and data processing.”¹
This is “algorithm” defined by Wikipedia – quite frankly, a rather mind-numbing couple of sentences. This isn’t exactly easy to comprehend even to someone working with algorithms on a daily basis, let alone someone who hasn’t dealt with advanced math since high school.
Luckily, there is a much simpler way to think of algorithms: at its core, an algorithm is simply a routine.
At its core, any algorithm is simply a routine.
Now, everyone has a routine in their daily life. For example, you might have a morning routine: you get out of bed and do things like take a shower, brush your teeth, and have breakfast. Another good example is a workout: a specific sequence of exercises you normally do at the gym.
You could also think of it as a recipe: it’s a step-by-step sequence of actions to perform with food items. In a recipe, if you’re missing an ingredient, you can usually use a substitute – swap rosemary for thyme, for example.
All of the above are examples of algorithms. The algorithm we’re going to talk about here is simply the routine in which peers work to discover and communicate with other peers.
Let’s play: Survivor of the Wilderness
To bring this metaphor to life, think of the following scenario.
You are inside a helicopter, flying over the Alps.
Suddenly, your engine catches on fire, so you must land the helicopter. Although you’ve never performed an emergency landing before, you manage to land safely.
As you look around, you realize that you are surrounded by immense mountains that would be very difficult to traverse. On top of that, you don’t have any necessary gear or equipment with you.
Suddenly, you realize that a massive blizzard is coming your way. The wall of snow is so thick, that you can barely see your own fingers once it sets in.
You wander around in a daze until finally, you come across a cabin, where you find refuge from the storm.
To your surprise, there is an actual car inside the cabin, and there are keys in the ignition. You try to start the car, and the motor roars – the car seems to be in full working order.
You keep looking around until you find a couple of other valuable items: a radio and a map.
Now, you have a car, a radio, and a map of the area at your disposal. You start to examine the map, which looks something like this:
Looking at the map, you appear to be in the heart of this mountain range, completely surrounded by towering peaks.
On this map, you can also see a supply depot that you could reach if you cross the only bridge leading there.
There also seems to be a communications tower nearby, outside the mountainous area.
As you continue to scrutinize the map, you discover some notes about the area you’re in:
- There are other people in the valley with radios and vehicles.
- These people also need supplies: everyone needs to get to the depot to procure supplies.
- The bridge leading to the depot is very old: it will collapse if more than a single car is crossing it at a time.
- You are not allowed to walk alone. It’s extremely cold and bears are known to frequent the area, which is extremely dangerous, so you can’t really wander around.
Now, your main objective is pretty clear: to survive.
But you have to think not just about yourself, but other residents of the valley. For example, if you were to break the bridge that leads to the sole provisions depot, the entire village could perish. Conversely, if the villagers were to damage the bridge, your own survival might be at stake.
You now find yourself alone in the cabin, with just these three tools:
- A map of the area, with the bridge, supply depot, and communications tower marked.
- A radio that only has two functions:
– You can broadcast a signal that anyone within a mile will receive, and they can send a signal back to confirm they’ve received yours.
– You can dial a person or place directly (but at the moment, you only have the number for the telecommunications tower.)
- A car that only has fuel enough for a single trip: to the supply depot and back. Based on the size of the car, you estimate that you could only bring back a day’s worth of supplies.
Objective no.1: Contact others
How would you now try to contact the other people of the valley, given that you do not know where they are?
You can’t exactly send smoke signals, since there is a massive snowstorm outside.
You can try to shout, but no one can hear your voice through the thick blizzard.
Q: How would you try to contact others in the valley?
Now, you would probably try to use the tools at your disposal.
Say you try the first function of your radio and send out a broadcast signaling for help, saying something like: “I’m here in this cabin, is anyone around?”
To your delight, two people send a signal back saying “We are here!”, which confirms you are not alone. But there is still a storm (and bears!) outside, so you can’t really go out looking for them.
Q: How do you locate more people?
You’d probably try to dial the communications tower. Luckily, someone responds – and you learn there are more people in the area than just the two you found. There are more people stranded in the mountains, and you’re even able to get the numbers to contact them.
You reach out to the stranded ones and establish contact with them, letting them know you can coordinate and work together to get supplies but that all of you would not be able to cross the bridge together.
Objective no.2: Supply run
Now, you must coordinate a supply run.
Q: How do you coordinate a supply run?
- What would you try to find out from others you’ve established contact with?
- What information do you need to operate the supply run to minimize the risk of collapsing the only bridge?
- What types of inventory or supplies are you hoping the others have?
Essentially, what you most need to figure out is the inventory at everyone’s disposal.
In this scenario, you discover that everyone also has access to vehicles.
You discover that one person even has a larger truck that can transport up to 5 days’ worth of supplies (instead of just the 1-day stock that smaller cars can bring).
Now that you’re able to communicate with everyone, you’ve marked their locations on the map:
Q: Which vehicle do you choose to send for the supply run?
The answer might be obvious: you send the driver of the largest car to bring 5 days’ worth of supplies.
But there are many of you, and you will still need more supplies. So you decide to send other drivers on supply runs too.
Q: The bridge can only handle the weight of one car at a time. How do you ensure they don’t overlap when crossing the bridge to avoid the bridge collapsing?
Since you can communicate now, you can establish a time frame and make sure each car only departs once the previous one has crossed the bridge.
Objective no.3: Backup plan
You’re very excited that your plan seems to be working. But you realize that there are still too many unknowns: what if one of the supply runners doesn’t make it through the storm? What if a wild bear attacks him while at the depot?
Q: What is your own contingency plan in case you don’t get supplies delivered?
Well, you do still have that car of your own. Since you know the timings of everyone’s runs, you decide to use your own car to bring back your own supplies as a backup.
Luckily, you’re successful. You bring back a day’s worth of supplies, and you now have both a plan A and B: you will survive the storm regardless of what happens.
The next day, you wake up to clear skies and the sound of helicopters coming to your rescue.
Congratulations, you’ve made it through!
“Survivor” as the Hive peering algorithm
Guess what? This game of “Survivor” is almost exactly how the peering algorithm behind Hive Video Optimization works.
This game of “Survivor” is almost exactly how the peering algorithm behind Hive Video Optimization works.
It’s very easy to draw parallels. Just think of the common constraints within the enterprise we are often faced with overcoming:
- A closed network (there are tall mountains all around!)
- An unknown number of peers within the network (we have no idea how many more people are stranded in the area)
- Single/limited access point (the single old bridge)
- Everyone wants fragments (people need supplies to survive the storm)
To solve this, we have implemented the peering algorithm.
On a very high level, its tasks are the following:
- Find eligible peers through:
a. UDP peer-to-peer connections (in the world of “Survivor,” use the radio broadcast to locate people close to you)
b. Tracker (This would be the radio tower that has been contacted by people in the area, and everyone reaches out to it first. Over the course of an event, the tracker builds up a large list of peers that any other peer can contact.
- Connect to peers
- Elect a leader
Once the peers are built up and connected, a “leader” with the strongest machine is elected.In our “Survivor” story, the leader is the driver of the largest truck that can carry 5 days’ worth of supplies, because that’s the person expected to carry the largest amount of load back.
- Request fragments
- Advertise fragments
Once the peers come back, peers are always requesting fragments, and those with an abundance of resources can advertise that they have fragments.
We didn’t do a deep dive into this bit in the game but think of it as stranded travelers requesting resources from others who have managed to complete a supply run.
And here is the last question of the game.
Q: What does you going to the supply depot yourself represent in the peering world?
Now that you have a much better understanding of peering, you can probably guess that you go back to the supply closet is exactly the behavior a peer can engage in. If the supply chain fails, there is always a contingency plan for the peer to go directly to the source, without relying on others to share fragments.
Curious to learn more about Hive? Our video experts are here to answer any questions you might have, regardless of whether you belong to an IT or HR team. Reach out to us for a free consultation on how to take your employee experience to the next level.