TITLE: For $M\otimes_R N$, why is it so imperative that $M$ be a right $R$-module and $N$ a left $R$-module?
QUESTION [15 upvotes]: I was reading about the construction of a tensor product of any right $R$-module $M$ and left $R$-module $N$ over a ring $R$.
Why is it required that $M$ and $N$ be right and left modules, respectively? How does the construction not work otherwise?

REPLY [9 votes]: Abstractly, the tensor product is the construction such that there is a natural isomorphism
$\newcommand{\op}{\textrm{op}} \newcommand{\Hom}{\textrm{Hom}}$
$$\Hom_{(S, T^\op)}(A \otimes_R B, C) \cong \Hom_{(S, R^\op)}(A, \Hom_{T^\op}(B, C))$$
where $A$ is a $(S, R^\op)$-bimodule, $B$ is a $(R, T^\op)$-bimodule, and $C$ is a $(S, T^\op)$-bimodule. (You can take $S = T = \mathbb{Z}$ if this helps. I write $(S, R^\op)$-bimodule to mean an object which has a left $S$-action and a right $R$-action simultaneously in a compatible way.)
Now, although I will use language suitable for bimodules here, what I say is also applicable to:

sets with a monoid or group action,
bifunctors $\mathcal{A} \times \mathcal{B}^\op \to \textbf{Set}$, where $\mathcal{A}$ and $\mathcal{B}$ are small categories, and more generally,
bifunctors of categories enriched over a suitable monoidal category.

Firstly, let us examine the hom objects, since tensor products are defined in terms of them. If $A$ and $B$ are left $R$-modules, then they are also abelian groups, and there is a natural monomorphism
$$\Hom_R(A, B) \hookrightarrow \Hom(A, B)$$
Indeed, observe that the $R$-actions of $B$ and $A$ (respectively) induce a $(R, R^\op)$-bimodule structure on $\Hom(A, B)$, as follows: if $f : A \to B$ is a homomorphism of abelian groups, we define $r \cdot f \cdot s : A \to B$ by
$$(r \cdot f \cdot s)(m) = r f(s m)$$
It is easily checked that this makes $\Hom(A, B)$ into a $(R, R^\textrm{op})$-bimodule. But what is $\Hom_R(A, B)$? It is the subgroup of those homomorphisms $f : A \to B$ such that
$$r \cdot f \cdot 1 = 1 \cdot f \cdot r$$
Thus, we get an equaliser diagram of the form
$$\Hom_R(A, B) \longrightarrow R \otimes \Hom(A, B) \mathrel{\rlap{\lower{0.5ex}{\longrightarrow}}\raise{0.5ex}{\longrightarrow}} \Hom(A, B)$$
where the upper map is given by the left $R$-action of $A$:
$$r \otimes f \mapsto 1 \cdot f \cdot r$$
and the lower map is given by the left $R$-action of $B$:
$$r \otimes f \mapsto r \cdot f \cdot 1$$
More generally, we need to form a special kind of limit called an ‘end’:
$$\Hom_R(A, B) = \int_R \Hom(A, B)$$
In the case of two functors $A, B : \mathcal{R} \to \textbf{Set}$, this amounts to the well-known formula
$$\textrm{Nat}(A, B) \cong \int_{r : \mathcal{R}} \textrm{Hom}(A r, B r)$$
Now, what about tensor products? They are formed in an essentially dual fashion. We take it for granted that there is a tensor product of abelian groups satisfying
$$\Hom(A \otimes B, C) \cong \Hom(A, \Hom(B, C))$$
and we want to understand how to get the corresponding constructions over $R$. Let $A, B , C$ be bimodules as in the first paragraph. First, consider the hom-object $\Hom(A, \Hom_{T^\op}(B, C))$. Because $\Hom$ is left exact in the second variable, we can extract the end to obtain
$$\int_{T^\op} \Hom(A, \Hom(B, C)) \cong \Hom(A, \Hom_{T^\op}(B, C))$$
Ends commmute with ends, so we can replace the outer $\Hom$ with $\Hom_{(S, R^\op)}$ as follows:
$$\int_S \int_{R^\op} \int_{T^\op} \Hom(A, \Hom(B, C)) \cong \Hom_{(S, R^\op)}(A, \Hom_{T^\op}(B, C))$$
We have assumed that there is a tensor-hom adjunction for abelian groups, so we can replace the integrand on the left hand side to obtain
$$\int_S \int_{R^\op} \int_{T^\op} \Hom(A \otimes B, C) \cong \Hom_{(S, R^\op)}(A, \Hom_{T^\op}(B, C))$$
and we know that
$$\Hom_{(S, T^\op)}(A \otimes B, C) \cong \int_S \int_{T^\op} \Hom(A \otimes B, C)$$
so we obtain
$$\int_{R^\op} \Hom_{(S, T^\op)}(A \otimes B, C) \cong \Hom_{(S, R^\op)}(A, \Hom_{T^\op}(B, C))$$
and now, applying the Yoneda lemma, we may push the end into the first argument of the integrand to get the coend formula for the tensor product:
$$A \otimes_R B = \int^R A \otimes B$$
Unpacking the definition of coend, this means there is a coequaliser diagram of the form
$$A \otimes R \otimes B \mathrel{\rlap{\lower{0.5ex}{\longrightarrow}}\raise{0.5ex}{\longrightarrow}} A \otimes B \longrightarrow A \otimes_R B$$
where the upper arrow is the map given by the right $R$-action of $A$:
$$a \otimes r \otimes b \mapsto a r \otimes b$$
and the lower arrow is the map given by the left $R$-action of $B$:
$$a \otimes r \otimes b \mapsto a \otimes r b$$
Thus, we see that the requirement that $A$ be a right $R$-module and $B$ be a left $R$-module is forced on us by the fact that $\Hom(B, -)$ has a natural right $R$-module structure when $B$ is a left $R$-module!
Moreover, it is clear from this construction that $\Hom_R$ and $\otimes_R$ are just two dual ways of neutralising two opposite $R$-actions:

$\Hom_R(B, C)$ extracts the universal $R$-equivariant subobject of $\Hom(B, C)$, while
$A \otimes_R B$ extracts the universal $R$-equivariant quotient of $A \otimes B$.