Let $f:A\rightarrow B$ be a retraction (i.e. a morphism that is a left inverse) and let $g:B\rightarrow A$ be the one such that $f\circ g = \operatorname{id}_B$.
I'd like to show that in fact $f:A\rightarrow B$ is a coequalizer of morphisms $\operatorname{id}_A : A\rightarrow A$ and $g\circ f :A\rightarrow A$.
My attempt: We know that $fg=\operatorname{id}_B$ (because $f$ is retraction), thus $fgf=\operatorname{id}_B \circ f = f = f \circ \operatorname{id}_A$. So $f$ coequalizes the two morphisms. Now I am struggling to show that $f$ is universal, i.e. if there is another $f' : A\rightarrow X'$ with $f' \circ \operatorname{id}_A=f'\circ gf$, then $f=f'$ (and so $X'=B$).
I tried to postcompose the equation $f'=f'gf$ with $g$ but that leads to $f'g=f'gfg$ but $gf=\operatorname{id}$, so this is just $f'g=f'g$ i.e. $0=0$, which proves nothing.
How to proceed?
The answer is already in the comments so I will post it myself. My mistake was in the fact that I did not need to show $f'=f$, but find factorization $f' = \varphi f$. But since $f'=f'gf$, $\varphi=f'g$ is one such possibility. If $\psi$ was another one, we get $\psi f = \varphi f$. Now, $f$ is retraction, thus epimorphism, so we cancel from the right to get $\varphi=\psi$, so $\varphi$ is indeed unique, so the proof is finished.