advanced⏱60 minLesson 4 of 5
Scaling Multi-User Deployments
Scale OpenCode for teams and organizations. Learn multi-user architecture, resource management, performance optimization, and enterprise deployment patterns.
Scaling Multi-User Deployments
Architecture Patterns
| Pattern | Users | Use Case |
|---|---|---|
| Single-user | 1 | Personal development |
| Team | 2-10 | Small teams |
| Department | 10-50 | Engineering teams |
| Enterprise | 50+ | Organization-wide |
Multi-User Architecture
Configuration Management
Shared Configuration
Create a central configuration repository:
config-repo/
├── opencode.json
├── .opencode/
│ ├── skills/
│ └── hooks/
└── README.md
Distribution
bash
# Sync configuration
rsync -av config-repo/ /opt/opencode/config/
# Or use Git
cd /opt/opencode/config
git pull origin mainResource Management
API Key Pooling
json
{
"providers": {
"openai": {
"apiKeyPool": [
"${OPENAI_KEY_1}",
"${OPENAI_KEY_2}",
"${OPENAI_KEY_3}"
],
"strategy": "round-robin"
}
}
}Rate Limiting
json
{
"scaling": {
"rateLimit": {
"perUser": {
"requests": 100,
"window": "1h"
},
"global": {
"requests": 1000,
"window": "1h"
}
}
}
}Resource Quotas
json
{
"scaling": {
"quotas": {
"maxConcurrentSessions": 50,
"maxTokensPerUser": 1000000,
"maxStoragePerUser": "1GB"
}
}
}Performance Optimization
Caching
json
{
"scaling": {
"cache": {
"enabled": true,
"type": "redis",
"url": "redis://localhost:6379",
"ttl": 3600
}
}
}Connection Pooling
json
{
"scaling": {
"connectionPool": {
"maxConnections": 100,
"idleTimeout": 30000
}
}
}Load Balancing
yaml
# nginx.conf
upstream opencode {
least_conn;
server opencode1:3000;
server opencode2:3000;
server opencode3:3000;
}
server {
listen 443;
location / {
proxy_pass http://opencode;
}
}User Management
Role-Based Access
json
{
"users": {
"admin": {
"role": "admin",
"permissions": ["*"]
},
"developer": {
"role": "developer",
"permissions": ["read", "write", "execute"]
},
"viewer": {
"role": "viewer",
"permissions": ["read"]
}
}
}Session Management
json
{
"scaling": {
"sessions": {
"maxConcurrent": 10,
"timeout": 3600,
"cleanupInterval": 300
}
}
}Monitoring
Metrics Collection
json
{
"monitoring": {
"enabled": true,
"metrics": {
"requests": true,
"latency": true,
"errors": true,
"tokens": true
},
"export": {
"prometheus": {
"enabled": true,
"port": 9090
}
}
}
}Health Checks
bash
# Check instance health
curl http://localhost:3000/health
# Response
{
"status": "healthy",
"uptime": 86400,
"sessions": 45,
"memory": "2.5GB"
}Deployment Options
Docker
dockerfile
FROM node:18-alpine
RUN npm install -g opencode
COPY opencode.json /app/
WORKDIR /app
CMD ["opencode", "--host", "0.0.0.0"]Kubernetes
yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: opencode
spec:
replicas: 3
selector:
matchLabels:
app: opencode
template:
spec:
containers:
- name: opencode
image: opencode:latest
ports:
- containerPort: 3000
env:
- name: OPENAI_API_KEY
valueFrom:
secretKeyRef:
name: opencode-secrets
key: api-keyBest Practices
| Practice | Reason |
|---|---|
| Centralized config | Consistent behavior |
| API key pooling | Cost optimization |
| Rate limiting | Fair usage |
| Monitoring | Visibility |
| Health checks | Reliability |
| Auto-scaling | Performance |
Practice Questions
Practice Question
What is the benefit of API key pooling?
Practice Question
What does rate limiting prevent?
Practice Question
Why use a load balancer?
Practice Question
What should you monitor in a multi-user deployment?
Practice Question
How do you distribute configuration to multiple instances?
Success
Key Takeaways
- Use centralized configuration for consistent behavior across instances
- API key pooling distributes costs and rate limits
- Rate limiting prevents abuse and ensures fair usage
- Caching with Redis improves response times
- Load balancing distributes requests for scalability
- Monitor requests, latency, tokens, and errors
- Docker and Kubernetes enable scalable deployments
Progress80%