With regard to AC grid power generation frequency, it is based on the rpm's of the generator sources.
Depending on the source of fuel and type of engine there is a reaction time consideration on putting in more or less fuel to getting mechanical power out.
Power companies plan based on statistics of knowing their typical load requirements versus time of day but there is variations that they have to react to in the short term.
Sudden load increases can cause all the generators in the network to slow down a little while boilers take some time to build up more steam to push the turbines.
Most power companies keep a track record of their slight dips in frequency and compensate some time later with slight over frequency. This causes the long term average to be very accurate so your AC frequency based time clocks stay correct.