Deploying WebSocket Applications

1. Deploying to Cloud Platforms

PlatformWS Support
AWS (EC2/ECS/EKS + ALB/NLB)Full
GCP (GKE / Cloud Run)Full; Cloud Run has 1h cap
Azure (AKS / App Service)Full with sticky
Fly.ioNative, region-routed
Render / RailwaySupported

2. Deploying to Heroku

DetailNotes
WS supportYes, on all dynos
Idle timeout55s (router); heartbeat ≤ 45s
Sticky sessionsLab feature
Max conn / dyno~5000

3. Deploying to Vercel

ConstraintDetail
Serverless functionsNo long-lived WS
RecommendedExternal WS service (Ably/Pusher/PartyKit)
Edge functionsLimited WS via upgradeWebSocket

4. Deploying to DigitalOcean

ResourceWS Notes
DropletFull Linux server
App PlatformNative WS support
Load BalancerL4 passthrough or L7 (HTTP)
KubernetesStandard ingress (nginx)

5. Configuring Docker Containers

Example: Dockerfile

FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
EXPOSE 8080
ENV NODE_ENV=production
CMD ["node", "server.js"]
SettingDetail
EXPOSEWS port
ulimit nofileIncrease for many conns
HealthcheckHEALTHCHECK CMD curl /healthz
Signal handlingSIGTERM → graceful drain

6. Setting Environment Variables

VarPurpose
PORTListen port
NODE_ENVproduction
JWT_PUBLIC_KEYVerify tokens
REDIS_URLPub/sub backplane
LOG_LEVELinfo / debug

7. Configuring SSL/TLS Certificates

SourceDetail
Let's Encrypt + certbotFree, auto-renew
AWS ACMFree for AWS LBs
CloudflareEdge TLS
Terminate at LBCommon pattern

8. Setting Up Process Managers

ToolUse
PM2Node clustering, restart
systemdOS-level service
Docker / K8sContainer orchestration
forever / nodemonDev only

9. Implementing Health Checks

Example: Liveness vs readiness

app.get("/livez",  (_, res) => res.send("ok"));
app.get("/readyz", async (_, res) => {
  try { await redis.ping(); res.send("ready"); }
  catch { res.status(503).send("down"); }
});
EndpointPurpose
/livezProcess alive
/readyzCan accept traffic
/healthzAggregate

10. Configuring Auto-Restart

TriggerDetail
CrashPM2/systemd restart
OOMK8s pod restart
Healthcheck failK8s readiness flip
DeployRolling update