Tuesday, July 16, 2013

What happens when you hit a key to start a job on a remote EC2 machine

Have you ever thought about what happens when you hit a key to start a job on a remote EC2 machine.

Strike a key on the keyboard and the capacitance changes instantaneously, sending a signal down the USB cable into the computer. The computer’s keyboard driver traps the signal, recognizes the key it’s from, and sends it to the Operating System for handling. The OS determines which application is active and decides whether the keystroke needs to be routed over an internet connection. If it is routed, a set of bytes is sent down the CAT-5 cable into the wall socket, abstraction masked via the OSI 7-layer model, and sent to a router. The router determines the closest router which is likely to know the IP of your destination ( a lot of stuff behind this even like DNS resolution etc.), and sends that packet onwards.

Eventually the packet arrives at the destination computer, enters the via ethernet cable, is trapped by the remote OS, interpreted as an enter stroke, sent to the shell, sent to the current program, and executed. Data from that remote machine is then sent back over the cable and the routers to your machine, which takes the packet, uses it to update the display, and tells you what happened on that remote box. 

All of that happens within an imperceptible fraction of a second. Just think...