Skip to main content

Scaling Guide

Guide for scaling the SBM CRM Platform to handle increased load.

Scaling Strategies​

Horizontal Scaling​

Add more servers to handle increased load.

Vertical Scaling​

Increase resources (CPU, RAM) on existing servers.

Database Scaling​

  • Read replicas for read-heavy workloads
  • Connection pooling
  • Query optimization

Application Scaling​

Load Balancing​

Set up Nginx load balancer:

upstream sbmcrm_api {
least_conn;
server 10.0.1.10:3000;
server 10.0.1.11:3000;
server 10.0.1.12:3000;
}

server {
listen 80;
server_name api.yourdomain.com;

location / {
proxy_pass http://sbmcrm_api;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}

Auto-Scaling​

AWS Auto Scaling​

{
"AutoScalingGroupName": "sbmcrm-api-asg",
"MinSize": 2,
"MaxSize": 10,
"DesiredCapacity": 3,
"TargetTrackingConfigurations": [
{
"PredefinedMetricSpecification": {
"PredefinedMetricType": "ASGAverageCPUUtilization"
},
"TargetValue": 70.0
}
]
}

Container Orchestration​

Kubernetes Deployment​

apiVersion: apps/v1
kind: Deployment
metadata:
name: sbmcrm-api
spec:
replicas: 3
selector:
matchLabels:
app: sbmcrm-api
template:
metadata:
labels:
app: sbmcrm-api
spec:
containers:
- name: api
image: sbmcrm/api:latest
resources:
requests:
memory: "512Mi"
cpu: "500m"
limits:
memory: "1Gi"
cpu: "1000m"

Database Scaling​

Read Replicas​

Set up PostgreSQL read replicas:

# On primary server
# Edit postgresql.conf
wal_level = replica
max_wal_senders = 3

# Create replication user
CREATE USER replicator WITH REPLICATION PASSWORD 'password';

# On replica server
# Edit recovery.conf
standby_mode = 'on'
primary_conninfo = 'host=primary_server port=5432 user=replicator'

Connection Pooling​

Use PgBouncer:

[databases]
sbmcrm_production = host=localhost port=5432 dbname=sbmcrm_production

[pgbouncer]
pool_mode = transaction
max_client_conn = 1000
default_pool_size = 25

Query Optimization​

  • Add indexes for frequently queried fields
  • Use query caching
  • Optimize slow queries
  • Use materialized views for complex reports

Cache Scaling​

Redis Cluster​

Set up Redis cluster for high availability:

# Create cluster
redis-cli --cluster create \
10.0.1.20:6379 10.0.1.21:6379 10.0.1.22:6379 \
10.0.1.23:6379 10.0.1.24:6379 10.0.1.25:6379 \
--cluster-replicas 1

Cache Strategy​

  • Cache frequently accessed data
  • Set appropriate TTLs
  • Use cache warming for critical data
  • Monitor cache hit rates

Message Queue Scaling​

RabbitMQ Cluster​

Set up RabbitMQ cluster:

# Join cluster
rabbitmqctl stop_app
rabbitmqctl join_cluster rabbit@node1
rabbitmqctl start_app

Queue Management​

  • Use multiple queues for different priorities
  • Set up dead letter queues
  • Monitor queue depths
  • Scale workers based on queue length

CDN for Static Assets​

CloudFront / Cloudflare​

Serve static assets through CDN:

  • Images
  • JavaScript bundles
  • CSS files
  • Fonts

Monitoring Scaling​

Key Metrics​

  • CPU utilization
  • Memory usage
  • Request rate
  • Response time
  • Error rate
  • Queue depth
  • Database connections

Scaling Triggers​

Set up auto-scaling based on:

  • CPU > 70%
  • Memory > 80%
  • Request rate > threshold
  • Response time > threshold

Cost Optimization​

Right-Sizing​

  • Monitor resource usage
  • Adjust instance sizes
  • Use reserved instances for predictable workloads
  • Spot instances for non-critical workloads

Caching​

  • Reduce database load with caching
  • Cache API responses
  • Use CDN for static assets

Best Practices​

  1. Start Small - Scale up as needed
  2. Monitor Metrics - Track scaling effectiveness
  3. Test Scaling - Load test before scaling
  4. Document Changes - Keep scaling decisions documented
  5. Review Regularly - Optimize based on actual usage
  6. Plan for Peaks - Handle traffic spikes
  7. Cost Awareness - Balance performance and cost