Featured image of post VPS Cost Optimization Guide: Complete Strategies to Save 70% on Cloud Spending

VPS Cost Optimization Guide: Complete Strategies to Save 70% on Cloud Spending

From data-driven resource right-sizing to storage tiering, auto-scaling, and spot instances — transform your $100+/month VPS bill into $30 while maintaining 99.9% uptime.

Introduction

Does your monthly VPS bill give you heart palpitations?

  • Bought a 4-core 8GB VPS, but actual CPU utilization is under 10%
  • Disk space grew from 20GB to 100GB, but most of it is cold data
  • Kept 2-3 idle servers “just in case”
  • Year-end bill is 3× what you expected

The problem isn’t that you overpaid — it’s that you haven’t optimized resources based on actual usage.

Statistics show that unoptimized cloud infrastructure wastes 30-50% of its budget. Through the practical strategies in this guide, you can reduce VPS costs by 60-70% while maintaining or even improving service availability.


Step 1: Establish Cost Visibility

1.1 Create a Resource Monitoring Dashboard

Before optimizing, you must know where your money goes. Use Prometheus + Grafana to create resource utilization dashboards:

# Deploy Node Exporter on your VPS
docker run -d \
  --name node-exporter \
  --network host \
  --pid host \
  -v /proc:/host/proc:ro \
  -v /sys:/host/sys:ro \
  -v /:/rootfs:ro \
  --mount type=bind,source=/etc/hostname,target=/etc/hostname \
  prom/node-exporter

# Scrape metrics via Prometheus
# prometheus.yml
scrape_configs:
  - job_name: 'vps-metrics'
    static_configs:
      - targets: ['localhost:9100']

1.2 Key Monitoring Metrics

MetricOptimization ThresholdNotes
CPU Utilization< 30% consider downsizingLong-term low utilization means oversupply
Memory Usage< 40% consider downsizingNote: buff/cache shouldn’t count as real usage
Disk I/O< 20% can use HDDLow I/O workloads can use cheaper HDD
Network Bandwidth< 50% of peakEstimate based on historical peaks
Disk Space< 60% utilizedKeep 40% buffer space

1.3 Cost Allocation Dashboard

Create per-VPS billing tracking:

#!/bin/bash
# cost-tracker.sh - Daily cost recording
VPS_NAME=$1
DAILY_COST=$2
DATE=$(date +%Y-%m-%d)

echo "$DATE,$VPS_NAME,$DAILY_COST" >> /opt/cost-tracking/history.csv

Step 2: Data-Driven Resource Adjustment

2.1 CPU Resource Optimization

Scenario A: Long-term Low Utilization

If your VPS has < 15% CPU utilization 24/7:

  1. Downgrade to smaller specs: e.g., 4C8G → 2C4G
  2. Switch billing model: Some providers offer per-second billing, cheaper for low utilization
  3. Use ARM architecture: AWS Graviton / Alibaba Cloud ARM instances offer better price-performance
# View historical CPU utilization (last 30 days)
promtool query instant prometheus:9090 \
  'avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[30d])) * 100'

Scenario B: Intermittent High Utilization

If CPU peaks at 80-90% but stays below 20% otherwise:

  1. Enable auto-scaling: Dynamically adjust instance count based on load
  2. Use spot instances: Non-critical workloads can save 60-70% with spot instances
  3. Consolidate workloads: Migrate multiple low-utilization services to one machine

2.2 Memory Optimization

Memory is a significant cost component for VPS.

Optimization strategies:

# Check memory usage
free -h
# Note: buff/cache is not real usage

# Find memory-intensive processes
ps aux --sort=-%mem | head -10

# Check for memory leaks
vmstat 1 5
ProblemSolution
Memory usage constantly growingCheck for memory leaks, set container memory limits
Frequent swap usageConsider upgrading RAM, or optimize application config
High buff/cache usageNormal behavior, can free with echo 3 > /proc/sys/vm/drop_caches

