On the existence of a pullback I’m not sure about my answer to the following problem:

Problem: Let $A,B$ and $C$ be sets, and let $f:A \rightarrow C$ and $g:B \rightarrow C$ be maps. Show that there exists a set $P$ and maps $h:P \rightarrow A$ and $k:P \rightarrow B$ such that $f \circ h = g \circ h$, and that for any set $X$ and maps $s:X \rightarrow A$ and $t:X \rightarrow B$ such that $f \circ s = g \circ t$, there is a unique map $u:X \rightarrow P$ such that $s = h \circ u$ and $t = k \circ u$.

Here it is my solution.

Solution: I’m dividing my solution in three parts in order to be more organised:

I started to define the set $P$ as $P = \{(x,y) \in A \times B | f(x) = g(y)\}$ and the maps $h:P \rightarrow A$ and $k:P \rightarrow B$ as $h((x,y))=x$ and $k((x,y))=y$ for all $(x,y) \in P$. Then it follows that $f \circ h, g \circ k:P \rightarrow C$. For $x \in P$, we deduce that $x = (a,b)$ with $a \in A$, $b \in B$ and $f(a)=g(y)$. So $(f \circ h)(x)=(f(h(x))=f(h((a,b)))=f(a)=g(y)=g(k((a,b)))=g(k(x))=(g \circ k)(x)$. Therefore $f \circ h = g \circ k$.


For the next step, I defined the map $u:X \rightarrow P$ as $u(x)=(s(x),t(x))$ for all $x \in X$. Now, let $x \in X$. We know that $(f \circ s)(x)=(g \circ t)(x)$, so $f(s(x))=g(t(x))$. Then $(s(x),t(x)) \in P$, which means that $u(x) \in P$. We observe that $h \circ u:X \rightarrow A$. Hence $(h \circ u)(x)=h(u(x))=h((s(x),t(x))=s(x)$. Therefore $h \circ u = s$. By the same reasoning, we conclude that $k \circ u = t$. This proves the existence of map $u$.


Now we turn our attention to the uniqueness of map $u$. Suppose that $u_1,u_2:X \rightarrow P$ are maps such that $h \circ u_1 = s = h \circ u_2$ and $k \circ u_1 = t = k \circ u_2$. Let $x \in X$, then $u_1(x) = (u_{1,1}(x),u_{1,2}(x))=((h \circ u_1)(x),(k \circ u_1)(x)) = (s(x),t(x))=((h \circ u_2)(x),(k \circ u_2)(x))=(u_{2,1}(x),u_{2,2}(x))=u_2(x)$. Therefore $u_1 = u_2$. So such map is unique.


What is concerning me on this solution is:

*

*Is it really necessary that $f \circ s = g \circ t$?


*Since I rarely use the above condition, I feel like something is missing in the solution (specially in the uniqueness part).
Any ideas or comments about that? Thank you for your time!
 A: The thing about pullbacks in general is that it is a pair of maps $h:P\to A$ and $k:P\to B$ that are universal with the property $f\circ h=g\circ k$. In other words, it is somehow the "best pair of functions" that achieve this property.
Therefore, it's necessary to compare the pair $(h,k)$ only against pairs $(s,t)$ that also satisfy this property; that is, $f\circ s=g\circ t$. The metric of being "better" is measured by the existence of a unique map $u$ through which $s$ and $t$ factor to recover $h$ and $k$ (which you've stated precisely in your question).
You mention that you "hardly use" the property $f\circ s=g\circ t$, and sure it may have been used only once, but it was used in a crucial way: the map $u:X\to P$ you defined would not exist otherwise. The map $u:X\to P$ is necessarily unique without this condition, because like you've shown, the set $P$ is a subset of $A\times B$ and so functions into $P$ are determined by their action on the components. Since $h$ and $k$ are just projections into the respective components, any two $u_1,u_2:X\to P$ that agree on components will be equal.
You can use this fact to realise the necessity of $f\circ s=g\circ t$ for the existence portion: by the uniqueness argument, you are forced to define $u:X\to P$ as $u(x) := (s(x),t(x))$ as you've done, but this is only a well-defined function $X\to P$ iff $(s(x),t(x))\in P$ for all $x$; that is, $f(s(x))=g(t(x))$ for all $x\in X$.
