For example, if you had a 1200 bps modem then you simply only dialed in to certain telephone numbers that supported that speed. If the modem had a choice of speeds one could use the AT register S37 to select one. Then one would need to start getty at 2400 bps. Thus getty needed to adjust to whatever speed was coming from the modem. The agetty program has a similar baud rate detection feature.
Modern modems can use almost any serial port speed.
To do this they employ speed buffering and flow control. If the flow entering the modem is faster than the flow exiting it, the excess flow is simply stored in a buffer in the modem. Then to prevent the buffer from overflowing, the modem sends a flow control signal to stop the input flow to the modem. This is true for either direction of flow. See Flow Control for more details.