First, the instruments are set up in the recording studio. Usually the drums are recorded first so that all the other instruments record their parts in the right timing. Drums are recorded to click more and more these days, so that the tempo is set by the DAW and it is easier to edit the tracks later.