Choose Your Approach
- SaladCloud Native Scheduled Scaling (recommended): Configure cron schedules in the Portal or API. Best for fixed schedules and the simplest operational setup.
- Serverless Scheduled Scaling (advanced): Run scheduled functions (AWS Lambda, Cloudflare Workers, or Google Cloud Functions) that call the Salad API. Best for conditional logic, external signals, or coordinating multiple container groups.
SaladCloud Scheduled Scaling (Portal and API)
Scheduled scaling lets you set replica counts at specific times using cron expressions. It works best for predictable usage patterns, such as business hours or nightly batch windows. This approach is ideal for:- Business hours scaling: Scale up during work hours, down during nights/weekends
- Batch processing windows: Prepare resources before scheduled jobs
- Global applications: Adjust capacity based on regional peak times
- Cost optimization: Predictably scale to zero during known low-usage periods
Plan Your Scaling Schedule
Before implementing, define your scaling schedule:Example Scaling Patterns
Business Hours Pattern:Key Considerations
- Time Zones: Use UTC in cron schedules
- Startup Time: Account for SaladCloud’s container startup time (5-15 minutes)
- Overlap Periods: Plan transitions to handle workload handoffs smoothly
- Emergency Scaling: Keep manual override capabilities for unexpected load
SaladCloud Portal
You can set a schedule while creating a container group or by editing an existing one. To add scheduled scaling when creating a container group:- On the “Container Configuration” page, find “Scheduled Scaling” just below “Replicas”.
- Click “Add Scaling Event”.
- Open the container group and click “Edit”.
- Scroll to the bottom of the page to “Scheduled Scaling” and click “Edit”.
Salad API
You can also configure scheduled scaling through the Salad API when creating or updating a container group. See Create Container Group and Update Container Group for the request details.Add Scaling Events
Enter a cron expression and the desired replica count, and SaladCloud will scale the container group on schedule.Scaling is not immediate. Plan ahead for instances to download the image and start.
- Add them one by one and click “Add Scaling Event” after each entry.
- Click “Bulk Edit” and add one entry per line using the format
cron_expression=replica_count.
Cron Expression Examples
0 8 * * 1-5- Weekdays at 08:00.0 18 * * 1-5- Weekdays at 18:00.0 0 1 * *- First day of every month at 00:00.0 2 * * *- Daily at 02:00.
Serverless Scheduled Scaling (Advanced)
Use this approach when you need conditional logic, external signals, or custom integrations. It relies on scheduled serverless functions that call the Salad API at specific times.Serverless Prerequisites
Before you begin, ensure you have:- ✅ SaladCloud API Key: You’ll need a valid API key with permissions to manage container groups
- ✅ Organization and Project: An active organization and project in SaladCloud
- ✅ Container Group: An existing container group that you want to scale on a schedule
- ✅ Serverless Platform Access: Account on one of the supported platforms (AWS Lambda, Cloudflare Workers, etc.)
- ✅ Time Zone Planning: Clear understanding of your scaling schedule and time zones
Serverless Approach Overview
Serverless scheduled scaling works by scheduling functions to run at specific times when you want to change your replica count:- Schedule functions to trigger at exact times when scaling is needed
- Execute scaling actions directly without checking current time
- Call the SaladCloud API to set the desired replica count
- Handle state transitions (starting/stopping container groups as needed)
Choose Your Serverless Implementation
Select one of the following serverless platforms for implementing serverless scheduled scaling:Option A: AWS Lambda + EventBridge
- Best for: AWS-heavy environments, complex logic, integration with other AWS services
- Scheduling: EventBridge with cron expressions and event payloads
- Cost: Pay-per-invocation, very cost-effective for periodic scaling
Option B: Cloudflare Workers + Cron Triggers
- Best for: Global distribution, simple logic, edge computing integration
- Scheduling: Built-in cron triggers with environment-based configuration
- Cost: Generous free tier, low latency execution
Option C: Google Cloud Functions + Cloud Scheduler
- Best for: Google Cloud environments, integration with GCP services
- Scheduling: Cloud Scheduler with flexible cron expressions
- Cost: Pay-per-invocation with generous free tier
AWS Lambda Implementation
Here’s a complete AWS Lambda implementation for serverless scheduled scaling:Lambda Function Code
Deployment Configuration
-
Create the Lambda Function:
- Runtime: Python 3.9 or later
- Timeout: 30 seconds
- Memory: 128 MB (sufficient for API calls)
-
Set Environment Variables:
-
Create Multiple EventBridge Rules for Your Schedule:
Business Hours Start (8 AM Monday-Friday):
Business Hours End (6 PM Monday-Friday):Batch Processing Start (2 AM Daily):Batch Processing End (6 AM Daily):Weekend Scale Down (Saturday 12 AM):
Testing Your Lambda Implementation
Unit Testing:Cloudflare Workers Implementation
Cloudflare Workers provides a clean single-worker approach where all scaling configuration is defined in thewrangler.toml file through environment variables:
Worker Script (src/index.js)
Wrangler Configuration
The key is to deploy the same worker multiple times with different names and environment variables. Create separatewrangler.toml files for each scaling action:
Business Hours Start (wrangler-business-start.toml):
wrangler-business-end.toml):
wrangler-batch-start.toml):
wrangler-shutdown.toml):
wrangler-weekend.toml):
Deployment Commands
Deploy each worker with its specific configuration:Simplified Deployment Script
Create adeploy.sh script to automate the process:
Testing Your Cloudflare Workers Implementation
Manual Trigger Testing:DRY_RUN environment variable to your wrangler.toml for testing:
Serverless Best Practices
Scheduling Considerations
-
Account for Startup Time: SaladCloud containers can take 5-15 minutes to start
- Schedule scale-up 15-30 minutes before you need the capacity
- Use multiple scaling events rather than trying to predict exact timing
-
Minimize Unnecessary Executions:
- Only schedule functions when you need to change replica counts
- Each cron trigger should have a specific scaling purpose
- Avoid overlapping schedules that might conflict
-
Handle Time Zones Properly:
- Use UTC in your cron expressions to avoid daylight saving issues
- Convert business hours to UTC when setting up schedules
- Document your schedule clearly for future maintenance
Error Handling and Reliability
Cost Optimization
- Scale to Zero: Use
0replicas during guaranteed low-usage periods - Gradual Scaling: Implement stepped scaling instead of jumping to max replicas
- Weekend Patterns: Reduce capacity during weekends unless needed
Troubleshooting
Common Issues
-
Function Not Triggering:
- Verify cron expressions are correct
- Check function permissions and environment variables
- Review platform-specific logs
-
API Authentication Errors:
- Ensure API key is correctly set as environment variable
- Verify API key has necessary permissions
- Check for trailing spaces in environment variables
-
Incorrect Scaling:
- Test your time calculation logic with various dates
- Verify timezone handling (use UTC consistently)
- Check for off-by-one errors in hour comparisons
-
Container Group Not Responding:
- Allow 5-15 minutes for scaling operations to complete
- Check container group status in SaladCloud portal
- Verify container group name matches exactly
Debugging Tools
Integration with Existing Autoscaling
You can combine serverless scheduled scaling with queue-based autoscaling:Next Steps
- 📊 Monitor Performance: Set up dashboards to track scaling effectiveness
- 🔧 Optimize Schedule: Adjust timing based on actual usage patterns
- 🚨 Add Alerting: Implement notifications for scaling failures
- 📈 Cost Analysis: Track cost savings from optimized scaling
- 🔄 Backup Strategy: Consider hybrid queue-based scaling for unexpected load