Back to Langflow

Best practices for Langflow on Kubernetes

docs/versioned_docs/version-1.12.0/Deployment/deployment-prod-best-practices.mdx

1.13.0.dev111.8 KB
Original Source

This guide provides best practices for deploying Langflow in production environments on Kubernetes.

Resources and scaling

Langflow's minimum resource requirements vary by deployment type:

  • IDE (development): Deploy both the Langflow visual editor (frontend) and API (backend). Typically, this is used for development environments where developers use the visual editor to create and manage flows before packaging and serving them through a production runtime deployment.

    The frontend service requires a minimum of 512Mi RAM and 0.3 CPU per instance with 1 replica.

    The backend service requires a minimum of 1Gi RAM and 0.5 CPU per instance with 1 replica.

  • Runtime (production): Deploy the Langflow runtime for production flows, which is headless (backend only) service focused on serving the Langflow API. This is used for production environments where flows are executed programmatically without the need for the visual editor.

    Minimum requirements include 2Gi RAM and 1000m (1 CPU) per instance with 3 replicas.

For more information about Langflow deployment types, see Langflow architecture on Kubernetes.

Estimate, test, and adjust

Start with the minimum recommended resources and replicas, then monitor and scale as needed based on your deployment's requirements and performance testing. Consider the following factors in your resource estimation and performance testing:

  • Flow complexity.

  • Volume of concurrent users and requests.

    For IDE (development) deployments, consider that frontend activity also pings the backend service, so you typically need to scale both the frontend and backend together.

  • Request payload content and size, particularly for file uploads in production deployments.

  • Storage requirements for cache, file management, and the Langflow database.

    An external PostgreSQL database is recommended for production deployments.

  • Infrastructure options that might require more resources, such as multi-core CPUs.

Use an external PostgreSQL database

An external PostgreSQL database is recommended for production deployments to improve scalability and reliability as compared to the default SQLite database.

Your resource allocation and replication strategy must be able to support the PostgreSQL service and storage. For example, for a runtime (production) deployment, you might allocate 4Gi RAM, 2 CPU, and multiple replicas for high availability. Tune PostgreSQL parameters, such as work_mem and shared_buffers, as needed based on resource requirements and usage metrics.

Recommended configurations include:

  • Persistent storage to prevent data loss on container shutdown
  • High Availability (HA) or Active-Active for automatic failover, scaling, and load balancing
  • Shared databases for multi-instance deployments
  • Shared storage, such as NFS or cloud storage, for multi-instance deployments to access large files stored on disk, such as in /opt/langflow/data/.

For more information, see Configure an external PostgreSQL database and Langflow database guide for enterprise DBAs.

Use HPA for dynamic scaling

Load balancing and dynamic scaling are recommended for runtime (production) deployments.

For example, consider using Horizontal Pod Autoscaler (HPA) in Kubernetes to dynamically scale based on CPU or memory usage. The following example shows a Langflow HPA configuration with CPU-based scaling:

yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: langflow-runtime-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: langflow-runtime
  minReplicas: 1
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 80

Failure points

Langflow's reliability in production depends on mitigating key failure points, particularly around the database, file system, and instance availability:

  • Database failures: See Langflow database guide for enterprise DBAs.
  • File system failures: Concurrency issues in file caching, such as /app/data/.cache, can cause IO errors in multi-instance setups. To avoid this, use a shared, POSIX-compliant file system or cloud storage. Use persistent volumes instead of ramdisk solutions that result in data loss on container shutdown.
  • Instance failures: Deploy multiple replicas to avoid service disruptions when a single instance fails. Use health checks to detect and replace failed pods.
  • Network and dependency failures: External APIs or services used in flows may fail, causing flow errors. Implement retry logic and error handling in flows or application code. Monitor network latency and dependency health.

Monitoring

Effective monitoring ensures Langflow operates reliably and performs well under varying loads:

  • Database monitoring: See Langflow database guide for enterprise DBAs.

  • Application logs: Collect and analyze logs for errors, warnings, and flow execution issues. Centralize logs using tools like ELK Stack or Fluentd. You can also inspect Langflow logs.

  • Resource usage: Track CPU, memory, and disk usage of Langflow instances. Use Prometheus and Grafana for real-time metrics collection and monitoring in Kubernetes.

    To expose your Langflow server's Prometheus metrics, set LANGFLOW_PROMETHEUS_ENABLED=True (the default is false). The default port for the Prometheus metrics is 9090. To change the port, set LANGFLOW_PROMETHEUS_PORT.

  • API performance: Monitor response times, error rates, and request throughput. Set alerts for high latency or error spikes.

  • Observability tools: Integrate with LangWatch or Opik for detailed flow tracing and metrics. Use these tools to debug flow performance and optimize execution.

Security

