Deploy Dify on SAE (Public Preview)

Updated at:

Dify is an open-source large language model (LLM) application development platform. Serverless App Engine (SAE) allows you to quickly deploy Dify without managing underlying compute resources, and achieve high availability and auto scaling in seconds with simple configuration.

Important

Responsibility Boundaries: Applications deployed from the App Center, unless otherwise specified, are consistent with their open-source community versions. You are responsible for any stability risks and security vulnerabilities associated with the open-source software. The SAE service guarantee covers only the stability of the underlying runtime and does not extend to the quality, security, or maintenance of the open-source software itself. We recommend that you conduct thorough technical reviews and security audits before deploying applications to a production environment.

Deploy Dify production environment

Solution architecture

image

Resource checklist

Resource type

Quantity

Description

Virtual Private Cloud (VPC)

1

Creates a private network in the cloud for resources like SAE applications and cloud databases.

vSwitch

2

Connects SAE applications and cloud databases to the same network, enabling communication between them and providing basic network segmentation and isolation.

To achieve high availability across availability zones, deploy resources to vSwitches in different availability zones.

security group

1

Controls inbound and outbound traffic rules for the Virtual Private Cloud.

Classic Load Balancer (CLB)

1

Provides load balancing services for Dify, distributing traffic to different backend servers to improve application throughput and availability.

NAT Gateway

1

Enables the Dify application to access public network services.

Elastic IP Address

1

Enables the Dify application to access public network services.

SAE application

6

Dify application components deployed on SAE, including dify-nginx, dify-sandbox, dify-worker, dify-web, dify-api, and dify-plugin-daemon.

Apsara File Storage NAS

1

Provides file storage for the Dify application.

ApsaraDB for Tair

1

Provides caching services for Dify.

ApsaraDB RDS for PostgreSQL

1

Provides relational database services for Dify.

Tablestore

1

Provides vector search services for Dify.

Billing

Products and services

Reference

Classic Load Balancer (CLB)

CLB billing overview

NAT Gateway

NAT Gateway billing overview

Elastic IP Address

Elastic IP Address billing overview

SAE application

SAE billing overview

Apsara File Storage NAS

NAS billing overview

ApsaraDB for Tair

ApsaraDB for Tair billing overview

ApsaraDB RDS for PostgreSQL

ApsaraDB RDS billing overview

Tablestore

Tablestore billing overview

(Optional) Application Real-Time Monitoring Service (ARMS)

ARMS billing overview

Permissions

A RAM user needs the following permissions.

Policy name

Notes

AliyunVPCFullAccess

Provides permissions to manage Virtual Private Cloud (VPC).

AliyunSLBFullAccess

Provides permissions to manage Server Load Balancer (SLB).

AliyunSAEFullAccess

Provides permissions to manage Serverless App Engine (SAE).

AliyunNASFullAccess

Provides permissions to manage Apsara File Storage NAS.

AliyunKvstoreFullAccess

Provides permissions to manage ApsaraDB for Tair.

AliyunRDSFullAccess

Provides permissions to manage ApsaraDB RDS.

AliyunOTSFullAccess

Provides permissions to manage Tablestore (OTS).

AliyunROSFullAccess

Provides permissions to manage Resource Orchestration Service (ROS).

AliyunComputeNestUserFullAccess

Provides user permissions to manage Compute Nest.

Deploy application

  1. Go to the App Center, select Dify Community Edition - Serverless Deployment, and click Deploy.

    1. Select Template: For production environments, select Dify High-availability Edition or Dify High-availability + Observable Edition, which uses Alibaba Cloud database services for high availability. The Dify High-availability + Observable Edition also integrates observability for dify-sandbox and dify-plugin-daemon, and uses automatic probe instrumentation to provide performance analysis, token analysis, and trace views. To add observability to the dify-api component, see Enable observability for Dify applications.

    2. Select Region: Select the region where you want to deploy the resources.

    3. Billing Method Configuration: Select pay-as-you-go or subscription.

    4. SAE Configuration: Set the SAE namespace Name (you can use the default value, 'default'), Number of SAE replicas, SAE vCPUs, and SAE Memory.

    5. Postgres Database Configuration: Set the PostgreSQL instance type, PostgreSQL instance storage type, PostgreSQL instance storage, PostgreSQL database account name, and PostgreSQL database password.

    6. Redis Database Configuration: Set the Redis instance password.

    7. Tablestore Configuration: Set the Tablestore instance type.

    8. Basic Configuration: Select Create VPC or Use Existing VPC. To improve service availability, select two availability zones to deploy your resources.

  2. After confirming the parameters and pricing details, note that if you select an Observable Edition, ARMS incurs additional charges that are not included in the pricing estimate. Click Next: Confirm Order and then Create Now.

    1. In the Deployed Scenarios list, you can view the created application scenario. Wait for the Status to change to Deployed, which indicates a successful deployment.

    2. Click the Scenario ID. In the Service Resources section, you can view and navigate to the deployed Service Resources. In the Use Now section, click the URL next to Dify Service Address to open the Dify management console.

  3. Set up an administrator account, log in, and then start using Dify.

Operations and management

Go to the SAE Application List. Select the application's region and namespace to view the deployed applications. Click an application ID to open its details page.

Application lifecycle management

On the Basic Information page, click the buttons at the top to View Application Configuration, Deploy Application (modify the application configuration and redeploy), perform Manual Scaling (adjust the number of application replicas), Stop Application, Restart Application, or Delete Application.

To delete all resources related to Dify, find the Dify scenario in Deployed Scenarios in the App Center and click Delete.

Auto scaling

On the Basic Information page, click Auto Scaling at the top to configure an auto scaling policy.

Application configuration

On the Basic Information page, click Deploy Application at the top. In the Environment Variables section, set the Variable Value. For some variables, you must reference a ConfigMap or a Secret.

Application monitoring (Observable Edition only)

View monitoring data for dify-sandbox and dify-plugin-daemon on their Application Monitoring pages or in the Application Monitoring > Application List section of the ARMS console.

To add observability to the dify-api component, see Enable observability for Dify applications.

Deploy Dify High-performance Edition

The Dify High-performance Edition builds on the Dify open-source version with code optimizations and configuration tuning. When deployed with appropriately sized Dify components and external resources, it can meet the demands of high-concurrency, multi-user production workloads.

The deployment and O&M methods are similar to those for the Dify High-availability Edition. The deployment parameters differ as follows:

  1. For Select Template, select Dify High-performance Edition.

  2. For Celery Backend Configuration, set the Celery backend Redis instance type and Celery backend Redis instance password.

Deploy Dify test environment

The Dify Test Edition uses single-node database instances to reduce costs, but this approach lacks high availability. This edition is therefore recommended only for testing.

Deployment and O&M are similar to the Dify High-availability Edition. The only configuration difference is the template selection: for Select Template, you must select Dify Test Edition or Dify Test + Observable Edition.