Are you an LLM? You can read better optimized documentation at /chatroom/en/operations/deployment.md for this page in Markdown format
Deployment Architecture
This document describes ChatRoom's deployment options and architecture.
Single Instance Deployment
Docker Compose
yaml
services:
postgres:
image: postgres:16
environment:
POSTGRES_DB: chatroom
POSTGRES_USER: chatroom
POSTGRES_PASSWORD: ${DB_PASSWORD}
volumes:
- pgdata:/var/lib/postgresql/data
app:
build: .
ports:
- "8080:8080"
environment:
DATABASE_DSN: postgres://chatroom:${DB_PASSWORD}@postgres:5432/chatroom
JWT_SECRET: ${JWT_SECRET}
depends_on:
- postgres
prometheus:
image: prom/prometheus
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
volumes:
pgdata:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Kubernetes Deployment
Key Kubernetes Resources
yaml
# Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: chatroom
spec:
replicas: 3
template:
spec:
containers:
- name: chatroom
image: chatroom:latest
ports:
- containerPort: 8080
envFrom:
- configMapRef:
name: chatroom-config
- secretRef:
name: chatroom-secret
livenessProbe:
httpGet:
path: /healthz
port: 8080
readinessProbe:
httpGet:
path: /ready
port: 80801
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Horizontal Scaling
Implemented
- PostgreSQL NOTIFY: Cross-instance message broadcast
- Session Persistence:
ws_sessionstable stores online status - Stateless API: All instances share the same database
Optional Optimizations
| Option | Description |
|---|---|
| Sticky Sessions | Ensure WebSocket connections route to the same instance |
| Redis Session | Replace Postgres NOTIFY, higher throughput |
| Message Queue | Kafka/RabbitMQ for high message volume |
Environment Variables
| Variable | Default | Description |
|---|---|---|
PORT | 8080 | HTTP listen port |
DATABASE_DSN | - | Database connection string |
JWT_SECRET | - | JWT signing secret (must be set in production) |
ENV | dev | Runtime environment |
ACCESS_TOKEN_TTL_MINUTES | 15 | Access Token validity period |
REFRESH_TOKEN_TTL_DAYS | 7 | Refresh Token validity period |
WS_TICKET_TTL_SECONDS | 60 | WebSocket Ticket validity period |
ALLOWED_ORIGINS | - | CORS whitelist (comma-separated) |
POD_ID | - | Instance identifier (distributed scenario) |
🌐 Languages: English | 简体中文