The opening lines of a book are meant to set the tone of the book - providing background, introducing its major characters and themes. Masechet Sotah does not disappoint. On the opening page we discuss the themes of marriage, sexual infidelity, character assessment and theology.
 

"One who warns his wife [against being alone with another man] must do so in front of two witnesses" (Sotah 2a). The Mishna begins with the case of a husband suspicious that his wife is unfaithful. There is no background information given - neither legal nor moral[1]. Rather the Mishna records a debate as to whether after appropriate warnings are given to one's wife not to be alone with another specific man, one witness would be sufficient to require her to go through the Sotah ordeal.

One might be tempted to think our Mishna is implicitly critiquing the lax moral standards of the wife. That may be so but that is not the whole story. "Reish Lakish, when he would begin to discuss [the subject of] Sotah, he would say as follows: 'They only pair a woman with a man according to his deeds'". If a man has an unfaithful wife the husband dare not claim total innocence. It is most likely that his actions contributed to her infidelity. It is often said that the rich marry the rich; well the morally righteous marry the morally righteous and those whose morals might be, shall we say, loose marry people of similar looseness.
  

Yet the Talmud immediately challenges Reish Lakish's assertion citing one of the more famous pieces of Midrashic literature; "but didn't Rav Yehuda say in the name of Rav: 'forty days before the creation of a child, a Heavenly voice goes out and proclaims, the daughter of ploni (John Doe) to ploni; the house of ploni for ploni and, the field of plonii for plonii"? Marriages are after all made in heaven!  
 

Rashi notes that one might have argued that there is no contradiction at all. G-d is all knowing and knows even before we are born who the spouse who is most fitting for us based on our actions. Our mate can be determined both based on our actions and yet be announced by G-d forty days before we are born. Why then does the Gemara believe that Reish Lakish and Rav are arguing?
  

"All is in the hands of heaven save for the fear of heaven". The doctrine of free choice - so fundamental to our belief system and without which we can neither be credited nor held responsible for our actions - indicates that G-d does not control or apparently even know how we will develop morally and ethically. "Rav Chanina bar Papa expounded: The name of the angel who is in charge of conception, 'Night' is his name; he takes a drop and places it in the presence of the Holy One, blessed be He, saying, 'Sovereign of the universe, what shall be the fate of this drop? Shall it produce a strong man or a weak man, a wise man or a fool, a rich man or a poor man?' Yet a  'wicked man' or righteous one' he does not mention, in agreement with the view of Rav Chanina. For Rav Chanina stated: All is in the hands of heaven save for the fear of heaven"(Niddah 16b).
 

Only because G-d does not know our future deeds the Gemara can query the contradiction between marriage based on our actions and marriage based on Divine decree. This may sound heretical but this is the simple reading of the Gemara and is the explanation given by Rashi[2]. (Because of its theological implications there were many who sought to re-interpret Rashi.)
 

So if they do contradict, which is it? Do we marry whom we deserve or is it pre-ordained in heaven? While I might have been inclined to leave this metaphysical question as a matter of philosophical dispute between two great Sages the Gemara resolves these two views by stating that in zivug rishon, a first marriage G-d decrees who we will marry 40 days before we are born but in zivug sheni, a second marriage it all depends on our actions.
  

This answer seems rather contrived and the Gemara does not explain why this  should be so. And since many marry only once (and that is a good thing) it seems that our actions have little bearing on our marriage partner.
  

Rav Yaakov Reisher in his commentary Iyun Yaakov quotes the teaching of the Zohar that zivug rishon and zivug sheni do not refer to our first and second marriages. Rather zivug rishon refers to when we are in the womb and zivug sheni to after we are born. G-d designs wonderful plans for us charting a path for us and arranging a lifelong partner to share that path with. But we do not always live up to that potential. Our actions can often lay waste to the best of plans. 

 
What is true of G-d is true of G-d's partners in creation - our parents (see Nidah 31a). They too have great hopes and expectations for us and they do everything they can to help us fulfill those hopes. But ultimately it is us alone, our own actions that determine the path we will lead in life.

[1] The Talmudic Sages assumed that those who would study its texts would be most familiar with the Biblical text and hence there was little need to give background that one could discover by reading the text. 
  

[2]Many of us are more familiar with the view of the Rambam that G-d knows everything including our moral future yet man still has free choice. As to how both can be true the Rambam says that this is part of the Divine human divide. The answer is basically unknowable to man but such does not make it any less true (see Hilchot Teshuva, chapter 5).