2.3 Disk Space Tiering

Cold data archiving strategy:

#!/bin/bash
# storage-tiering.sh - Automatic cold data archival

# Find files not accessed in 90 days
find /data -type f -mtime +90 -exec mv {} /mnt/archive/ \;

# Compress archives periodically
tar czf /mnt/archive/backup-$(date +%Y%m%d).tar.gz /mnt/archive/old-files/

# Upload to cheap object storage (optional)
rclone copy /mnt/archive/ backup:my-bucket/cold-storage/
Data TierAccess FrequencyStorage SolutionCost Comparison
Hot dataMultiple times dailySSD/NVMe$0.10/GB/month
Warm dataSeveral times weeklyHDD$0.03/GB/month
Cold dataSeveral times monthlyObject storage$0.01/GB/month
Archive dataRarelyTape/Deep archive$0.004/GB/month

Step 3: Auto-Scaling Strategies

3.1 Horizontal Scaling (Add Instances)

Best for: Services with fluctuating traffic (websites, APIs)

# Kubernetes HPA configuration
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: web-service
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: web-service
  minReplicas: 1
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 70

Cost calculation:

  • Base instance: $20/month
  • Peak extra instances: $20 × 5 instances × 10 hours/day ÷ 30 days = $33/month
  • Total: $53/month (saving $147/month vs running 10 instances constantly)

3.2 Vertical Scaling (Adjust Instance Specs)

Best for: Single-service workloads with stable utilization

# Use DigitalOcean snapshot migration
doctl compute snapshot create my-vps-snapshot --instance-id 123456
doctl compute droplet create my-vps-small \
  --image my-vps-snapshot \
  --size s-1vcpu-1gb \
  --region nyc1

3.3 Auto-Shutdown Strategy

For non-24/7 services (dev environments, test environments):

#!/bin/bash
# auto-shutdown.sh

# Business hours: 9:00-18:00
START_HOUR=9
END_HOUR=18

CURRENT_HOUR=$(date +%H)

if [ "$CURRENT_HOUR" -lt "$START_HOUR" ] || [ "$CURRENT_HOUR" -ge "$END_HOUR" ]; then
    # Non-business hours, shutdown dev server
    doctl compute droplet action stop 123456
fi

Savings: 15 hours saved per day, 50% cost reduction monthly.


Step 4: Spot Instances & Reserved Instances

4.1 Spot Instances

Save 60-70%, but can be reclaimed at any time.

ScenarioSuitable?
Batch processing✅ Perfect fit
Containerized stateless services✅ Suitable (with auto-recovery)
Development/testing environments✅ Suitable
Production databases❌ Not suitable
Public API services⚠️ Requires redundancy design
# AWS EC2 spot instance launch
aws ec2 run-instances \
  --instance-market-options 'SpotOptions={InstanceInterruptionBehavior=terminate}' \
  --instance-type m5.large \
  --min-count 1 \
  --max-count 1

4.2 Reserved Instances

Save 30-60%, ideal for long-term stable workloads.

# AWS Reserved Instance purchase example
aws ec2 purchase-reserved-instances-offering \
  --reserved-instances-offering-id <offer-id> \
  --instance-count 1

Hybrid strategy:

  • Base load with reserved instances (guaranteed availability)
  • Peak load with spot instances (cost reduction)
  • Burst load with on-demand instances (flexibility)

Step 5: Storage Cost Optimization

5.1 Object Storage vs Block Storage

Data TypeOriginalOptimizedSavings
Static assetsEBS block storageS3 + CDN70-80%
Backup filesLocal diskObject storage60-70%
Log archivesLocal diskGlacier90%+
User filesLocal diskObject storage50-60%

5.2 Smart Compression & Deduplication

# Enable ZFS compression
zfs set compression=zstd rpool/data

# Clean up unused packages regularly
apt autoremove --purge -y
apt clean

# Clean Docker resources
docker system prune -a --force
docker volume prune --force

