Step 1: Add a wild card (*) host as your A record in DNS.
Step 2: In your web server you need to listen to *.xyz.com . In nginx you will do something like this:
server {
server_name ~^(.*)\.xyz\.com$ ;
root /home;
}
Step 3: Once the request hits nginx (and if it is configured as reverse proxy), it'll forward the request to a backend such as Node or Python. Your backend code has to parse the host and find out the subdomain. Once you find out the subdomain, rest is easy.
Let me know if you have any questions!