Skip to main content

Application Scaling

Miren automatically scales HTTP service instances based on requests through HTTP ingress. This page explains how scaling works and how to configure it for your needs.

Scaling out across machines

This page is about how many instances of your app run. When the machine itself runs out of room, you add more machines to the cluster instead: see Distributed Runners.

Minimum working example​

Configure scaling in .miren/app.toml under [services.<name>.concurrency]:

[services.web.concurrency]
mode = "auto"
requests_per_instance = 10
scale_down_delay = "15m"

[services.worker.concurrency]
mode = "fixed"
num_instances = 2

auto scales the service with HTTP requests through ingress, all the way down to zero when idle; fixed runs an exact instance count. Deploy and the settings take effect. Both modes and every field are explained below.

How Autoscaling Works​

By default, Miren uses autoscaling for web services. As HTTP requests through Miren's ingress increase, Miren automatically launches additional instances to handle the load. When that traffic decreases, instances are scaled back down.

Auto mode only tracks HTTP ingress traffic

Only HTTP requests through Miren's ingress count as activity for autoscaling. TCP/UDP traffic, node-port traffic, and direct calls between services that bypass ingress do not keep an auto-mode service active or wake it after it scales to zero. Use fixed mode for services that need to stay running for these traffic paths, background work, or other non-ingress activity.

This approach is similar to Google Cloud Run's scaling model: instead of guessing how many replicas you need, Miren observes actual demand and adjusts automatically.

Why Autoscaling by Default?​

Guessing instance counts is error-prone:

  • Too few instances and your app can't handle traffic spikes
  • Too many instances waste resources when traffic is low
  • Manual scaling requires constant monitoring and adjustment

With autoscaling, Miren handles this automatically so you can focus on your application.

Scale to Zero​

Miren can scale your application all the way down to zero instances when there's no traffic. This is particularly valuable for self-hosted deployments where resource efficiency matters:

  • Better utilization: Run dozens of apps on a single server—only active apps consume resources
  • Lower costs: Development, staging, and low-traffic production apps don't waste memory or CPU
  • No idle tax: Internal tools, webhooks, and scheduled tasks don't need dedicated instances waiting around

When an HTTP request arrives through ingress for a scaled-to-zero app, Miren quickly spins up an instance to handle it. The first request may have slightly higher latency, but subsequent requests are served immediately.

Scaling Modes​

Miren supports two scaling modes:

ModeDescriptionUse Case
autoScales instances based on HTTP requests through ingressStateless HTTP services, APIs
fixedRuns a set number of instancesTCP/UDP services, direct-only services, databases, workers, stateful services

Default Behavior​

When you deploy without explicit configuration:

  • web service: Auto mode with 10 concurrent requests per instance, 15-minute scale-down delay
  • All other services: Fixed mode with 1 instance

Configuring Scaling​

Configure scaling in your .miren/app.toml file under [services.<name>.concurrency].

Auto Mode (Default for Web)​

Auto mode scales HTTP service instances based on concurrent requests through ingress:

[services.web.concurrency]
mode = "auto"
requests_per_instance = 10
scale_down_delay = "15m"

Auto Mode Options​

OptionDescriptionDefault
modeMust be "auto""auto" for web
requests_per_instanceTarget concurrent requests per instance10
scale_down_delayHow long to wait before scaling down idle instances15m

How Auto Mode Calculates Instances​

Miren targets requests_per_instance concurrent requests per instance, the number of in-flight requests being handled simultaneously, not requests over a period of time. For example, with requests_per_instance = 10:

  • 5 concurrent requests → 1 instance
  • 15 concurrent requests → 2 instances
  • 100 concurrent requests → 10 instances

This means a single instance handling fast requests (e.g., 10ms each) can serve thousands of requests per second while staying under the concurrency limit.

The scale_down_delay prevents thrashing when traffic fluctuates. An instance won't be terminated until it has been idle for this duration.

Fixed Mode​

Fixed mode runs a specific number of instances regardless of traffic:

[services.worker.concurrency]
mode = "fixed"
num_instances = 3

Fixed Mode Options​

OptionDescriptionDefault
modeMust be "fixed""fixed" for non-web
num_instancesExact number of instances to run1

Disabling an App​