5.3 CDN for Static Resources

Migrate static assets (images, CSS, JS) to CDN:

SolutionCostNotes
Cloudflare Pro$20/monthBasic CDN + security
Cloudflare Free$0Suitable for low-traffic sites
Self-hosted CDN$0.02/GBSuitable for high traffic

Step 6: Architecture Optimization to Reduce Infrastructure Needs

6.1 From Monolith to Microservices

Before optimization: One large VPS running all services

  • 4C8G, $50/month
  • Single point of failure affects all services

After optimization: Multiple small VPS instances分工运行

  • 4 × 1C2G, $5/month = $20/month
  • Fault isolation, easier to scale

6.2 Containerization & Resource Limits

# docker-compose.yml - Resource limits
services:
  web:
    image: nginx:latest
    deploy:
      resources:
        limits:
          cpus: '0.5'
          memory: 256M
        reservations:
          cpus: '0.25'
          memory: 128M

6.3 Serverless Architecture

For low-frequency services, consider serverless options:

Service TypeTraditionalServerlessSavings
Scheduled tasksRunning 24/7Lambda/Cloud Functions90%+
Low-frequency APIPermanent processAPI Gateway + Lambda80%+
Batch processingFixed instanceElastic containers70%+

Real-World Case: From $120/month to $28/month

Before Optimization

ResourceSpecsMonthly Cost
Web server4C8G SSD$40
Database server4C16G SSD$60
Backup server2C4G 1TB HDD$20
Total$120

Optimization Measures

  1. Web server downgrade: CPU utilization < 20% long-term, downgrade to 2C4G
  2. Database optimization: Add cache layer, reduce DB load, downgrade to 2C8G
  3. Backup tiering: Hot backups kept 7 days, cold backups archived to object storage
  4. Enable spot instances: Development environment uses spot instances

After Optimization

ResourceSpecsMonthly Cost
Web server2C4G$20
Database server2C8G$30
Backups (object storage)1TB$2.30
Dev environment (spot)1C2G$5
Total$57.30

Actual savings: $120 - $57.30 = $62.70/month (52% savings)

With further architecture optimization (adding cache, enabling CDN), costs can drop to $28/month (77% savings).


Monitoring Optimization Results

Establish continuous monitoring to ensure stability after optimization:

# Alertmanager rules
groups:
  - name: cost-optimization
    rules:
      - alert: HighCPUUtilization
        expr: node_cpu_seconds_total{mode="idle"} < 0.3
        for: 10m
        labels:
          severity: warning
        annotations:
          summary: "CPU utilization exceeds 70%, consider scaling up"
      
      - alert: StorageNearCapacity
        expr: node_filesystem_avail_bytes / node_filesystem_size_bytes < 0.2
        for: 5m
        labels:
          severity: critical
        annotations:
          summary: "Disk space below 20%, need to clean or expand"

Summary

VPS cost optimization is a continuous process requiring:

  1. Establish visibility: Monitor resource usage, track every expense
  2. Data-driven decisions: Adjust resources based on actual usage, not guesswork
  3. Automated strategies: Use auto-scaling, spot instances to reduce manual effort
  4. Architecture optimization: Fundamentally reduce demand for expensive resources
  5. Continuous monitoring: Regularly review bills, discover new optimization opportunities

Remember: The best optimization is avoiding unnecessary resource consumption, not saving money on wasted resources.

Start today — run the monitoring script for a week, analyze the data, then create your optimization plan. You’ll be amazed at how much you can save!


Appendix: Useful Optimization Tools

ToolPurposeLink
PrometheusMetrics monitoringprometheus.io
GrafanaVisualization dashboardsgrafana.com
SpotINSTSpot instance managementspotinst.com
CloudHealthCloud cost analysiscloudhealthtech.com
rcloneCloud storage syncrclone.org

📺 看视频版教程 → DuckDB Lab YouTube

Subscribe for more DuckDB & AI automation tutorials