The first modern railway is usually taken to be the Liverpool and Manchester Railway built by George Stephenson which opened in 1830.
This was a twin track railway, ie using one line of rails for each direction so trains wouldn’t come into head on collision. To stop trains running into the back of the train in front “Policemen” were stationed every few miles who would signal to the driver how much time had elapsed since the preceding train had passed. If it was less than 10 minutes the train would be expected to stop.
This system actually worked quite well, given that the policeman were not originally issued with watches and therefore had to guess the time elapsed, and also given the very poor brakes.( locomotives originally didn’t have any, ad the driver would whistle to the brakesmen riding on the carriage roofs to turn their brakes ).
The major risk was from a train breaking down. In which case a breaksman was expected to run a mile back down the track to signal warning to a following train.
All the early railways in the U.K. adopted a variety of the train interval system, which was basically the best that could be done until the introduction of the telegraph enabled much safer forms of working.