A concept that can help you as a GM is remembering to always give players as much free agency as you can at all times but remember you are in control of the game.
What does that mean? Well, setting goal and making it important to your players is your job but how they approach it or choose not to approach and weather the succeed or fail is mainly theirs. So if you want them do something you need to provide a story hook to draw them in, if they take it you can real them in, if they grab it but run in an unexpected direction let give them the slack to go their way and real them back to your planned narrative only if they appear lost or board, if they choose not to take the hook use a different hook with more tempting bate/draw don't force them to your narrative or you just become a story teller not a GM.
Another example of that is standard DC tests, when a player asks to try a task you can assign a difficulty 1-37 (1-5 trivial, 6-10 fairly easy, 11-15 minor challenge, 16-20 difficult, 21-25 very difficult, 26 - 30 should be impossible for most (particularly characters and NPCs considered lower than level 5), 31-37 ... a miracle has happened, a success of this event will be story most people will not believe it actually happened), after you assign a difficulty for the task and stick to it unless the players do something to change the difficulty. Their is a tendency to make a task easier for lower level characters and harder for veteran characters but if you do this they don't actually gain anything from becoming better at skills.. at the same time you need to balance what takes you pull your players into and warn them when they enter into something that you have set above them because they world is in your head and its possible to accidently remove free agency and "Total Party Kill" your group by indirectly leading them through omission.
Example 1: 1st level Players head east to a river. "we want to swim across", GM "it looks difficult but you can try, every one roll athletics" (DC25), players don't have the athletics skill and strength to get across they all roll and they all drown. GM "well you were warned"
... This is bad GMing as the players had no way to understand the difficulty of what they were doing and they fail and die and impossible task on a single roll.
Example 2: 1st level Players head east to a river. "we want to swim across", GM "The river is raging even at a glance you know there is little chance any of you can make it across especially carrying all your gear. Do any of you want to risk this peril?" (DC25), one player says "sure I am really strong and athletic, give me rope, I will tie it off, leave my gear hear, and try to swim to the other side". As GM if you deem the task is easier now that the player is not carrying gear you can reduce the DC from 25 to 20 for the test, lets say the player fails with a high roll, GM "CharacterX, tries his/her hardest but is quickly swept down stream the rope pulls tight but CharacterX can't get out on his own, do you help the character by pulling the rope or some other means?" Players try DC15 with role and fail, CharacterX gets a constitution save DC10 and fails so the characterX drowns.... In this case the GM offered some possibilities and fair warning and the CharacterX dies from bad decisions and bad luck on rules having multiple opportunities to turn back and escape. The GM didn't railroad the players and is not responsible for the Characters death.
As long as players care clear on the danger, make a choice, and their is some opportunity for the party to save themselves no matter how slim the GM can rest at ease that player free agency was given and the GM is not at fault for character death.
Example 3: 1st level Players head east to a river. "we want to swim across", GM "The river is raging even at a glance you know there is little chance any of you can make it across especially carrying all your gear. Do any of you want to risk this peril?" (DC25), Players "We all jump in and start swimming" they fail roles but 2 of them role over 15 so GM says you two make it across the rest of you fail and start to drown roll constitution check to resist drowning as you wash down river. While I am not opposed to give them multiple constitution and escape checks to see if they get out down stream... They all failed the test. I don't recommend adjusting DC in post because then players learn that someone will always succeed if they all try together. Some times trying together just means failing together and not having any one to dig you out of the whole you just dug yourself into. I think having multiple attempts to escape should be fine but each failure should have a risk of damage and or drowning, a success gives them another chance to escape, multiple constitution save successes might mean that they reach a slower part of the river with a lower DC but multiple failures should end the group. Sudden death is not for everyone at the same time consequences for throwing warnings to the wind and failing should be real. It helps immersion and it means that the success are more epic.
That's my two cents anyway. Happy Gaming.