Shipping Python APIs/
Lesson

Your FastAPI app is deployed and running at my-app-production-abc123.railway.app. It works. But you want users to reach it at api.myapp.com. This is where code ends and infrastructure begins, and it is the part AI handles worst, because there is nothing to code. It is all configuration in external systems.

How a request reaches your APIWhat is api?A set of rules that lets one program talk to another, usually over the internet, by sending requests and getting responses.

Before diving into configuration, understand what happens when someone visits api.myapp.com:

Browser → DNS Resolver → Platform Load Balancer → TLS Termination → Your App
    ↓           ↓                    ↓                    ↓              ↓
"api.myapp.com" "Where is that?"  "Route to app"   "Decrypt HTTPS"  "Handle request"104.21.12.34
  1. DNSWhat is dns?The system that translates human-readable domain names like google.com into the numerical IP addresses computers use to find each other. resolution: the browser asks "what IP addressWhat is ip address?A numerical label (e.g., 172.217.14.206) that identifies a device on a network - DNS translates domain names into IP addresses. is api.myapp.com?" and gets an answer from DNS
  2. TCP connection: the browser connects to that IP address
  3. TLSWhat is ssl/tls?Encryption protocols that secure the connection between a browser and a server, preventing eavesdropping on data in transit. handshakeWhat is handshake?The initial exchange between a client and server that establishes a connection and agrees on communication rules before data starts flowing.: HTTPSWhat is https?HTTP with encryption added, so data traveling between your browser and a server can't be read or tampered with by anyone in between. encryptionWhat is encryption?Scrambling data so only someone with the right key can read it, protecting information from being intercepted or stolen. is established (SSL certificate verification)
  4. HTTPWhat is http?The protocol browsers and servers use to exchange web pages, API data, and other resources, defining how requests and responses are formatted. request: the actual request reaches the platform's load balancerWhat is load balancer?A server that distributes incoming traffic across multiple backend servers so no single server gets overwhelmed.
  5. Routing: the platform routes the request to your specific app containerWhat is container?A lightweight, portable package that bundles your application code with all its dependencies so it runs identically on any machine.
  6. Your code: FastAPI receives the request and returns a response
02

DNSWhat is dns?The system that translates human-readable domain names like google.com into the numerical IP addresses computers use to find each other. records you need to know

You configure DNS records at your domain registrar (Namecheap, Cloudflare, Google Domains, etc.).

Record typePoints toWhen to useExample
AIP addressRoot domain (myapp.com)myapp.com → 104.21.12.34
CNAMEAnother domainSubdomain (api.myapp.com)api.myapp.com → my-app.railway.app
AAAAIPv6 addressIPv6 supportmyapp.com → 2606:4700::1

For most deployments, you need one CNAME record pointing your subdomainWhat is subdomain?A prefix to a domain (api.example.com, blog.example.com) that routes to a distinct service or section of a site. to the platform's domain.

# DNS record for Railway deployment
Type: CNAME
Name: api
Value: my-app-production.up.railway.app
TTL: 300
Good to know
You cannot use a CNAME record for a root domain (myapp.com without a subdomain). Some DNS providers offer "CNAME flattening" or "ALIAS records" as a workaround. Cloudflare does this automatically. If your provider does not, use an A record with the platform's IP address.
03

HTTPSWhat is https?HTTP with encryption added, so data traveling between your browser and a server can't be read or tampered with by anyone in between. and TLSWhat is ssl/tls?Encryption protocols that secure the connection between a browser and a server, preventing eavesdropping on data in transit. certificates

HTTPS encrypts the connection between the browser and your server. Without it, passwords and tokens travel in plain text.

The good news: in 2026, every deployment platform auto-provisions TLS certificates via Let's Encrypt. You do not need to buy certificates or configure them manually.

The flow:

  1. You add a custom domain in the platform's dashboard
  2. You configure DNSWhat is dns?The system that translates human-readable domain names like google.com into the numerical IP addresses computers use to find each other. to point to the platform
  3. The platform detects the DNS change and requests a Let's Encrypt certificate
  4. HTTPS works automatically (usually within minutes)

AI pitfall
AI sometimes generates code for manual certificate management (certbot, openssl commands, certificate files in the repo). For platform-hosted apps, this is unnecessary and wrong. The platform handles certificates. You only need manual cert management if you are running your own server on a VPS.
04

Reverse proxies

A reverse proxyWhat is reverse proxy?A server that sits in front of your app and forwards incoming requests to it, often handling SSL, caching, or load balancing along the way. sits between the internet and your application. On managed platforms, this is handled for you. But understanding what it does helps you debug issues.

Internet → Reverse Proxy (platform) → Your Uvicorn Process
               ↓
        - SSL termination (decrypts HTTPS)
        - Load balancing (routes to healthy instances)
        - Static file serving
        - Rate limiting
        - Request buffering

When you deploy on Railway or Fly.io, the platform's reverse proxy handles SSLWhat is ssl/tls?Encryption protocols that secure the connection between a browser and a server, preventing eavesdropping on data in transit. termination. Your app receives plain HTTPWhat is http?The protocol browsers and servers use to exchange web pages, API data, and other resources, defining how requests and responses are formatted. on its internal port. This is why your FastAPI app binds to 0.0.0.0:$PORT with no SSL configuration, the proxy already handled it.

Headers from the proxy

The reverse proxy adds headers that tell your app about the original request:

# These headers come from the reverse proxy, not the client
# X-Forwarded-For: 203.0.113.42       ← client's real IP
# X-Forwarded-Proto: https             ← original protocol
# X-Request-ID: abc-123               ← request tracking

from fastapi import Request

@app.get("/debug")
async def debug(request: Request):
    return {
        "client_ip": request.headers.get("X-Forwarded-For"),
        "protocol": request.headers.get("X-Forwarded-Proto"),
    }
AI pitfall
AI often adds --ssl-keyfile and --ssl-certfile flags to the uvicorn start command. Behind a reverse proxy, this causes double encryption (proxy encrypts, then uvicorn tries to encrypt again). Your app should listen on plain HTTP; the proxy handles HTTPS.
05

Platform-specific domain setup

Railway

  1. Go to your service's Settings → Domains
  2. Click "Add Custom Domain"
  3. Add a CNAME record at your DNSWhat is dns?The system that translates human-readable domain names like google.com into the numerical IP addresses computers use to find each other. providerWhat is provider?A wrapper component that makes data available to all components nested inside it without passing props manually.
  4. Railway auto-provisions the certificate

Fly.io

fly certs create api.myapp.com
# Then add a CNAME record: api.myapp.com → my-app.fly.dev

Render

  1. Go to your service's Settings → Custom Domains
  2. Add your domain
  3. Add the CNAME record Render gives you
  4. Certificate is provisioned automatically
06

Quick reference

ConceptWhat it isWho manages it
DNS recordsMaps domain names to IP addressesYou, at your registrar
TLS certificateEnables HTTPS encryptionPlatform (auto via Let's Encrypt)
Reverse proxySits between internet and your appPlatform (managed)
SSL terminationDecrypts HTTPS before reaching your appReverse proxy
TTLHow long DNS records are cachedYou set it; lower = faster changes