Wirebook › Bonus lesson
How can two people draw on the same picture at once?
You and a friend are colouring the same picture on two tablets. You do the sun, they do a bush, and at the very same moment you both colour the middle square. When the tablets talk to each other again, whose drawing survives? Online drawing boards, shared documents and spreadsheets have to answer this question many times a second.
Three ways to share one picture
| Rule | What happens | Good for |
|---|---|---|
| Last save wins | Each device uploads its whole copy. The last one to arrive replaces everything, so the other person's work quietly disappears. | Things only one person edits, like your own settings |
| Take turns | Only the device holding the "lock" may change things. Nothing clashes, but everyone else waits, and if the holder goes offline, nobody can draw. | Old-style shared files ("someone else has this document open") |
| Merge small changes | Devices send tiny changes ("square 27 is now pink") instead of whole pictures. Changes to different squares simply both happen. Only a change to the same square needs a rule, such as "the later one wins". | Live drawing boards, shared documents, multiplayer design tools |
How real apps keep everyone's work
- Send small changes, not whole files. "Insert 'big ' at position 0" is tiny and easy to combine with someone else's change.
- Shift the numbers. When two changes cross on the way, the server adjusts the later one's position to make room for the earlier one. Grown-ups call this operational transformation; it is the idea behind many shared document editors.
- Or give every letter a name tag. Instead of "position 7", say "after the letter with tag Owl-12". Tags never move, so changes can arrive in any order and still fit together. These structures are called CRDTs, and they also let apps work offline and catch up later.
- Decide what a clash means. When two people really change the same thing, something has to give. Some apps keep the later change, some keep both and ask, and code-sharing tools such as Git mark a merge conflict for a person to sort out.
It's a bit like… two friends colouring photocopies of the same page on a long car journey. At the end, you lay the pages on top of each other. Colours in different places? Keep both. Did you both colour the same balloon? Then you need a rule, like "the last one to colour it wins", or you ask each other.
Related lessons: a shared park with lag (one world kept on a server), how a game remembers progress, how a download picks up where it left off. Grown-up twins: Tooltern's text diff shows exactly what changed between two versions.