In general, OBS does nothing differently. There are 3 major steps OBS does perform: the first step is reading all sources and compositing them onto the canvas. This is what you see in the preview. This step is the same for streaming and recording.
The second step is encoding the video. This compresses the video data. This is also done for streaming as well as for recording. However, not every encoding method is suited for streaming. Streaming requires low bandwidth constant bitrate encoded data, while disk recording isn't constrained at all.
So, in simple output mode, OBS automatically chooses CBR as rate control and let you set the bitrate for streaming. For recording, it automatically sets CQP or CRF as rate control, which results in variable rate and high data volume, thus giving much higher quality. In advanced output mode, you're free to configure whatever rate control you like, but if you stray away from CBR for streaming your streams will break, and if you stray from quality based rate controls for recording, you will get bad quality or waste disk space, and in case you choose CBR even both at the same time.
The third step is the actual output. This is where there is actually different programming between recording and streaming: for recording, OBS is writing the data to disk. For streaming it's writing the data out to the network. Which is a whole more complicated than it seems, because network is not very reliable and prone to intermittent data loss, and this network output module has to have this in mind.