Two Generals Problem

Summary

There are two armies led by generals on either side of a castle. In order to win, both armies must attack at the same time. If only one army attacks, they will lose. The only means of communicating is via a messenger, who has to cross in front of the castle and may be killed along the way.

In order to coordinate the attack, general A can send a message to general B. But this raises an issue; how do we know if general B received the message? We have no way of knowing, except that general B may chose to send an acknowledgement message. But this messenger may also be killed, so how will general B know if general A acknowledges the acknowledgement?

This is the basic idea of the two generals problem. It's a classic unsolvable problem in distributed computing.

This problem can occur in the real world. For example, in 2018, a food-delivery company in the UK had a bug in their app. Customers would order food, and the app would say that there was an error, and to try again. BUT internally, the order was fulfilled properly. Customers did not know this, so they would order multiple times as instructed. This lead to many customers being charged for duplicate orders.

If the operation of ordering was idempotent however, this would not have occurred. This does not solve the issue of knowing if the first message got however. Idempotent tokens can be used to achieve this.