Skip to main content

Auto-Scaling Configuration

Enable automatic scaling based on CPU and memory usage to handle varying workloads efficiently. When enabled, the platform automatically adjusts the number of running instances to match demand.

Overview​

The autoscaler monitors your app's resource usage and intelligently scales up during high demand and down during low usage periods, optimizing both performance and cost.

How It Works​

The platform scales the app:

  1. Metrics: the platform reads the average CPU and memory use of the app's instances, as a percent of the app's size, on its own schedule (about every 15 seconds). There is no polling interval to set.
  2. Instance count: it sets the number of instances so the average sits at your thresholds (instances = current instances x average use / threshold, rounded up, taking the larger of the CPU and memory answers), always between the minimum and maximum.
  3. Scale up: at most 50% more instances per scale-up cooldown, following the highest count asked for during that window.
  4. Scale down: at most 25% fewer instances per scale-down cooldown, following the highest count asked for during that window, so a short dip does not remove instances.

Enabling Autoscaling​

During Deployment​

  1. Navigate to Apps and deploy your application
  2. Scroll to the Autoscaling (Optional) section
  3. Check Enable Autoscaling
  4. Configure thresholds and limits based on your needs

Changing Autoscaling After Deployment​

  1. Open the app and stay on its Overview tab
  2. On the Autoscaling card, click Edit
  3. Check or clear Enable Autoscaling and set the values
  4. Click Save

A running app rolls out with the change at once, with no downtime: its autoscaler is created, changed or, when you clear Enable Autoscaling, removed (the app then runs its set number of instances). A stopped app gets it when it starts. Through the API: autoscaling on PATCH /api/v1/apps/:id (the whole block, or null to turn it off), or autoscaling on client.apps.update in the Python SDK.

Configuration Options​

SettingDefaultRangeDescription
Min Replicas11-20Minimum number of instances always running
Max Replicas102-50Maximum number of instances to scale to (must be greater than Min Replicas)
CPU Threshold70%1-100%Scale up when average CPU exceeds this
Memory Threshold80%1-100%Scale up when average memory exceeds this
Scale Up Cooldown60s30-600sAdds at most half the instances again once per this period
Scale Down Cooldown120s60-900sRemoves at most a quarter of the instances once per this period
max_replicas Validation

max_replicas must be greater than min_replicas. Both have a minimum value of 1.

Understanding Thresholds​

CPU Threshold: Percentage of the CPU in the app's size (set when you deploy it)

  • If the app's size has 1 CPU and the threshold is 70%, scaling triggers at 0.7 CPU
  • Lower thresholds = more aggressive scaling
  • Higher thresholds = fewer instances, lower cost

Memory Threshold: Percentage of the memory in the app's size

  • If the app's size has 1 GB of memory and the threshold is 80%, scaling triggers at about 819 MB
  • Critical for preventing OOM (Out of Memory) errors
  • Recommended: 70-80% for memory-intensive apps

Scaling Behavior​

Example​

An app sized at 1 CPU and 1 GB of memory, with a CPU threshold of 70% and a memory threshold of 80%, runs 2 instances averaging 0.9 CPU (90%) and 600 MB (59%). CPU asks for 2 x 90 / 70 = 2.6, so 3 instances; memory asks for 2 x 59 / 80 = 1.5, so 2. The platform runs 3 (the larger), within the scale-up limit of 50% more per cooldown.

When use falls back, the count follows it down by at most 25% per scale-down cooldown.

Cooldown Periods​

  • Scale Up Cooldown: 60 seconds (30-600s through the API)
  • Scale Down Cooldown: 120 seconds (60-900s through the API)

Each is the window over which the platform takes the highest count asked for before it changes the count, and the period of its 50% (up) or 25% (down) step. This prevents rapid scaling oscillations ("flapping").

Example Configurations​

Light Traffic API (Development)​

Best for development and testing with predictable low traffic.

Size (set when you deploy): 0.5 CPU, 512 MB memory

Autoscaling: Disabled (use fixed instances instead)

  • Fixed Instances: 1

Use Case: Development, testing, personal projects


Production Web App (Moderate Traffic)​

Balanced configuration for production apps with moderate traffic.

Size (set when you deploy): 1 CPU, 1 GB memory

Autoscaling:

  • Enabled: Yes
  • Min Replicas: 2
  • Max Replicas: 10
  • CPU Threshold: 70%
  • Memory Threshold: 80%
  • Scale Up Cooldown: 60s
  • Scale Down Cooldown: 120s

Use Case: Production web apps, REST APIs, dashboards

Expected Behavior:

  • Always 2 instances for high availability
  • Scales to 10 during traffic spikes
  • Handles 5x traffic increase automatically

High-Traffic API (Variable Load)​

Aggressive scaling for APIs with unpredictable traffic patterns.

Size (set when you deploy): 2 CPU, 2 GB memory

Autoscaling:

  • Enabled: Yes
  • Min Replicas: 3
  • Max Replicas: 20
  • CPU Threshold: 60%
  • Memory Threshold: 70%
  • Scale Up Cooldown: 30s
  • Scale Down Cooldown: 60s

Use Case: High-traffic APIs, real-time services, production critical apps

Expected Behavior:

  • Always 3 instances for redundancy
  • Scales aggressively (lower thresholds)
  • Fast response to load changes
  • Can handle 6-7x traffic increases

