There are a mess of Implementations, the two I use are strfry and nostream.
Depends on your use case whether you want it to be public or private but essentially you get a VPS or a box you can run it on. Install one of the implementations. If it's a local host thing you don't need to get an SSL cert and a domain name but if it's public you'll need a domain name and an SSL cert.
As for coding your own relay, I am not that great of a coder, so I probably wouldn't know where to start if I was starting from scratch.