Long before Joseph existed, his great-grandfather received information from God regarding his descendants (and he still had no children). Joseph could never image this prophecy would be fulfilled through him. Joseph arrived in Egypt as a slave and erroneously accused, ended up in prison. Everything seemed so unjust! However, according to divine perspective, he was exactly where he was supposed to be.
An opportunity came up, and standing before Pharaoh, Joseph did not complain about his situation - he only passed on what God wanted to transmit through a strange dream. Joseph did not have a plan with all of this, but God's plan was coming right along. God used Joseph to preserve the life of the Egyptians and of his own family when facing a famine situation. His brothers went to Egypt seeking food. After various emotional events took place, they found out the true identity of that governor, and, invited by him, they went to live in Egypt. A long time after this, their descendants left Egypt under the command of Moses, leaving behind 400 years of slavery - exactly as God has said.
God used a man's life, changing the circumstances according to His own will in order to fulfill His plan. He also does this with us. He knows about everything and has a plan to be accomplished. But we do not always notice that He is making things happen. Everything is going well, and then, suddenly, something not planned occurs, decisions are made, and changes are needed. We suffer with the new situation, unjustly, many times. We do not understand how God could allow such things, and we forget that He is in control. Like Joseph, we do not know what awaits us, but we can trust in God's plans. He does not forget His promises and acts for our good. Let's praise God for that!
We see chaos, but God sees the final result and controls everything to fulfill His plan.