The "magic diagram" is cartesian I am trying to solve an exercise from Vakil's lecture notes on algebraic geometry, namely, I want to show that
$\require{AMScd}$
\begin{CD}
    X_1\times_Y X_2 @&gt;&gt;&gt; X_1\times_Z X_2\\
    @V V V @VV V\\
    Y @&gt;&gt;&gt; Y \times_Z Y
\end{CD}

is a cartesian diagram. I think I've figured out where the maps come from: The lower map is the diagonal induced from the universal property of $Y \times_Z Y$, the upper map is coming from the universal property of $X_1\times_Z X_2$ (this is one of the previous exercises in Vakil's notes), the map on the right also comes from the universal property of $Y \times_Z Y$ since we have two maps from $X_1\times_Z X_2$ to $Y$ whose composition with $Y\rightarrow Z$ coincides, and finally the map on the left side is either composition $X_1\times_Y X_2 \rightarrow X_i \rightarrow Y$. At this point, I don't even see why this diagram should be commutative.

But even discarding the issue of commutativity, given some $T$ instead of $X_1\times_Y X_2$ making the above diagram commute, I have no clue how to obtain a canonical map $T \rightarrow X_1\times_Y X_2$.

I could solve all the other problems in this section of his notes, but this one eludes me. Any help or solution (preferably just using the universal properties that we're given) would be greatly appreciated.
First, why is the diagram commutative: you've got the following commutative diagram:


It is commutative precisely because this is how we defined the map $X_1 \times_Y X_2 \to X_1 \times_Z X_2$. The bottom right square is used to define $Y \to Y \times_Z Y$.

Now, you diagram is commutative iff the two maps $X_1 \times_Y X_2 \to Y \times_Z Y$ are equal, iff each component maps are equal.


The red path is used to define the (first component of the) map that factors through $X_1 \times_Y X_2 \to X_1 \times_Z X_2 \to Y \times_Z Y$
The blue path is used to define the (first component of the) map that factors through $X_1 \times_Y X_2 \to Y \to Y \times_Z Y$.


As you can see, they are equal. Therefore the magic diagram commutes.



Now, the universal property. Suppose you're given $T \to X_1 \times_Z X_2$ and $T \to Y$  such that the two maps $T \to Y \times_Z Y$ are equal. In other words, you're given maps $T \to X_1$, $T \to X_2$ and $T \to Y$, such that the two maps $T \to X_i \to Z$ are equal, and the maps the blue path and the red path are equal (where $T$ is in the position of $X_1 \times_Y X_2$). As you can see, this is precisely the same thing as giving two maps $T \to X_i$ such that $T \to X_i \to Y$ are equal, because then the fact that the maps into $Z$ are equal is a consequence of the fact that the maps into $Y$ are equal. So there's a unique map $T \to X_1 \times_Y X_2$ making everything commute.



Considering that Vakil introduces the Yoneda lemma after this exercise, I didn't dare give the proof using it. But by the Yoneda lemma, you can just consider the case of sets; in the equations that you'll write, you'll arrive at the same conclusion -- that giving a maps that make everything commute will give you a redundant condition that the images in $Z$ are the same, and that the fibered product of the whole thing is the fibered product over $Y$.
Vakil's algebraic geometry notes on &quot;schemes&quot; gives this as an exercise (see exercise 1.3.s on page 37 in the attached link). Any scheme has an open cover of affine schemes and let us first prove it for affine schemes.
https://math.stanford.edu/~vakil/216blog/FOAGnov1817public.pdf
Let $A\rightarrow B$ be a map of commutative unital rings and let $C_1,C_2$ be commutative unital $B$-algebras. Let $m:B\otimes_A B \rightarrow B$ be the multiplication map and let $I:=ker(m)$. We want an explicit isomorphism
$$B\otimes_{B\otimes_A B}(C_1\otimes_A C_2) \cong C_1\otimes_B C_2.$$
Note that there is a canonical isomorphism
$$ B\otimes_{B\otimes_A B}(C_1\otimes_A C_2)\cong C_1\otimes_A C_2/I(C_1\otimes_A C_2)$$
where we view $C_1\otimes_A C_2$ as a left $B\otimes_A B$-module via the canonical map.  The canonical map
$$C_1\otimes_A C_2 \rightarrow C_1\otimes_B C_2$$
induce a canonical map
$$F': B\otimes_{B\otimes_A B}(C_1\otimes_A C_2) \cong C_1\otimes_A C_2/I(C_1\otimes_A C_2)   \rightarrow C_1\otimes_B C_2.$$
We want a map in the other direction: There is a canonical map
$$F: C_1\times C_2 \rightarrow C_1\otimes_A C_2/I(C_1\otimes_A C_2)$$
defined by
$$F(x,y):=\overline{x\otimes y}.$$
The map $f$ induce a map of rings $F$
$$F: C_1\otimes_B C_2 \rightarrow C_1\otimes_A C_2/I(C_1\otimes_A C_2).$$
Question: &quot;I am trying to solve an exercise from Vakil's lecture notes on algebraic geometry, namely, I want to show that
$\require{AMScd}$
\begin{CD}
    X_1\times_Y X_2 @&gt;&gt;&gt; X_1\times_Z X_2\\
    @V V V @VV V\\
    Y @&gt;&gt;&gt; Y \times_Z Y
\end{CD}
is a cartesian diagram.&quot;
Answer: It seems to me that $F \circ F'=F' \circ F=Id$ is the identity. Hence there is a canonical isomorphism of commutative unital rings
$$B\otimes_{B\otimes_A B}(C_1\otimes_A C_2) \cong C_1\otimes_B C_2.$$
If we let $Y:=Spec(B), Z:=Spec(A), X_i:=Spec(C_i)$ we get a canonical isomorphism
$$Y\times_{Y\times_Z Y}(X_1\times_Z X_2)\cong X_1\times_Y X_2.$$
All maps are &quot;canonical&quot; and using a glueing lemma the theorem should follow.
Note: Some of the above proofs are overly complicated and you speak of algebraic geometry and Vakil's notes on algebraic geometry and schemes - the above proof is completely elementary.