CPU-Intensive Processing​

Optimized for compute-heavy workloads.

Size (set when you deploy): 4 CPU, 1 GB memory

Autoscaling:

  • Enabled: Yes
  • Min Replicas: 2
  • Max Replicas: 15
  • CPU Threshold: 60% (lower for CPU-heavy apps)
  • Memory Threshold: 80%

Use Case: Image processing, video transcoding, data analysis


Memory-Intensive Application​

Optimized for memory-heavy workloads.

Size (set when you deploy): 1 CPU, 4 GB memory

Autoscaling:

  • Enabled: Yes
  • Min Replicas: 2
  • Max Replicas: 10
  • CPU Threshold: 70%
  • Memory Threshold: 70% (lower to prevent OOM)

Use Case: In-memory caching, ML inference, data processing

Monitoring Autoscaling​

View autoscaling activity in your app details page:

Metrics tab​

  • Instances: how many instances are running and ready, out of how many the autoscaler wants
  • CPU and Memory: usage across all instances, against the size you set

Scale to Zero When Idle​

An app can sleep when nobody uses it, so it costs no compute while idle. It is off by default.

Turning It On​

  • When you deploy: in the Autoscaling (Optional) section, switch on Scale to zero when idle and set the minutes.
  • After deployment: on the app's Overview tab, on the Autoscaling card, switch on Scale to zero when idle. To change the minutes, type a new number and click Save.

Idle minutes can be from 1 to 1440 (24 hours). The default is 15.

How It Works​

  1. Sleeping: once no request and no open connection (WebSocket or server-sent events) has reached the app for the idle minutes, it goes to zero instances. Its status shows Sleeping. Nothing runs, so no compute is charged; its disk and volumes are kept.
  2. Waking: the next request wakes it. A browser opening the app sees a Starting page that opens the app as soon as it is ready. An API call, webhook or WebSocket waits until the app is ready (up to 3 minutes), then gets its answer.
  3. Budgets and credits: a wake is checked like a start. If a budget or your credits do not allow it, the request is refused and the app stays asleep.
  4. Stopped apps: an app you stopped (or one stopped by a schedule or budget) is never woken by a request. Only a sleeping app wakes.

A sleeping app shows Start and Stop. Start wakes it now; Stop stops it so requests no longer wake it. Turning the setting off on a sleeping app starts it at once.

With autoscaling on, a woken app starts at its minimum instances and the autoscaler takes over from there.

Through the API: scaleToZero on PATCH /api/v1/apps/:id ({"enabled": true, "idleMinutes": 15}, or null to turn it off), or scale_to_zero on client.apps.update in the Python SDK ({"idle_minutes": 15}, or False).

When to Keep It Off​

The first request after a sleep waits while the app starts, often 30 to 90 seconds. Keep the setting off for:

  • Apps called by webhook senders that give up in under a minute
  • Apps that must answer every request quickly

Best Practices​

Traffic Patterns​

Predictable Traffic:

  • Use fixed instances instead of autoscaling
  • Right-size resource allocation
  • Lower operational complexity

Unpredictable Traffic:

  • Enable autoscaling with higher max replicas
  • Set lower thresholds for faster response
  • Monitor scaling patterns and adjust

Resource Allocation​

CPU-Intensive Apps:

  • Lower CPU threshold (60%)
  • Higher CPU limits
  • Prevents performance degradation

Memory-Intensive Apps:

  • Lower memory threshold (70%)
  • Higher memory limits
  • Prevents OOM errors

Balanced Apps:

  • Standard thresholds (70% CPU, 80% memory)
  • Balanced resource allocation

Cost Optimization​

  1. Start Conservative: Begin with low max replicas, increase if needed
  2. Monitor Patterns: Review metrics to find optimal settings
  3. Use Min Replicas Wisely: Higher min = higher baseline cost
  4. Development Environments: Disable autoscaling, use 1 instance
  5. Tune Cooldowns: Adjust scale_up_cooldown (30-600s) and scale_down_cooldown (60-900s) based on your traffic patterns

Troubleshooting​

Not Scaling Up​

Problem: CPU/memory high but no new instances

Check:

  • Reached max replicas limit?
  • Currently in cooldown period?
  • Thresholds configured correctly?
  • Metrics being collected?

Solution:

# Lower thresholds for more aggressive scaling
cpu_threshold: 60% # Was 70%
memory_threshold: 70% # Was 80%

# Increase max replicas
max_replicas: 20 # Was 10

Scaling Flapping​

Problem: Instances constantly scaling up and down

Check:

  • Thresholds too close to scale-down threshold?
  • Resource limits too low?

Solution:

# Increase cooldown periods
scale_up_cooldown: 120 # Was 60
scale_down_cooldown: 300 # Was 120

Slow Scaling​

Problem: Scaling happens too slowly

Check:

  • Thresholds too high?
  • Cooldown periods too long?

Solution:

# Lower thresholds
cpu_threshold: 60% # Was 70%

# Reduce cooldown
scale_up_cooldown: 30 # Minimum allowed

High Costs​

Problem: Too many instances running

Solution:

# Reduce min replicas
min_replicas: 1 # Was 3

# Reduce max replicas
max_replicas: 5 # Was 20

# Allow more aggressive scale-down
# (automatic - 50% of thresholds)

Next Steps​