Following http://www.math.columbia.edu/~masdeu/files/notes/ModForms.pdf, define an effective Cartier divisor of an $S$-scheme $f: X \rightarrow S$ as a closed subscheme $Z \subseteq X$, such that $Z$ is flat and finite over $S$ via $f$.
$D$ defines an invertible sheaf $\mathcal{I}(D)$ on $X$; take $\mathcal{L}(D)$ to be its dual.
On page 20, we have "The degree of $D$ is defined as the rank of $f_*(i_*\mathcal{O}_D \otimes \mathcal{L}(D))$," where $i : Z \rightarrow X$ is the inclusion.
I understand that the latter sheaf is locally free, because $f$ is finite and flat. But I don't understand why it has a well-defined rank; why can't be different on affine subsets? It's not even required that $S$ should be connected...