Deploying GrowthBook
Introduction
GrowthBook is an open-source feature flagging and A/B testing platform that empowers teams to deploy features safely, run experiments, and make data-driven decisions. Built with modern development workflows in mind, GrowthBook provides a robust solution for managing feature rollouts, conducting experiments, and analyzing results—all while maintaining full control over your data.
Deploying GrowthBook on Klutch.sh provides a scalable, production-ready infrastructure for your feature management and experimentation platform, with support for persistent data storage, database integration, and flexible configuration options. This guide covers everything you need to deploy GrowthBook successfully, from initial setup to production best practices.
Prerequisites
Before deploying GrowthBook on Klutch.sh, ensure you have:
- A Klutch.sh account (sign up here)
- A GitHub repository for your GrowthBook deployment configuration
- A MongoDB database (either a managed service like MongoDB Atlas or a self-hosted instance)
- Basic familiarity with Docker and environment variables
- (Optional) A data warehouse connection for importing experiment results (BigQuery, Snowflake, Redshift, etc.)
Understanding GrowthBook Architecture
GrowthBook consists of two main components:
- GrowthBook Application: The main web interface for managing features, experiments, and viewing results
- MongoDB Database: Stores all application data including feature flags, experiment configurations, user accounts, and settings
For production deployments, you’ll also want to consider:
- Data Source Connections: Optional connections to your data warehouse for importing experiment results
- Redis Cache: Optional caching layer for improved performance at scale
- Persistent Storage: Required for uploaded files and media assets
Getting Started: Preparing Your Repository
-
Create a new directory for your GrowthBook deployment configuration:
Terminal window mkdir growthbook-klutchcd growthbook-klutch -
Create a
Dockerfilein the root of your repository. This ensures consistent, reproducible deployments:# Use the official GrowthBook Docker imageFROM growthbook/growthbook:latest# Set working directoryWORKDIR /usr/local/src/app# Expose the default GrowthBook portEXPOSE 3100# The base image already includes the start command# CMD ["yarn", "start"]Note: You can pin to a specific version for production stability, e.g.,
growthbook/growthbook:2.5.0. Check the Docker Hub tags for available versions. -
(Optional) Create a
.dockerignorefile to exclude unnecessary files:.git.gitignorenode_modulesnpm-debug.logREADME.md.env.env.local -
Create a
README.mdfile documenting your configuration and deployment notes:# GrowthBook Deployment on Klutch.shThis repository contains the configuration for deploying GrowthBook on Klutch.sh.## Environment VariablesSee the Klutch.sh dashboard for the required environment variables.## DeploymentPush changes to the main branch to trigger automatic deployment on Klutch.sh. -
Initialize a Git repository and push to GitHub:
Terminal window git initgit add .git commit -m "Initial GrowthBook deployment configuration"git branch -M maingit remote add origin https://github.com/your-username/growthbook-klutch.gitgit push -u origin main
Setting Up MongoDB
GrowthBook requires MongoDB for storing all application data. You have several options:
Option 1: MongoDB Atlas (Recommended)
- Create a free account at MongoDB Atlas
- Create a new cluster (the free M0 tier works well for getting started)
- Create a database user with read/write permissions
- Add
0.0.0.0/0to the IP whitelist (or specific Klutch.sh IPs if available) - Get your connection string (it should look like:
mongodb+srv://username:password@cluster.mongodb.net/growthbook)
Option 2: Self-Hosted MongoDB on Klutch.sh
- Deploy a MongoDB instance on Klutch.sh (see the MongoDB deployment guide)
- Configure persistent volumes for MongoDB data
- Note the internal connection details for GrowthBook to connect
Deploying GrowthBook on Klutch.sh
Klutch.sh automatically detects the Dockerfile in your repository and uses it to build and deploy your application.
-
Log in to Klutch.sh
-
Create a new project (if you haven’t already) and give it a descriptive name like “GrowthBook Production”
-
Create a new app within your project:
- Name: Choose a name like “growthbook”
- Repository: Select your GitHub repository containing the Dockerfile
- Branch: Select
mainor your preferred deployment branch - Traffic Type: Select HTTP
- Internal Port: Set to
3100(GrowthBook’s default port)
-
Configure compute resources based on your expected usage:
- Region: Choose the region closest to your users or data sources
- Compute: Start with 1 CPU and 2GB RAM, scale up as needed
- Instances: Start with 1 instance, increase for high availability
-
Configure environment variables (see next section for details)
-
Click Create to deploy
Klutch.sh will automatically detect your Dockerfile, build the image, and deploy your GrowthBook instance. Your application will be available at a URL like example-app.klutch.sh.
Required Environment Variables
Configure these environment variables in your Klutch.sh app settings:
Core Configuration
# MongoDB ConnectionMONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/growthbook
# Application URL (your Klutch.sh app URL)APP_ORIGIN=https://example-app.klutch.sh
# Secret key for JWT tokens (generate a secure random string)JWT_SECRET=your-secure-random-string-here
# Secret key for encryption (generate a secure random string)ENCRYPTION_KEY=your-secure-encryption-key-hereOptional Configuration
# Email Configuration (for user invitations and notifications)EMAIL_ENABLED=trueEMAIL_HOST=smtp.sendgrid.netEMAIL_PORT=587EMAIL_HOST_USER=apikeyEMAIL_HOST_PASSWORD=your-sendgrid-api-keyEMAIL_FROM=noreply@yourdomain.com
# Data Source Connections (for experiment analysis)# Example for BigQueryBIGQUERY_PROJECT_ID=your-project-idBIGQUERY_DATASET=your-dataset
# Redis (for caching and improved performance)REDIS_URL=redis://your-redis-host:6379
# Enable multi-organization modeIS_MULTI_ORG=false
# License key (for Enterprise features)LICENSE_KEY=your-license-key-hereSecurity Notes
- Always store sensitive values like
JWT_SECRET,ENCRYPTION_KEY, and database credentials as secrets in Klutch.sh - Generate secure random strings for
JWT_SECRETandENCRYPTION_KEYusing:openssl rand -hex 32 - Never commit secrets to your Git repository
- Rotate secrets periodically for enhanced security
Setting Up Persistent Storage
GrowthBook needs persistent storage for uploaded files, media assets, and local file-based caching.
-
In your Klutch.sh app settings, navigate to the Volumes section
-
Add a persistent volume:
- Mount Path:
/usr/local/src/app/uploads - Size: Start with 5GB, increase based on your usage
- Mount Path:
-
(Optional) Add additional volumes for caching:
- Mount Path:
/usr/local/src/app/.cache - Size: 2GB
- Mount Path:
Persistent volumes ensure that uploaded files and cached data survive app restarts and redeployments.
Initial Setup and Configuration
-
Once your GrowthBook app is deployed, navigate to your app URL (e.g.,
https://example-app.klutch.sh) -
Complete the initial setup wizard:
- Create your admin account
- Set up your organization name
- Configure your data source connections (if using)
-
Create your first feature flag:
- Click Features in the navigation
- Click Add Feature
- Give it a name and description
- Set the default value
- Click Save
-
Generate SDK connections:
- Click SDK Connections in the navigation
- Click Add SDK Connection
- Choose your language/platform
- Copy the SDK endpoint and client key
- Integrate into your application
-
Configure team access:
- Click Settings → Team
- Invite team members via email
- Assign appropriate roles (Admin, Engineer, Analyst, etc.)
Integrating GrowthBook into Your Application
After deployment, integrate GrowthBook into your application to use feature flags and run experiments.
Example: JavaScript/Node.js Integration
-
Install the GrowthBook SDK:
Terminal window npm install @growthbook/growthbook -
Initialize GrowthBook in your application:
import { GrowthBook } from '@growthbook/growthbook';// Create a GrowthBook instanceconst growthbook = new GrowthBook({apiHost: 'https://example-app.klutch.sh',clientKey: 'sdk-abc123xyz',enableDevMode: true, // Set to false in production// User attributes for targetingattributes: {id: user.id,email: user.email,country: user.country,// Add any other user attributes}});// Load features from the APIawait growthbook.loadFeatures();// Check if a feature is enabledif (growthbook.isOn('new-checkout-flow')) {// Show new checkout flow} else {// Show old checkout flow}// Get a feature value with a fallbackconst buttonColor = growthbook.getFeatureValue('button-color', 'blue'); -
Use feature flags in your components:
function CheckoutButton() {const buttonColor = growthbook.getFeatureValue('button-color', 'blue');const isEnabled = growthbook.isOn('new-checkout-button');if (!isEnabled) return null;return (<button style={{ backgroundColor: buttonColor }}>Complete Purchase</button>);}
Example: React Integration
-
Install the React SDK:
Terminal window npm install @growthbook/growthbook-react -
Set up the GrowthBook provider:
import { GrowthBook, GrowthBookProvider } from '@growthbook/growthbook-react';const growthbook = new GrowthBook({apiHost: 'https://example-app.klutch.sh',clientKey: 'sdk-abc123xyz',attributes: {id: user.id,loggedIn: !!user,}});function App() {useEffect(() => {growthbook.loadFeatures();}, []);return (<GrowthBookProvider growthbook={growthbook}><YourApp /></GrowthBookProvider>);} -
Use hooks in components:
import { useFeature, useFeatureValue } from '@growthbook/growthbook-react';function NewFeatureComponent() {const feature = useFeature('new-dashboard');const theme = useFeatureValue('theme', 'light');if (!feature.on) return <OldDashboard />;return <NewDashboard theme={theme} />;}
Running A/B Tests and Experiments
GrowthBook makes it easy to run A/B tests and analyze results:
-
Create an Experiment:
- Navigate to Experiments in GrowthBook
- Click Add Experiment
- Define your hypothesis and metrics
- Set up variations (A, B, C, etc.)
- Configure targeting rules
-
Implement in Your Application:
const { value } = growthbook.run({key: 'checkout-button-text',variations: ['Buy Now', 'Complete Purchase', 'Checkout']});// Use the variation in your UI<button>{value}</button> -
Connect Your Data Source:
- Configure BigQuery, Snowflake, Redshift, or another data warehouse
- Set up event tracking in your analytics platform
- Map experiment events to metrics in GrowthBook
-
Analyze Results:
- View real-time results in the GrowthBook dashboard
- Monitor statistical significance
- Make data-driven decisions to roll out winning variations
Local Development with Docker Compose
For local development and testing, use Docker Compose to run GrowthBook alongside MongoDB:
-
Create a
docker-compose.ymlfile:version: '3.8'services:mongodb:image: mongo:7container_name: growthbook-mongorestart: unless-stoppedports:- "27017:27017"environment:- MONGO_INITDB_ROOT_USERNAME=root- MONGO_INITDB_ROOT_PASSWORD=passwordvolumes:- mongodb_data:/data/dbgrowthbook:image: growthbook/growthbook:latestcontainer_name: growthbook-apprestart: unless-stoppedports:- "3100:3100"depends_on:- mongodbenvironment:- MONGODB_URI=mongodb://root:password@mongodb:27017/growthbook?authSource=admin- APP_ORIGIN=http://localhost:3100- JWT_SECRET=dev-secret-key-change-in-production- ENCRYPTION_KEY=dev-encryption-key-change-in-production- NODE_ENV=developmentvolumes:- growthbook_uploads:/usr/local/src/app/uploadsvolumes:mongodb_data:growthbook_uploads: -
Start the services:
Terminal window docker-compose up -d -
Access GrowthBook at
http://localhost:3100 -
When ready to deploy, push your Dockerfile to GitHub and deploy on Klutch.sh
Note: Docker Compose is for local development only. Klutch.sh does not support Docker Compose for deployments.
Production Best Practices
Security
- Enable HTTPS: Klutch.sh provides automatic HTTPS for all apps
- Use Strong Secrets: Generate cryptographically secure random strings for JWT and encryption keys
- Enable Authentication: Configure email/password authentication or integrate with OAuth providers (Google, GitHub, etc.)
- Regular Backups: Back up your MongoDB database regularly
- Role-Based Access: Use GrowthBook’s role system to limit permissions appropriately
Performance
- Enable Redis Caching: Add a Redis instance for improved performance with large feature flag sets
- Optimize Database: Index frequently queried fields in MongoDB
- Monitor Resources: Use Klutch.sh monitoring to track CPU, memory, and network usage
- Scale Horizontally: Add more instances during high-traffic periods
Reliability
- Database Replication: Use MongoDB replica sets for high availability
- Health Checks: Configure health check endpoints if supported
- Monitoring and Alerts: Set up monitoring for your GrowthBook instance
- Regular Updates: Keep GrowthBook updated to the latest stable version
Configuration Management
- Environment-Specific Settings: Use different configurations for staging and production
- Feature Flag Organization: Use tags and folders to organize features logically
- Documentation: Document your feature flags and experiments in GrowthBook
- Change Management: Implement a review process for production feature changes
Troubleshooting Common Issues
GrowthBook Won’t Start
- Check MongoDB Connection: Verify your
MONGODB_URIis correct and the database is accessible - Verify Environment Variables: Ensure all required environment variables are set correctly
- Check Logs: View application logs in the Klutch.sh dashboard for specific error messages
- Port Configuration: Confirm the internal port is set to 3100
Features Not Loading in SDK
- Verify SDK Endpoint: Ensure your SDK is pointing to the correct GrowthBook URL
- Check Client Key: Confirm you’re using the correct SDK client key
- CORS Configuration: If calling from a browser, ensure CORS is configured properly
- Network Connectivity: Verify your application can reach the GrowthBook instance
Performance Issues
- Enable Redis: Add Redis caching to reduce database queries
- Database Optimization: Add indexes to frequently queried MongoDB collections
- Scale Vertically: Increase CPU and RAM if the instance is under-resourced
- Scale Horizontally: Add more instances and use load balancing
Data Source Connection Failures
- Check Credentials: Verify data warehouse credentials are correct
- Network Access: Ensure GrowthBook can reach your data warehouse
- Query Permissions: Confirm the database user has necessary query permissions
- SQL Syntax: Test queries manually in your data warehouse first
Upgrading GrowthBook
-
Check the GrowthBook releases page for the latest version
-
Update your Dockerfile to use the new version:
FROM growthbook/growthbook:2.6.0 -
Review the changelog for breaking changes or required migrations
-
Test in a staging environment first
-
Push the changes to GitHub:
Terminal window git add Dockerfilegit commit -m "Update GrowthBook to v2.6.0"git push origin main -
Klutch.sh will automatically rebuild and redeploy your app
-
Monitor the deployment and verify everything works correctly
Advanced Configuration
Custom Domain Setup
-
Configure a custom domain in Klutch.sh (see Custom Domains guide)
-
Update the
APP_ORIGINenvironment variable to match your custom domain:Terminal window APP_ORIGIN=https://growthbook.yourdomain.com -
Update SDK endpoints in your applications to use the custom domain
Multi-Organization Setup
Enable multi-organization mode if you need to support multiple teams or clients:
IS_MULTI_ORG=trueThis allows you to create separate organizations within a single GrowthBook instance, each with isolated features, experiments, and users.
Webhook Integration
Configure webhooks to receive notifications when features or experiments change:
- Navigate to Settings → Webhooks in GrowthBook
- Add a webhook endpoint URL
- Select the events you want to receive
- Use webhooks to trigger CI/CD pipelines, send notifications, or update external systems
Monitoring and Analytics
Monitor your GrowthBook instance to ensure optimal performance:
- Application Metrics: Use Klutch.sh built-in monitoring to track CPU, memory, and network usage
- MongoDB Metrics: Monitor database performance, query times, and connection pool usage
- API Response Times: Track SDK endpoint response times to ensure fast feature flag evaluation
- Feature Usage: Use GrowthBook’s analytics to see which features are most active
- Experiment Results: Monitor experiment metrics and statistical significance in real-time
Resources
- GrowthBook Documentation
- GrowthBook GitHub Repository
- GrowthBook Docker Hub
- Klutch.sh Documentation
- Klutch.sh Volumes Guide
- Klutch.sh Deployments Guide
Deploying GrowthBook on Klutch.sh provides a robust, scalable platform for feature management and experimentation. With automatic Dockerfile detection, persistent storage, and easy scaling, you can focus on building great features and running successful experiments without worrying about infrastructure management.