Redundancy and Failover
Redundancy is keeping extra copies of a part, so the system keeps working when one copy fails. Failover is switching work to a working copy when the first copy stops.
Server A answers while it is up
Two app servers sit behind the load balancer and server A is up. Every request lands on A.
a_alive = True
destinations = []
for request in range(3):
destinations.append("A" if a_alive else "B")
print("destinations:", destinations)After A stops, every request lands on B
A flag marks server A as stopped and the balancer switches the destination. Every later request lands on B.
a_alive = False
destinations = []
for request in range(3):
destinations.append("A" if a_alive else "B")
print("destinations:", destinations)Picking the first working server
Server A is stopped and server B is working. The picker skips A and chooses B.
servers = [("A", False), ("B", True)]
def pick(servers):
for name, alive in servers:
if alive:
return name
print("chosen server:", pick(servers))Example
a_alive = True
destinations = []
for number in range(1, 6):
if number == 3:
a_alive = False
destinations.append("A" if a_alive else "B")
print("request", number, "->", destinations[-1])
print("A answers:", destinations.count("A"))
print("B answers:", destinations.count("B"))Key points
- Redundancy: Keeping extra copies of a part beyond the one in use.
- Failover: Switching work to a working copy when the first copy stops.
- Spare copy: An extra copy that answers nothing until failover sends work to it.
- Load balancer role: The load balancer sends each request to a server, so it is the part that can switch the destination.
- No spare, no failover: Failover needs a working copy waiting, or there is nothing to switch to.
In this example, server A answers the first 2 requests and then stops. Failover sends the remaining 3 requests to B, so no request is lost when A stops.
Note
Redundancy supplies the spare copies, and failover is the switch that uses them.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
Server A stops and the load balancer starts sending every request to the waiting server B. What is that switch called?