Sidebar: Your Phone's Contract Is Different
Everything in this book so far has assumed that the last hop was a wire. Most of Courtyard’s users are on phones. The contract the box made in Chapter 1 still holds for them, but the last link of all, from the tower or the access point to the device in a pocket, amends that contract in four places. The amendments are short enough to be read against Chapter 1 in one sitting, and they are what to suspect whenever something works on a laptop and fails on a phone.
Chapter 1’s contract, with four clauses struck through in red and their amendments written beside them.
The first amendment is that the medium is shared again. The problem of Chapter 4 has come back. Radio is one wire that every device within range is tapped into, and two devices transmitting at once collide. The access point, which is the switch of the air, arbitrates by making everyone listen before talking and back off on collision, which is the etiquette Chapter 4 said the wired world had abandoned. It could not be abandoned here, because you cannot give every phone its own private slice of air. So bandwidth is shared with every device on the same channel, the neighbours’ included, and it drops when the room fills up. That is why conference Wi-Fi is what it is.
The second amendment is that loss no longer means congestion. Chapter 16 built the sender’s entire sense of the path on one signal: if a piece is lost, the path is full, so back off. That was true for wires, where almost all loss is a full queue. Radio loses pieces for other reasons. There is interference, there is fading, there is a hand over the antenna or a wall in the way. The path is not full; the air was noisy for a moment. But the sender cannot tell the difference. It sees loss, halves its window, and slows down for nothing.
The link layer knows this and mostly hides it. Wi-Fi and mobile radios retransmit lost frames themselves, several times, quickly, before the transport ever notices, which is a small Chapter 11 tucked inside Chapter 4’s rung. The trade is that the hidden retransmissions show up as variable delay. The piece arrives, but late. Radio converts loss into jitter, and the texture of Chapter 5 is rougher in a pocket than it is on a desk.
The third amendment is that your address changes as you walk. Leave the flat and your phone drops off Wi-Fi and onto cellular. That is a different network, and Chapter 5 said that an address is assigned by the network you are on. A new network means a new address. Every connection your phone had was named by a four-tuple that included the old address, and all of them are now wrong. Every one of them dies. The identity of Chapter 8 is gone and the numbering of Chapter 12 belongs to an address that no longer exists, so every connection has to be re-established from nothing: handshake, security handshake, slow start. Chapter 6 of this part will tell you what that costs. Walking out of a door resets every conversation your phone was having.
The fix is to name a connection by something other than the four-tuple: a connection identifier that both ends agree on and that survives a change of address. That is what the fork at the end of Chapter 17 built, and connection migration is one of the main reasons it exists. Your phone changes address, the connection continues, and the server merely notices that the pieces now arrive from somewhere else.
The fourth amendment is that the radio sleeps. The radio is the most power-hungry part of a phone. It cannot be on all the time, so it powers down between bursts and wakes when there is something to send or receive. Waking costs energy and a noticeable delay, often a hundred milliseconds or more before the first piece moves.
Now recall the heartbeat of Chapter 13, and Chapter 3 of this part, where the heartbeat became the only thing keeping a router from forgetting you. Every application that keeps a connection open needs one, every thirty seconds or so. Ten such applications make a radio that never sleeps, and a battery that is flat by lunchtime.
So the platform intervenes. Instead of every app holding its own connection and its own heartbeat, the operating system holds a single long-lived connection to a service the platform runs, with a single heartbeat, and applications receive their messages through it. An application is woken briefly when something arrives and then put back to sleep, and applications are actively prevented from keeping their own connections alive in the background. This is the push notification channel. The architectural reason it exists is not a feature at all; it is one NAT keepalive, shared across every app on the device, so that the radio can sleep.
This means that on a phone, Courtyard’s chat does not keep a connection open when it is in the background. It is told, through the shared channel, that a message is waiting, and it connects to fetch it. Presence, the online dot from Chapter 13, becomes approximate, a matter of “last seen a few minutes ago”, because the pulse that would have made it exact has been taken away to save the battery.
Read together, the four amendments describe a device whose link is shared, whose loss is noise, whose address moves, and whose radio would rather be off. Not one of those was true of anything in Part I. When a thing works on a laptop on Wi-Fi and fails on a phone walking down a street, whether it is a call that drops at the door, a message that arrives ten minutes late, or a “connected” indicator that is lying, it is one of these four, and now you know which to suspect.