> ## Documentation Index
> Fetch the complete documentation index at: https://www.qovery.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Optimize

> Optimize resources and reduce costs with Qovery

## Overview

Qovery helps you optimize infrastructure costs through intelligent resource management, auto-scaling, and efficient build processes.

## Cluster Auto-Scaling with Karpenter

Qovery uses **Karpenter** to automatically provision and scale cluster nodes based on your workload demands.

### How Karpenter Works

Karpenter monitors pending pods and automatically provisions the right-sized nodes to run them efficiently:

* **Just-in-time provisioning**: Nodes are created only when needed
* **Bin-packing optimization**: Workloads are efficiently packed onto nodes
* **Fast scaling**: New nodes ready in \~2 minutes
* **Cost-optimized instance selection**: Automatically selects the most cost-effective instance types

### Benefits

<CardGroup cols={2}>
  <Card title="Automatic Scaling" icon="arrows-left-right-to-line">
    Scales cluster up and down based on demand
  </Card>

  <Card title="Cost Optimization" icon="dollar-sign">
    Selects optimal instance types for your workloads
  </Card>

  <Card title="Fast Provisioning" icon="bolt">
    New nodes available in minutes
  </Card>

  <Card title="Efficient Packing" icon="boxes-stacked">
    Maximizes resource utilization
  </Card>
</CardGroup>

Karpenter runs automatically on Qovery-managed clusters with no configuration required.

## Pod Auto-Scaling

Automatically scale your application instances based on CPU utilization or custom metrics.

### Horizontal Pod Autoscaling (HPA)

Configure auto-scaling for your applications:

<Steps>
  <Step title="Navigate to Settings">
    Go to your Application → **Settings** → **Resources**
  </Step>

  <Step title="Configure Auto-Scaling">
    Set the auto-scaling parameters:

    * **Min Instances**: Minimum number of running instances (e.g., 2)
    * **Max Instances**: Maximum number of instances (e.g., 10)
    * **Target CPU Utilization**: Scale when CPU exceeds threshold (e.g., 60%)
  </Step>

  <Step title="Save and Deploy">
    Click **Save** and redeploy your application
  </Step>
</Steps>

### How It Works

When CPU utilization exceeds the target threshold, Kubernetes automatically adds more pod instances. When usage decreases, it scales back down to the minimum.

<Note>
  Auto-scaling helps maintain performance during traffic spikes while reducing costs during low-traffic periods.
</Note>

### Event-Driven Autoscaling with KEDA

For advanced use cases, Qovery supports **event-driven autoscaling** powered by [KEDA](https://keda.sh).

**What is KEDA?**

KEDA scales your applications based on external event sources like:

* Message queues (AWS SQS, RabbitMQ, Kafka)
* Data streams (AWS Kinesis)
* Databases (PostgreSQL, MySQL)
* Custom metrics (Prometheus, Datadog)
* Scheduled events (cron-based)

**When to Use KEDA**:

* Your application processes messages from a queue
* Scaling should respond to queue depth, not CPU usage
* You need to scale based on external metrics
* You want scale-to-zero capability

<Warning>
  **Beta Feature** - KEDA autoscaling is currently in beta and available to select customers only. Contact your Qovery account manager if you're interested in early access.
</Warning>

<Warning>
  **AWS and GCP clusters only** - KEDA event-driven autoscaling is currently available for applications deployed on AWS and GCP clusters.
</Warning>

<Card title="KEDA Configuration Guide" icon="book" href="/configuration/application#keda-event-driven">
  Learn how to configure event-driven autoscaling with detailed examples and authentication patterns
</Card>

## Spot Instances

Reduce compute costs by up to 70% using **Spot Instances** for non-critical workloads.

### What Are Spot Instances?

Spot instances use spare cloud capacity at significantly discounted prices compared to on-demand instances.

### When to Use Spot Instances

<CardGroup cols={2}>
  <Card title="Development Environments" icon="code">
    Ideal for testing and development
  </Card>

  <Card title="Staging Environments" icon="flask">
    Perfect for pre-production testing
  </Card>

  <Card title="Batch Processing" icon="gears">
    Good for fault-tolerant workloads
  </Card>

  <Card title="CI/CD Jobs" icon="circle-check">
    Suitable for short-lived tasks
  </Card>
</CardGroup>

### Configuration

Qovery automatically configures Spot instances with intelligent fallback:

* **Spot instances**: Used when available (up to 70% cost savings)
* **Automatic fallback**: Switches to on-demand if spot capacity unavailable
* **Graceful handling**: Manages spot instance interruptions

<Warning>
  Don't use Spot instances for production workloads requiring high availability.
</Warning>

## Environment Start-Stop

Automatically stop non-production environments outside business hours to reduce costs.

### Scheduling Environments

<Steps>
  <Step title="Access Environment Settings">
    Navigate to Environment → **Settings**
  </Step>

  <Step title="Enable Scheduling">
    Turn on **Environment Scheduling**
  </Step>

  <Step title="Configure Schedule">
    Set when the environment should be running:

    * **Start time**: e.g., 8:00 AM
    * **Stop time**: e.g., 8:00 PM
    * **Days**: Monday-Friday
    * **Timezone**: Your local timezone
  </Step>

  <Step title="Save">
    Click **Save** to apply the schedule
  </Step>
</Steps>

### Cost Savings

Stopping environments when not in use can reduce costs by **60-70%** for development and staging:

```
Example Savings:
Development Environment (runs 24/7): $500/month
Development Environment (scheduled 8am-8pm, Mon-Fri): $150/month
Savings: $350/month (70%)
```

<Tip>
  Schedule development and staging environments to run only during working hours.
</Tip>

## Build Optimization

Qovery optimizes your application builds to save time and resources.

### Smart Build Detection

Qovery avoids unnecessary rebuilds by:

* **Detecting code changes**: Only rebuilds when application code changes
* **Skipping unchanged services**: If no changes detected, uses previous build
* **Monitoring Git commits**: Tracks which services are affected by commits

This reduces build times and CI/CD costs by avoiding redundant builds.

### Docker Cache

Qovery leverages Docker layer caching to speed up builds:

* **Layer caching**: Reuses unchanged Docker layers from previous builds
* **Dependency caching**: Cached `npm install`, `pip install`, etc. if dependencies unchanged
* **Multi-stage build support**: Efficiently caches intermediate build stages

### Build Cache Benefits

<CardGroup cols={2}>
  <Card title="Faster Builds" icon="bolt">
    Reduces build time by 50-80% for unchanged layers
  </Card>

  <Card title="Lower Costs" icon="dollar-sign">
    Fewer compute resources needed for builds
  </Card>

  <Card title="Faster Deployments" icon="rocket">
    Get changes to production quicker
  </Card>

  <Card title="Automatic" icon="wand-magic-sparkles">
    Works automatically, no configuration needed
  </Card>
</CardGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Secure" icon="shield" href="/getting-started/guides/qovery-101/secure">
    Implement security best practices
  </Card>

  <Card title="Kubecost Integration" icon="chart-line" href="/configuration/integrations/observability/kubecost">
    Track and analyze Kubernetes costs
  </Card>
</CardGroup>
