TITLE: Motivation behind the definition of flat module
QUESTION [21 upvotes]: Can someone explain what is the motivation behind the definition of a flat module? I saw the definition but I don't really know why it is important to work with these structures.

REPLY [9 votes]: According to the answers to this MO question, flatness should really be thought of as an algebraic condition rather than a geometric one. Mumford [The red book of varieties and schemes, Ch. III, § 10] writes,

The concept of flatness is a riddle that comes out of algebra, but which technically is the answer to many prayers.

For the purposes of homological algebra, it is incredibly useful for a functor to preserve exact sequences, and flatness of a (right) $R$-module $M$ is precisely what is needed to make the functor $M \otimes_R -$ send exact sequences of (left) $R$-modules to exact sequences of abelian groups. For example, if $I$ is a (left) ideal of $R$, then we have an exact sequence of (left) $R$-modules:
$$0 \longrightarrow I \longrightarrow R \longrightarrow R / I \longrightarrow 0$$
In general, the tensored sequence is only right exact:
$$M \otimes_R I \longrightarrow M \longrightarrow M \otimes_R R / I \longrightarrow 0$$
It's not hard to see that the image of $M \otimes_R I \to M$ is the abelian group $M I$, so when $M$ is flat, the natural map $M \otimes_R I \to M I$ is an isomorphism. Conversely, if this holds for every (left) ideal $I$, then $M$ is flat. Morally, what this is saying is that a flat $R$-module has no "generalised" $R$-torsion; if $R$ is a principal ideal domain, then an $R$-module is flat if and only if it has no $R$-torsion in the ordinary sense. (Think of $M \otimes_R I$ as being a group of formal linear combinations of formal products; one possible way $M \otimes_R I \to M I$ could fail to be an isomorphism is if $m \cdot a = 0$ for some non-zero $m$ in $M$ and non-zero $a$ in $I$.) 
Under certain circumstances, flatness coincides with other conditions which are more geometric in nature. For example, if $R$ is a commutative noetherian ring, then the following are equivalent for a finitely-generated $R$-module $M$:

$M$ is projective.
$M$ is flat.
$M$ is locally free, in the sense that there are $f_1, \ldots, f_n$ in $R$ such that $f_1 + \cdots + f_n = 1$ and each $M \otimes_R R[1 / f_i]$ is free.

Actually, we always have the implication projective $\Rightarrow$ flat, even when $M$ is not finitely generated and $R$ is non-commutative/non-noetherian (just so long as the axiom of choice holds!), but the commutative noetherian case is what is usual in algebraic geometry. Being locally free means that $M$ is the module of global sections of a finite-dimensional vector bundle $\tilde{M}$ over $\operatorname{Spec} R$. It is reasonably clear that the rank of $\tilde{M}$ is locally constant on $\operatorname{Spec} R$. We have a partial converse: if $R$ is a noetherian integral domain and the rank of finitely-generated module $M$ is constant on $\operatorname{Spec} R$, then $M$ is locally free and hence flat.