In the fourth aliyah the story of Yosef is interrupted by the episode of Yehuda and Tamar. Yehuda is one of Yosef's brothers, in fact the one who suggested selling him. After their father Yakov is grieved over the loss of Yosef, Yehuda goes off and marries and has three sons, Er, Onan, and Shelah. He found a wife named Tamar for his first son Er, but Er spilled his seed and died as a result.
Yehuda had his second son fulfill the mitzvah of Yirbum, of marrying his childless deceased brother's wife, but he also, spilled his seed and died. Yehuda hesitated to give his third son to Tamar, so she returned to her father's house as a widow.
Eventually, Yehuda's own wife passes away and he goes on a business trip. Tamar dresses like a prostitute and sits by the side of the road. Yehuda doesn't recognize her and visits her and leaves his signet ring, and she becomes pregnant. A few months later, when her pregnancy is evident, Yehuda orders her to be burned. While she is being taken out to be burned, she produces the signet ring and says the owner of this is the father. She is very careful not to embarrass Yehuda in public (she would rather be burnt if he didn't admit he was the father). From this we learn to what lengths we must go to avoid embarrassing someone.
In any case, the child from this union begins a long line that leads to King David, then on to Moshiach, indicating that this entire story was a Divinely orchestrated plan in fulfillment of the purpose of creation: the Messianic era, may it be fulfilled speedily in our days.