TITLE: How is a descent datum the same as a comodule structure?
QUESTION [17 upvotes]: For a homomorphism of commutative rings $f:R\to S$, there are at least two notions of a descent datum for this map. One of these is to be an $S$-module $M$, with an isomorphism $M\otimes_R S\cong S\otimes_R M$ satisfying the cocycle condition. This can be thought of as saying something about "agreeing on intersections" since it's demanding that the two ways of tensoring $M$ up to an $S\otimes_R S$ module, i.e. either along the left unit or the right unit $S\to S\otimes_R S$ are equivalent. This is basically, I think, the dual of saying that it agrees on projections. 
Another common way of phrasing descent data is to say that $M$ is an $S$-module which is also an $S\otimes_R S$-comodule, where $S\otimes_R S$ is a coring with structure map $\Delta:S\otimes_R S\to S\otimes_R S\otimes_R S\cong S\otimes_R S\otimes_S S \otimes_R S$ using the unit map of $S$. 
I have written down some vague things about how these two are the same, but is there a functorial equivalence between the two categories of descent data? How does one obtain a comodule structure from the isomorphism $M\otimes_R S\cong S\otimes_R M$? And vice versa? And if you're feeling pedagogical, you might even mention how these two notions are equivalent to the notion of being a coalgebra for a certain comonad!
Thanks!

REPLY [18 votes]: I find it easier to use geometric notation, so let $X = \mathrm{Spec}(S)$, $Y=\mathrm{Spec}(R)$, and $\phi: X \to Y$ be the morphism corresponding to $f$. We have adjoint functors
$$
\phi_\ast : S\text{-}\mathrm{mod} \to R\text{-}\mathrm{mod}: \phi^\ast.
$$
Consider the (beginning of the) Cech simplicial set correponding to the map $\phi$.
$$ \ldots X \times_Y X \rightrightarrows ^{\widehat{\phi}_1} _{\widehat{\phi}_2} X \stackrel{\phi}{\rightarrow} Y $$
(sorry for the bad latex). It might be helpful to have in mind the example where $X$ is an open cover of $Y$, so that the space $X\times _Y X$ is consists of double intersections.
First of all, note that the structure of being a comodule for the coring $S \otimes_R S$ is a map 
$$M \stackrel{a}{\to} M \otimes _S (S \otimes _R S) \simeq M \otimes _R S \simeq \phi ^\ast \phi _\ast M$$
satisfying the usual conditions. You may notice that the functor $\phi^\ast \phi_\ast$ has the structure of a comonad, and indeed, being a comodule for $S \otimes_R S$ in the category of $S$-modules is the same thing as being a comodule (aka coalgebra) for the comonad $\phi^\ast \phi_\ast$.
By base change, we have $\phi ^\ast \phi_\ast M \simeq \widehat{\phi}_{1\ast} \widehat{\phi}_2 ^\ast M$, so by adjunction, a map $a$ as above corresponds to a gluing map
$$\widetilde{a}: \widehat{\phi}^\ast _1 M \to \widehat{\phi}^\ast_2 M$$
i.e. a map
$$ M\otimes_R S \to S \otimes_R M$$.
This is the basic mechanism of the correspondence between comodules for $S \otimes _R S$ and the more down-to-earth notion of descent data. One can check that the conditions for $a$ to define a comodule correspond to the cocycle condition for the gluing map $\widetilde{a}$. 
If the map $\phi$ is actually nice enough for descent (e.g. faithfully flat), then descent is a concequence of the Barr-Beck theorem: an $S$-module $M$ which is a comodule for $\phi^\ast \phi_\ast$ descends to an $R$-module $N$.
As you are a homotopy theorist, I should note that if you want to do this with complexes of modules (or more fancy things), then you will need the entire Cech simplicial set $\mathcal C(\phi)_\bullet$. Then, the data of being a comodule for $\phi^\ast \phi_\ast$ will be equivalent to being a simplicial module on $\mathcal C(\phi)_\bullet$.