The Two Generals’ Problem

  • Published on Aug 12, 2019
  • Time to tell a story about idempotency, computer science, and the Night of the Multiple Orders. • Sponsored by Dashlane -try 30 days for free at:
    Written by Sean M Elliott and Tom Scott
    Directed by Tomek
    Graphics by Mooviemakers
    Audio mix by Haerther Productions
    Thanks to Dashlane for sponsoring the video! If you're techie enough to watch this video, you should be using a password manager. Get a 30-day free trial at
    I'm at
    on Twitter at
    on Facebook at
    and on Instagram as tomscottgo

Comments • 1 905

  • Tom Scott
    Tom Scott  22 days ago +2420

    Yes, I had help with the graphics for this series. There's no way I'd have animated that myself! On that note, thanks to Dashlane for sponsoring and helping me hire an animator: their free trial link is

    • Andrew F
      Andrew F 4 hours ago

      How is it unsolvable? Wouldn't you just need a maximum of two confirmations sent in order after the original message? If you get at least one confirmation in the correct order after the original message then you know both parties received the original, right? What am I not understanding here?

    • john smith
      john smith 8 hours ago +1

      who would put the castle in the valley but a computer tech

      ERMAN ATES 15 hours ago

      It was very well put. Animations were only fabulous. Thanks

    • John Jennings
      John Jennings 2 days ago

      Glad to know Dashlane is sponsoring you and you trust them! Been using them for 3 years now

    • Treqqing
      Treqqing 2 days ago

      Could you do an episode on the flat earth

  • Ricky
    Ricky 22 minutes ago

    The great part of this episode of the basics is that it is more like 2 episodes, one about the generals problem, and one about password managers.

  • a z
    a z Hour ago

    The two general's problem is nonsenical because war is never planned and structured this way. Instead the following applies:
    There will be ONE general and TWO commanders each commandeering one army. The general plans and sends messages to the commanders and they execute his/her commands relaying relevant feedback to the general so the general has realtime information on the state of play from the perspective of each commander. Extrapolating, you see this in IT in every large corporate as the admin (or general) sends out messages to each commander (each computer attached to the corporate network) with the computers relaying realtime statuses back to the admin.
    By contrast the foodordering problem is one of STRUCTURE and is analogous to the following battle structure. you are the general, you have one army and one commander but the army is fragmented into different specialisms (eg tanks, jet fighters, ground soldiers etc etc ) with each specialism controlled by a lieutenant. The structure SHOULD BE that the general commands the commander and the commander relays to each lieutenant HOWEVER some of the lieutenants are BYPASSING the commander and relaying directly to the general thereby creating INFORMATION-CONFUSION, and this is combined with the fact information lines between the general and the commander have been cut. The general thus doesn't have correct realtime information.
    Therefore the solution is that the lieutenants ONLY exchange information with the commander and anytime general-commander information lines are cut the commander issues a "STOP WHAT YOU ARE DOING" command to every lieutenant.
    Extrapolating and applying this to the food ordering system, the user (general) is communicating with the app (commander), the app then communicates to each lieutenant (eg food ordering, delivery, payment etc etc) and anytime the information line between user-general and app-commander is cut the app-commander issues a "STOP WHAT YOU ARE DOING" command to every lieutenant

  • Neodimium
    Neodimium Hour ago

    The solution is send them information in quantum entanglement state. (-;

  • Wolf Slayer
    Wolf Slayer Hour ago

    even thieves can't avoid a traceable digital fingerprint....just a logical fact.

  • 4our 20wenty
    4our 20wenty 3 hours ago

    The actual same thing happens to me

  • Louis Wouters
    Louis Wouters 3 hours ago

    But they don't know that we know they know!

  • Ursula Panzer
    Ursula Panzer 4 hours ago

    Just go around the castle and talk to them

  • Vagabond Wastrel
    Vagabond Wastrel 4 hours ago

    obviously war drums or bag pipes.

  • The Sinful Gamer
    The Sinful Gamer 5 hours ago

    That problem isn't nearly that difficult. Once A has sent B a message, B sends a message back, confirming they got that message, A then sends a confirmation that they have indeed got the message, if they get a reply to that message, they are all good, considering they both at this point understand at 8pm they would attack, both would attack.

  • Matt Kazachinsky
    Matt Kazachinsky 6 hours ago

    Am I the only one that got an ad for that same company?

  • ano nym
    ano nym 8 hours ago

    Couldn't the message chain be:
    Red: We attack at 8PM.
    Blue: we both Attack at 8PM, please confirm that this message is recieved.
    Red: Your message is recieved, we will both attack at 8.
    Regardless of if the last message makes it, they will both have the agreement to attack.

  • FateEntity
    FateEntity 10 hours ago

    Video IMMEDIATELY jumps into it and I felt lost and confused about what was going on. Maybe have a small few second intro or a preface? Disliked.

  • TechByte
    TechByte 10 hours ago

    So how exactly does this fix the two generals problem? There’s still now way for each general to know if his message made it...

  • terrorzilla
    terrorzilla 10 hours ago

    Had a similar problem ordering pizza in the USA recently. I actually got the order acknowledgement and tracker notice after the pizza arrived. Like you, I suspected it had worked and was right.

  • Famalamadingdong GE/PD
    Famalamadingdong GE/PD 11 hours ago

    Suggest recipes for Tom to cook tbh

  • Mohsen Javaed
    Mohsen Javaed 11 hours ago


  • Cheese Borger
    Cheese Borger 12 hours ago

    These comments are excellent, wish I could see them more than once!

  • Cheese Borger
    Cheese Borger 12 hours ago

    These comments are excellent, wish I could see them more than once!

  • Sean Webb
    Sean Webb 12 hours ago

    Captain Kirk would have solved the problem.

  • Paul Anderson
    Paul Anderson 13 hours ago

    Figured it out - the general would turn his entire division, including himself into messengers. Crisis averted, you're welcome.

  • shake bake
    shake bake 14 hours ago

    Please do a video that explains to us simple/matrix folk, why we have to enjure annoying adverts that nobody acknowledge's, understands or care's for. Let alone ever buys from? The moon landing or 9/11 makes more sense 🚀🙄

  • Gold Fishy
    Gold Fishy 15 hours ago

    But his token solution doesn’t actually solve the generals problem presented in the beginning. However, a solution to the generals problem was discovered in 2009. That solution was Bitcoin. Seriously. Google it.

  • SnipahWoolF
    SnipahWoolF 15 hours ago

    Wrong! there is a solution for this Problem, it's called quantum entanglement.

  • Luny Moon
    Luny Moon 15 hours ago

    Couldn't you just have the messengers meet in the middle, shout the time, and then run back quick as they can?

  • Dank_Bandit
    Dank_Bandit 16 hours ago

    To solve the two generals problem, just tell the other side to raise tall flags before the attack begins to signal that its time. Is there some way that wouldn't work? Both sides of the valley are above the castle so that won't be blocking their view.

  • Kronus Exodues
    Kronus Exodues 18 hours ago

    okay, what about the solution of brute forcing this?
    A sends B a hundred messages that they'll attack at midnight. many of them might get decepted, but a few ought to get through. A then just relies on the brute force being successful, B relies on A relying on it, both attack at midnight and win. and if B gets that message multiple times, that's no tragetdy either.
    Is that brute force approach something that get's done in practice?

  • GoodISnipr
    GoodISnipr 19 hours ago

    Call of Duty is a game of Rock, Paper, Scissors.
    Play split screen local.
    Choose a loadout. Only 1.
    The other player, if they see what you chose, can then choose their loadout to have a very high kill/death ratio.
    But, this is why there are 5 custom loadout slots. Use them wisely and then take what you've learned and apply the principles in reality.

  • Tevan Pinrut
    Tevan Pinrut 20 hours ago

    Power to the deliveroo strikers tho

  • StoneyGames
    StoneyGames 21 hour ago

    got randomly recommended this video an hour after it came out......... i am now subbed and have been bingeing your videos

  • Clarence's Real Life
    Clarence's Real Life 21 hour ago

    why did I watch this so long hahaha

  • Nathaniel Echeverria
    Nathaniel Echeverria 21 hour ago

    Walk around

  • jimifloydrix
    jimifloydrix 21 hour ago

    Re: idempotency. How does the phone know that it's the same order twice? How do you prevent the phone from creating a new idempotency key the second time you request something?

  • Nil Haul
    Nil Haul 21 hour ago

    Quantum computing

    • Ask to seduce Miss
      Ask to seduce Miss 21 hour ago

      attack from different locations then one of the Generals takes their army there and waits for the agreed time.

  • Chuck
    Chuck 22 hours ago

    Only drawback to Dashlane is cost. Free as single use, but to sync it is expensive..

    • Ask to seduce Miss
      Ask to seduce Miss 21 hour ago

      Solution: General A marches his army through the danger zone suffers losses and meets up with General B and army. They agree to attack at a set time. If it’s important that t

  • Jimmy Jams
    Jimmy Jams 22 hours ago

    Take the long way round, at night?

  • filevans
    filevans 22 hours ago

    where do they ever put castles in valleys? I've never seen one, all the ones I've seen are on hilltops

  • Prof.Tu.nichts
    Prof.Tu.nichts 23 hours ago

    Use Smoke signs

  • Tay Woode
    Tay Woode Day ago

    I almost read the title as “The two genders problem” and was about to comment that there is only two genders, not 72 😂

  • Ultra .26
    Ultra .26 Day ago

    I thought it said the 2 genders problem

  • Leopard Bra Brado
    Leopard Bra Brado Day ago +3

    not accurate, a castlee would have been built on the highest point :)

    • Logan
      Logan 13 hours ago +1

      Not neccessarily if the valley is an important trade route and it is surrounded my steep cliffs

  • Umar Abd Aziz
    Umar Abd Aziz Day ago

    If army A and B had send messages back and forth mentioning attack time at 8 pm, wouldn't you kinda know that 8 pm Is confirmed already?

    • Leopard Bra Brado
      Leopard Bra Brado Day ago

      army have received the message and both will attack at the same time.

  • oldcowbb
    oldcowbb Day ago

    i was very skeptical of dashlane, but now it is tom scott verified, hmmm

  • Shemsy
    Shemsy Day ago

    Why not use a a pigeon?

  • Udai Kumar
    Udai Kumar Day ago +2

    My IQ increases watching even a single Tom Scott video.

  • Mercury2wo
    Mercury2wo Day ago

    So I understood the concept of “imdepotency” (forgive the miss-spelling) but how does that solve the “2 Generals Problem” who want to attack at the same time?

  • Mitchell Wong Ho

    Best narration of Game of Thrones ever!

  • Stalking Like Candy

    Is Tom 20 or 50?

  • Luna Protege
    Luna Protege Day ago

    How does Hashgraph solve this?

  • Danté
    Danté Day ago +1

    A sends a messenger, then B sends a messenger halfway back with A's messenger, and they both leave from the castle to their respective armies making sure the other makes it past the castle, then both armies know the message has been sent. This wouldn't apply to coding, but it follows the rules of the riddle.

  • Mark Hansen Music

    Solution: General A marches his army through the danger zone suffers losses and meets up with General B and army. They agree to attack at a set time. If it’s important that they attack from different locations then one of the Generals takes their army there and waits for the agreed time.

  • MightyElemental
    MightyElemental Day ago

    I had this exact problem when buying plane tickets. So I ended up buying duplicate plane tickets.

  • 112steinway
    112steinway Day ago

    I'm sorry, but if someone is stupid enough to build a fortress at the bottom of a valley like that AND allow two armies to surround them like that...then they're not very good at their jobs.

  • Everyday Learner

    Where and when did the problem happened? Is there a captain here?

  • CommanderS
    CommanderS Day ago

    Wow, this is a really interesting problem I hadn't thought about before. Thanks, Tom!

  • Blinded Toaster
    Blinded Toaster Day ago

    Send the original messanger back. Jesus it's so simple.

    • Louis Wouters
      Louis Wouters 3 hours ago

      In both cases B won't know that A received the confirmation so they will nkt attack, because they can't be sure that A is going to attack

  • A VERY horny Mr.Dinosaur

    but did you _REALLY_ order that food, or was it just for the story purposes?

  • RaisedByCats
    RaisedByCats Day ago

    What if both generals send a messenger simultaneously. The messengers meet in the middle and negotiate a time for the attack. Once agreed on a time, they each set off back to their home base. If one is killed, the other messenger sees that, knows the attack is off and relays that information to their general. When the dead messenger doesn't come back, their general knows no agreement was made on timing and that the attack is off. If both are killed, neither returns and the generals know the attack is off. If one or both messengers are killed, the generals send another two messengers to try again. However, if both messengers return, they both have knowledge of the timing of the attack and that the other messenger wasn't killed.

  • F M
    F M Day ago +1

    What about creating a third army consisting of soldiers from both armies and place it in the middle where the original armies can view it and attack when the new army attacks. A third reliable server, perhaps a satellite can solve this issue by receiving and recording data from both parties and re-communicate what it received to assure correct information during transactions. Expensive, but solvable.
    Edit: Another simpler solution is to not to attack until the same messenger sent has arrived back, which would assure the other army have received the message and both will attack at the same time.

  • leonselbst
    leonselbst Day ago

    not accurate, a castlee would have been built on the highest point :)

  • xcheesyindianx
    xcheesyindianx Day ago

    To be honest, the biggest problem I see is that someone put a fort in a valley and not at the top of one of the hills...

  • Joel Walby
    Joel Walby Day ago

    Also a situation where a fast cryptocurrency could be used. To reliably prove a transaction has taken place.

  • pixlion
    pixlion Day ago

    If there’s one known point that the chance of failure to send the message always happens at. What if you send two messengers, and at that point one goes back while the other continues, the one that went back can tell wether the other succeeded or not. And in the event it works they can storm the fortress together.

  • OrcinusDrake
    OrcinusDrake Day ago

    I don't get it, didn't you just solve the problem?
    General A sends the message and asks for a confirmation. They wait the return trip, if confirmation arrives great. If it doesn't arrive then resend the message.
    General B receives the message, then responds with the confirmation. They assume the confirmation was a success unless they receive the same message again, in which case they just resend their confirmation.

  • Rem Sutton
    Rem Sutton Day ago

    This happened to me on saturday with uber eats

  • spam onme
    spam onme Day ago

    Way back in 2000 JSP had session IDs, to help mitigate this problem.

  • Lol Xava
    Lol Xava Day ago +1

    Is USclip your full time job??

  • Dingo Prod
    Dingo Prod Day ago

    really interesting :-)

  • Reid Wallace
    Reid Wallace Day ago

    Rather than feeling you have to choose between trusting your credit card info to a poorly coded app OR cooking yourself... you could phone a restaurant that still employes its own delivery staff... and order food the way that involves somebody being payed decently and not have to worry about some 'disruptive' big tech nonsense resulting in a 90 minute wait for pizza.

  • Kev Parkin
    Kev Parkin Day ago

    Just so happens I’m about to implement an event based data transfer process for an e-commerce company to replace the data migration cron jobs, so this video was actually perfectly timed! I’ll link to it in my coms to the rest of the business when I need to explain guaranteed events in a simple way :)

  • Ignat
    Ignat Day ago

    Smoke Signals?

  • deanmoncaster
    deanmoncaster Day ago +1

    You just described my sex life, an impotency key where someone can repeatedly and constantly ask for the same thing but it only ever happens once :(

    • deanmoncaster
      deanmoncaster Day ago +1

      @Puppet lover because the last time I tried that I set the house alight and that's why no more sexytime

    • Puppet lover
      Puppet lover Day ago

      Why couldn't general A add an addendum on the message like, "light a bonfire @ dusk if you agree, and the attack will commence @ sunrise"? Does that violate the problem

  • Jackson McAvoy
    Jackson McAvoy Day ago +1

    Couldn’t one side, say the red side, send a messenger to go over, inform blue of a time to attack, and return to the red side to confirm blue got the message? That way, if the red messenger doesn’t come back as instructed, the red side can assume the message was not received and keep sending messengers until one of them returns. The only conflict in that case would be if red and blue decided to send messengers at the same time, which is unlikely anyway.

    • Puppet lover
      Puppet lover Day ago

      (transmission control protocol) or UDP (user datagram protocol) were there is either communication confirmation or just throwing data at an endpoint hoping it all gets there.

  • Titan Uranus
    Titan Uranus Day ago

    But what if the general themselves delivers the message? Then they would know they made it.

    • Titan Uranus
      Titan Uranus Day ago

      @Wolfgang Laun Exactly! logic puzzles are bunk.

    • Wolfgang Laun
      Wolfgang Laun Day ago +1

      In other words: don't order by app, walk to the pizzeria!

  • Phrotonz GT
    Phrotonz GT Day ago

    Actually, the general problem is possible.
    General A keeps sending “Attack at 8. Respond please” until they get a response. Then General B would need to keep sending messages until they also get a response. Once that happens, then it is all good.