Running Langflow in production requires robust security measures to protect the application, data, and users. Follow industry best practices and use secure Langflow configurations, such as the following:

  • Container security: Apply security best practices for containerized applications. For example, set readOnlyRootFilesystem: true in runtime (production) containers to prevent unauthorized modifications. Restrict access to files and codebases containing sensitive data and configuration files that shouldn't be exposed to unauthorized users.
  • Secrets management: Store sensitive data like API keys and PostgreSQL credentials in Kubernetes secrets or external secrets managers like HashiCorp Vault.
  • Authentication, authorization, and access control: Start your Langflow server with authentication enabled, as explained in API keys and authentication. Restrict network and resource access with firewalls, network policies, network security groups, or VPCs. For example, restrict PostgreSQL database access to Langflow instances.
  • Encryption and privacy: Follow industry best practices and legal requirements for data privacy and encryption of data in transit and at rest, including GDPR requirements, HTTPS, TLS, and SSL. For example, configure PostgreSQL with valid SSL certificates and append ?sslmode=require or ?sslmode=verify-full to the connection string to enable SSL for database connections.
  • Security posture maintenance: Conduct regular security audits, keep current with software updates, and monitor for suspicious activity using intrusion detection systems.

Production preflight checks {#production-preflight}

To verify production infrastructure before any workers start, set the LANGFLOW_DEPLOYMENT_PROFILE environment variable to prod.

By default, LANGFLOW_DEPLOYMENT_PROFILE is set to dev and skips these checks. When set to prod, Langflow runs every check once and prints the full result. A fail aborts boot with a non-zero exit, so a misconfigured server never starts up. A warn does not abort and allows startup.

Preflight checks run for any Langflow process started with the prod profile enabled, not only Kubernetes.

To enable preflight checks, set the following in your .env file:

text
LANGFLOW_DEPLOYMENT_PROFILE=prod

Alternatively, pass the CLI option, which overrides the environment variable:

bash
uv run langflow run --deployment-profile prod

Required checks

These checks abort boot when they fail:

CheckWhat must be true
DatabaseLANGFLOW_DATABASE_URL is a reachable PostgreSQL database. SQLite fails this check.
File storageLANGFLOW_STORAGE_TYPE is an external object store such as s3, not local disk.
Encryption secretLANGFLOW_SECRET_KEY is set in the environment to a usable Fernet key. An auto-generated key or a node-local config_dir/secret_key file is not enough. See LANGFLOW_SECRET_KEY.
pgVectorPGVECTOR_CONNECTION_STRING is set, the database is reachable, and the Postgres vector extension is installed (CREATE EXTENSION vector;). Production Langflow requires pgVector even if you are not creating knowledge bases yet.

Degraded checks

These checks report reduced capability. Telemetry and MCP only warn. Cache and the shared job queue abort boot if you selected an external backend that is unreachable.

Checkokwarnfail (aborts)
CacheLANGFLOW_CACHE_TYPE=redis and Redis is reachableIn-memory default (async or memory). Caches are not shared across replicas.Redis selected but unreachable. Unset LANGFLOW_CACHE_TYPE to boot with the in-memory fallback.
Shared queueLANGFLOW_JOB_QUEUE_TYPE=redis and Redis is reachableIn-process default (asyncio). Jobs stay on a single pod.Redis selected but unreachable. Unset LANGFLOW_JOB_QUEUE_TYPE to boot with the in-process fallback.
TelemetryProduct telemetry is enabledLANGFLOW_DO_NOT_TRACK is setNever fails
MCP serving postureMCP is disabled, or the serving knobs below match the multi-tenant valuesOne or more knobs are still at a single-tenant defaultNever fails

If this plane does not serve MCP, set LANGFLOW_MCP_SERVER_ENABLED=false. Otherwise, production preflight expects these values when MCP is enabled:

VariableExpected in prodDefault
LANGFLOW_SKIP_MCP_AUTO_INITtruefalse
LANGFLOW_ADD_PROJECTS_TO_MCP_SERVERSfalsetrue
LANGFLOW_MCP_COMPOSER_ENABLEDfalsetrue
LANGFLOW_MCP_SERVERS_LOCKEDtruefalse
LANGFLOW_MCP_SSE_ENABLEDfalsetrue
LANGFLOW_MCP_SERVER_INTERPRETER_HARDENINGtruefalse
LANGFLOW_MCP_SERVER_DOCKER_HARDENINGtruefalse
LANGFLOW_SSRF_PROTECTION_ENABLEDtruetrue
LANGFLOW_CONNECTOR_SSRF_VALIDATION_ENABLEDtruetrue
LANGFLOW_CONNECTOR_SSRF_ALLOW_LOOPBACKfalsetrue
LANGFLOW_DISABLE_TRACK_APIKEY_USAGEtruefalse
LANGFLOW_MCP_SERVER_ALLOWED_PACKAGESSet to an allowlist (empty string blocks all package runners)Unset
LANGFLOW_MCP_SERVER_ENV_ALLOWLISTSet to an allowlist (empty string blocks all tenant-supplied environment variables)Unset

Local Chroma in prod

The prod profile blocks new knowledge bases and memory bases that use local Chroma. For local storage, use a shared pgVector, OpenSearch, or Chroma Cloud store, or run Langflow with LANGFLOW_DEPLOYMENT_PROFILE=dev

See also