Also on making sure that it is balanced all the time. The effort it takes to make sure that there's always input exactly as much energy as is taken out of the system is just staggering. And if only a few of the things needed to adjust it fail .. here comes the brown/blackout.
Most of the effort has been done in design. Rotating mass of generators is a nice self-correcting system, also the frequency is a near-zero latency signaling mechanism across the entire grid. Each participant can measure it and make independent decisions whether the grid needs more power or more consumption.
There is a lot of work that goes into predicting and commanding large participants and it's a complex system but some of the design is just beautiful in it's simplicity.