In studying the story, we see that David was given ample opportunity to doubt a triumphant outcome.
And Saul said to David, "You are not able to go against this Philistine to fight with him; for you are a youth, and he a man of war from his youth." (1 Samuel 17:33)
Instead of being moved by fear and unbelief, David recalled how God had delivered him in times past from the lion and the bear.
"Your servant has killed both lion and bear; and this uncircumcised Philistine will be like one of them, seeing he has defied the armies of the living God." Moreover David said, "The Lord, who delivered me from the paw of the lion and from the paw of the bear, He will deliver me from the hand of this Philistine." (1 Samuel 17:36-37)
What I never realized before is that he was not only encouraging himself, but also those around him who heard his words. Think about it. Here we find King Saul carrying the weight of a difficult decision. If he sends David to meet Goliath only to fail, then Israel would be made the slaves of the Philistines.
Then he (Goliath) stood and cried out to the armies of Israel, and said to them, "Why have you come out to line up for battle? Am I not a Philistine, and you the servants of Saul? Choose a man for yourselves, and let him come down to me. If he is able to fight with me and kill me, then we will be your servants. But if I prevail against him and kill him, then you shall be our servants and serve us." (1 Samuel 17:8-9)
This wasn't about the fate of one man, but about that of an entire nation of people. Of course, we know that David went forth at Saul's command, defeated Goliath, and spared all of Israel. This was accomplished through the faith of a shepherd boy who encouraged the heart of a king.