To turn an app off without deleting it, disable it:

miren app disable -a myapp --reason "Moved to the new cluster"

Every service, autoscaled or fixed, is held at zero until you run miren app enable. Running instances shut down and visitors get a 503 holding page. A disabled app is frozen, so deploys, rollbacks, config changes such as miren env set, and miren app restart are all refused until it's enabled. That's what lets miren app enable bring it back as it was. The app keeps its versions, routes, environment, disks, and addons. Scheduled tasks pause, but miren app run still works for a backup or migration while the app is off. Task runs already in progress finish, and addons keep running.

Enabling resumes scheduled tasks from the enable time. Any pending scheduled ticks at or before that time are discarded, including ticks that became due before the app was disabled but had not yet been picked up.

To take traffic down while the app keeps running and can still be deployed, use maintenance mode instead.

Unlike an autoscaled service that has scaled to zero, a disabled app doesn't wake on traffic. miren app list shows it as disabled, and miren app status shows when and why.

miren app enable returns fixed services to their configured count right away; autoscaled services start on the next request.

Updating a Disabled App​

To update an app that should stay off, such as a fallback copy on another cluster, turn it on behind maintenance mode, deploy, check it, and turn it off again:

miren route down app.example.com --reason "Updating"
miren app enable -a myapp
miren deploy
miren app status -a myapp
miren app disable -a myapp --reason "Fallback copy"
miren route up app.example.com

Run route down for each hostname that points at the app, since anything you miss serves visitors while it's on. Bring the routes back up at the end, or they'll still be down the next time you enable the app.

Enabling turns the whole app on, and maintenance mode only stops traffic on its routes. For that window workers run, scheduled tasks fire, and deploy tasks run during the deploy. If the copy shares a database or sends mail, give it a setting of its own that keeps those side effects quiet, such as miren env set -e FALLBACK_MODE=1, and set it while the app is on.

Examples​

High-Traffic API​

For an API that handles many concurrent requests:

[services.web.concurrency]
mode = "auto"
requests_per_instance = 50
scale_down_delay = "5m"

This configuration:

  • Allows 50 concurrent requests per instance (higher density)
  • Scales down after 5 minutes of reduced traffic (faster scale-down)

Background Worker​

For a background job processor:

[services.worker.concurrency]
mode = "fixed"
num_instances = 2

This runs exactly 2 worker instances at all times.

Database Service​

For a database that should always be running:

[services.db]
image = "postgres:16"

[services.db.concurrency]
mode = "fixed"
num_instances = 1

Complete Multi-Service App​

name = "myapp"

# Web service: autoscales based on traffic
[services.web.concurrency]
mode = "auto"
requests_per_instance = 20
scale_down_delay = "10m"

# Worker service: fixed at 3 instances
[services.worker.concurrency]
mode = "fixed"
num_instances = 3

# Database: single instance with persistent storage
[services.db]
image = "postgres:16"

[services.db.concurrency]
mode = "fixed"
num_instances = 1

[[services.db.disks]]
name = "postgres-data"
mount_path = "/var/lib/postgresql/data"
size_gb = 20

Scaling and Disks​

Services with persistent disks must use fixed mode with exactly 1 instance:

[services.db.concurrency]
mode = "fixed"
num_instances = 1

[[services.db.disks]]
name = "db-data"
mount_path = "/data"
size_gb = 10

This restriction exists because disks use exclusive leasing where only one instance can mount a disk at a time.

Tuning Tips​

Choosing requests_per_instance​

  • Lower values (5-10): More responsive scaling, higher resource usage
  • Higher values (50-100): More efficient resource usage, may have slower response to traffic spikes

Start with the default (10) and adjust based on your application's characteristics.

Choosing scale_down_delay​

  • Shorter delays (2m-5m): Faster resource reclamation, but may cause more scaling churn
  • Longer delays (15m-30m): More stable instance counts, but holds resources longer

Consider your traffic patterns:

  • Bursty traffic: Use longer delays to avoid constant scaling
  • Predictable traffic: Shorter delays work well

Monitoring Scaling​

View your current instance counts:

# See app status including instance counts
miren app

# Watch instance counts in real-time
miren app --watch

# List all running sandboxes
miren sandbox list

Next Steps​