Considering he was a standard protocol droid (E chu ta!), he probably built him from the scrap of previously deactivated ones. Still impressive, but certainly not "from scratch."
I like this analogy in particular because it also explains how Vader might not have connected the dots that this was the same protocol and astrometric droids from his childhood.
When I was a kid I had an old apple IIe computer. An IT guy I knew gave me some parts for it that his company was discarding and I added them to my computer.
But if I were to see another apple II computer today, I would never assume that it was my exact computer from my childhood.
Maybe the galaxy has an excellent standards committee so all these components are compatible. Like if you just connect red wires to red wires everything just works? So he just went around the junkyard looking for compatible wires and stuff?