Context & Why: The Web Scraping Bottleneck in Modern RAG
Retrieval-Augmented Generation (RAG) pipelines live and die by input quality. If you feed your vector database messy HTML packed with navigation menus, cookie banners, tracking scripts, and SVG icons, your embeddings degrade fast. Instead of capturing core semantic meaning, vectors end up indexing UI clutter and boilerplate noise.
Standard HTTP scrapers like BeautifulSoup and basic requests hit a wall when handling modern single-page applications. They cannot execute dynamic client-side JavaScript from frameworks like React, Vue, or Next.js, often returning little more than an empty <div id="root"></div> shell.
Firecrawl tackles this bottleneck directly. It bundles headless browser automation, dynamic DOM pruning, and Markdown conversion into an accessible API engine. Under the hood, it loads dynamic scripts, strips out structural noise like headers and sidebars, and returns clean, LLM-ready Markdown.
The hosted cloud tier works well for quick experiments, but running your own instance is usually the smarter move for production workloads. Self-hosting behind your own VPC lets you index internal documentation securely, bypass cloud rate caps, and dodge per-page billing. Scraping 50,000 internal documentation pages monthly on a cloud plan can run hundreds of dollars; on your own hardware, that workload costs virtually nothing beyond existing compute.
Installation: Deploying Firecrawl on Docker
A self-hosted Firecrawl cluster runs several moving parts: an orchestration API server, a Redis instance for job scheduling via BullMQ, and headless Chromium workers managed through Playwright. Using Docker Compose keeps this multi-container setup manageable and reproducible.
Prerequisites
Before beginning, provision a host machine with:
- A Linux distribution (Ubuntu 22.04 LTS or newer works best)
- At least 4 vCPUs and 8GB of RAM (Headless Chromium tabs easily spike memory during concurrent scrapes)
- Docker Engine 24.0+ and Docker Compose v2.20+
1. Clone the Official Repository
First, pull the Firecrawl source repository to your server:
git clone https://github.com/mendableai/firecrawl.git
cd firecrawl
2. Configure the Environment Variables
Copy the default environment template into place:
cp apps/api/.env.example apps/api/.env
Open apps/api/.env. For an internal, self-hosted deployment, verify the following baseline variables:
# Port settings
PORT=3002
HOST=0.0.0.0
# Redis Queue
REDIS_URL=redis://redis:6379
# Authentication
# Set USE_AUTH=true and assign a key if exposing this port outside a private VPC
USE_AUTH=false
BULL_AUTH_KEY=your_secure_queue_key_here
# Worker Concurrency
NUM_WORKERS_PER_QUEUE=4
3. Launch the Stack
Build and start all services in detached mode:
docker compose -f docker-compose.env.yml up -d --build
Docker will download the images, initialize Redis, start the Playwright workers, and bind the API service to port 3002.
Configuration: Tuning for Heavy Documentation Sites
Default configurations work well for quick tests. However, crawling deep API references or heavy enterprise SPAs demands custom tuning to avoid memory exhaustion.
Chromium Shared Memory and Limits
Headless browsers leak memory over long batch jobs. By default, Docker assigns a tiny 64MB shared memory space (/dev/shm) to containers. That limit causes Chromium tabs to crash instantly on asset-heavy pages. Open docker-compose.env.yml and adjust resource limits for the worker service:
services:
playwright-service:
shm_size: '2gb' # Critical: prevents Chromium tab crashes on large DOMs
deploy:
resources:
limits:
cpus: '2.0'
memory: 3500M
reservations:
memory: 1024M
restart: unless-stopped
Setting shm_size: '2gb' provides the browser enough buffer to process complex DOM trees without dropping worker threads mid-crawl.
Scrape Parameters for Cleaner Embeddings
When posting scraping jobs, pass parameters that strip unneeded tokens before data reaches your vector database. Here is an optimized curl example:
curl -X POST http://localhost:3002/v1/scrape \
-H "Content-Type: application/json" \
-d '{
"url": "https://docs.python.org/3/tutorial/controlflow.html",
"formats": ["markdown"],
"onlyMainContent": true,
"waitFor": 1500,
"removeBase64Images": true
}'
Why these options matter:
- onlyMainContent: Discards site headers, legal footers, and sidebars, extracting only the actual document body.
- waitFor: Waits 1,500ms after initial page load so client-side frameworks finish hydrating their components.
- removeBase64Images: Strips embedded base64 image strings. A single embedded PNG can add 50,000 characters of useless junk to your embedding chunks.
Verification & Monitoring: Testing and Maintaining the Cluster
With the stack online, establish automated checks and operational visibility to catch stuck worker jobs early.
1. Run an End-to-End Test
Check that all containers are healthy:
docker compose -f docker-compose.env.yml ps
Run a Python script to verify extraction quality and confirm that the API returns clean Markdown output:
import requests
API_URL = "http://localhost:3002/v1/scrape"
payload = {
"url": "https://docs.python.org/3/tutorial/controlflow.html",
"formats": ["markdown"],
"onlyMainContent": True
}
try:
response = requests.post(API_URL, json=payload, timeout=30)
response.raise_for_status()
result = response.json()
if result.get("success"):
markdown_data = result["data"]["markdown"]
print(f"Success! Extracted {len(markdown_data)} characters.")
print("--- Sample Output ---")
print(markdown_data[:250])
else:
print(f"API Error: {result.get('error')}")
except requests.exceptions.RequestException as exc:
print(f"Connection failed: {exc}")
2. Track Redis and Memory Consumption
Full-site crawls push jobs into Redis lists managed by BullMQ. If workers stall, queue backlogs grow quickly. Monitor live resource usage across the stack:
# Check container CPU and memory usage
docker stats --no-stream
# Check Redis memory footprint and connected clients
docker exec -it firecrawl-redis redis-cli info memory
3. Debugging Worker Failures
When a scrape request hangs or yields empty text, stream real-time logs from the API container:
docker compose -f docker-compose.env.yml logs -f --tail=100 api
Watch for TimeoutError or TargetClosedError logs. A TimeoutError usually means a site took longer to hydrate than your waitFor budget allowed. A TargetClosedError typically signals an OOM event where the OS killed the Chromium worker process. If crashes persist, increase the container’s memory limit or configure a rotating proxy to avoid rate limits.

