They build the dam in such a way that it keeps the water at the desired level and leaves special canals for excess water to run through.