You wrote your first RAG prototype with the LangChain Chroma integration. The integration default is chromadb.PersistentClient(path="./chroma_db") — embedded mode, where the database lives as a SQLite file plus a hnsw directory inside the application’s working directory. It worked for the prototype. Then a second application wanted to query the same vector store, then a teammate wanted to ingest in parallel, then you deployed two app pods behind a load balancer and discovered that two Chroma persistent clients pointed at the same directory will corrupt each other’s SQLite file in roughly the time it takes to make a coffee. The fix is server mode — Chroma’s chroma run mode that fronts the same storage layer with a FastAPI server you can put behind a load balancer, lock down with auth, and back up properly.
What’s happening
ChromaDB has three deployment shapes and people confuse them constantly. EphemeralClient keeps everything in memory — fine for unit tests, gone on restart. PersistentClient is what most tutorials show — embedded mode, SQLite + HNSW under a directory. Server mode is what chroma run --path /var/lib/chroma --host 0.0.0.0 --port 8000 gives you: a FastAPI process that owns the on-disk store and serves a REST API, allowing multiple clients to share the store without stepping on each other. Client code switches from chromadb.PersistentClient(path=...) to chromadb.HttpClient(host=..., port=..., headers={'Authorization': 'Bearer ...'}) and otherwise looks identical. The storage layout is the same — SQLite for collection metadata + the HNSW segment files for the vector index — so migration from embedded to server is a cp -a of the directory and a client code change. There are two auth providers worth knowing: token auth (Chroma’s chromadb.auth.token_authn.TokenAuthenticationServerProvider, which is what we’ll wire up here) and basic auth via htpasswd. Token is what you want for service-to-service traffic; reserve basic auth for human ops access through a separate path.
How to verify
API liveness and version:
curl -fsS https://chroma.internal:8000/api/v1/heartbeat
# {"nanosecond heartbeat":1739...}
curl -fsS https://chroma.internal:8000/api/v1/version
# "0.5.x"
Token gate working (these MUST behave this way):
# No token → 401
curl -sS -o /dev/null -w '%{http_code}\n' https://chroma.internal:8000/api/v1/collections
# 401
# With token → 200
curl -fsS -H "Authorization: Bearer ${CHROMA_TOKEN}" \
https://chroma.internal:8000/api/v1/collections | jq
If unauthenticated requests come back 200, your auth provider isn’t loaded — check the systemd journal for the warning Chroma prints when CHROMA_SERVER_AUTHN_PROVIDER is set but the credentials provider isn’t reachable.
Collection sanity from a client:
import chromadb
client = chromadb.HttpClient(
host="chroma.internal", port=8000, ssl=True,
headers={"Authorization": f"Bearer {token}"},
)
c = client.get_or_create_collection("documents", metadata={"hnsw:space": "cosine"})
print(c.count())
c.add(ids=["a"], documents=["test"], embeddings=[[0.1]*1536])
print(c.peek())
If count() works but add() raises a 500 with a SQLite “database is locked” message, you’re still in embedded mode through a second process — verify the server is the only thing holding the path open with lsof +D /var/lib/chroma.
The fix
Save the script as /root/setup-chromadb-server.sh and run as root on a single Ubuntu 22.04 VM. The script does base hardening, installs Python 3.11, creates a dedicated chroma system user, installs ChromaDB into a venv at /opt/chromadb/venv (so apt-managed Python upgrades don’t break it), drops the server config with token auth enabled, writes a systemd unit that runs as chroma, wires nginx as the TLS terminator on 8443, and lays down a nightly backup script that does a sqlite3 .backup of the metadata store plus a snapshot of the segment directory to S3.
#!/usr/bin/env bash
set -euo pipefail
### Ubuntu 22.04 ChromaDB 0.5 server-mode installer
### Run as root on a single VM with a dedicated data volume at /var/lib/chroma
### Assumes you have wildcard or per-host TLS material from your internal CA
if [[ "$(id -u)" -ne 0 ]]; then
echo "Run as root."
exit 1
fi
# === EDIT BEFORE RUN ===
NODE_HOSTNAME="chroma.internal"
NODE_IP="10.50.0.41"
CHROMA_VERSION="0.5.23"
CHROMA_ADMIN_TOKEN="$(openssl rand -hex 32)"
CHROMA_READ_TOKEN="$(openssl rand -hex 32)"
S3_BUCKET="chroma-backups-prod"
S3_REGION="us-east-1"
S3_ACCESS_KEY="CHANGE_ME"
S3_SECRET_KEY="CHANGE_ME"
TLS_CERT_PATH="/etc/ssl/chroma/fullchain.pem"
TLS_KEY_PATH="/etc/ssl/chroma/privkey.pem"
# =======================
echo
echo "========================================"
echo "ChromaDB server on ${NODE_HOSTNAME} (${NODE_IP})"
echo "========================================"
echo
echo "==> Base OS update + tooling"
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get -y upgrade
apt-get -y install ca-certificates curl gnupg lsb-release \
ufw fail2ban unattended-upgrades chrony jq sqlite3 \
python3.11 python3.11-venv python3.11-dev build-essential \
awscli nginx
systemctl enable --now chrony
hostnamectl set-hostname "${NODE_HOSTNAME}"
echo "==> SSH hardening"
sed -i 's|^[#[:space:]]*PermitRootLogin.*|PermitRootLogin prohibit-password|' /etc/ssh/sshd_config
sed -i 's|^[#[:space:]]*PasswordAuthentication.*|PasswordAuthentication no|' /etc/ssh/sshd_config
sshd -t && systemctl restart ssh
echo "==> fail2ban + unattended-upgrades"
cat > /etc/fail2ban/jail.d/sshd.local <<'FAIL2BAN'
[sshd]
enabled = true
port = ssh
backend = systemd
maxretry = 4
findtime = 10m
bantime = 1h
FAIL2BAN
systemctl enable --now fail2ban
cat > /etc/apt/apt.conf.d/52unattended-upgrades-local <<'AUTOUP'
Unattended-Upgrade::Automatic-Reboot "false";
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
AUTOUP
echo "==> UFW — only allow client TLS through nginx"
ufw --force reset
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp
ufw allow 8443/tcp comment 'chroma TLS via nginx'
ufw --force enable
echo "==> Kernel/limits"
cat > /etc/sysctl.d/99-chroma.conf <<'SYSCTL'
vm.max_map_count = 262144
vm.swappiness = 1
fs.file-max = 1048576
SYSCTL
sysctl --system
cat > /etc/security/limits.d/99-chroma.conf <<'LIMITS'
chroma soft nofile 1048576
chroma hard nofile 1048576
LIMITS
echo "==> Dedicated chroma user"
if ! id -u chroma >/dev/null 2>&1; then
useradd --system --home /var/lib/chroma --shell /usr/sbin/nologin chroma
fi
echo "==> Persistent data volume"
if [[ -b /dev/sdb && ! -d /var/lib/chroma ]]; then
if ! blkid /dev/sdb; then
mkfs.ext4 -L chroma /dev/sdb
fi
mkdir -p /var/lib/chroma
echo "LABEL=chroma /var/lib/chroma ext4 defaults,noatime 0 2" >> /etc/fstab
mount /var/lib/chroma
fi
mkdir -p /var/lib/chroma /opt/chromadb /etc/chromadb /var/log/chromadb
chown chroma:chroma /var/lib/chroma /var/log/chromadb
echo "==> Python venv + ChromaDB"
python3.11 -m venv /opt/chromadb/venv
/opt/chromadb/venv/bin/pip install --upgrade pip wheel
/opt/chromadb/venv/bin/pip install "chromadb==${CHROMA_VERSION}"
chown -R chroma:chroma /opt/chromadb
echo "==> Token credentials file"
cat > /etc/chromadb/credentials.json <<EOF
{
"users": [
{
"id": "admin",
"tokens": ["${CHROMA_ADMIN_TOKEN}"],
"role": "admin"
},
{
"id": "reader",
"tokens": ["${CHROMA_READ_TOKEN}"],
"role": "db_reader"
}
]
}
EOF
chown chroma:chroma /etc/chromadb/credentials.json
chmod 600 /etc/chromadb/credentials.json
echo "==> ChromaDB env file"
cat > /etc/chromadb/chromadb.env <<EOF
CHROMA_SERVER_HOST=127.0.0.1
CHROMA_SERVER_HTTP_PORT=8000
PERSIST_DIRECTORY=/var/lib/chroma
IS_PERSISTENT=true
ANONYMIZED_TELEMETRY=False
# Auth — token via header
CHROMA_SERVER_AUTHN_PROVIDER=chromadb.auth.token_authn.TokenAuthenticationServerProvider
CHROMA_SERVER_AUTHN_CREDENTIALS_FILE=/etc/chromadb/credentials.json
CHROMA_AUTH_TOKEN_TRANSPORT_HEADER=AUTHORIZATION
CHROMA_SERVER_AUTHZ_PROVIDER=chromadb.auth.simple_rbac_authz.SimpleRBACAuthorizationProvider
CHROMA_SERVER_AUTHZ_CONFIG_FILE=/etc/chromadb/authz.yaml
EOF
chmod 600 /etc/chromadb/chromadb.env
cat > /etc/chromadb/authz.yaml <<'AUTHZ'
roles_mapping:
admin:
actions:
- "*:*"
db_reader:
actions:
- tenant:get
- db:get
- collection:get_or_create
- collection:get
- collection:list
- collection:count
- collection:get_record
- collection:query
users:
- id: admin
role: admin
- id: reader
role: db_reader
AUTHZ
echo "==> systemd unit"
cat > /etc/systemd/system/chromadb.service <<'UNIT'
[Unit]
Description=ChromaDB server
After=network.target
[Service]
Type=simple
User=chroma
Group=chroma
EnvironmentFile=/etc/chromadb/chromadb.env
WorkingDirectory=/var/lib/chroma
ExecStart=/opt/chromadb/venv/bin/chroma run --path /var/lib/chroma --host 127.0.0.1 --port 8000 --log-config /etc/chromadb/log_config.yml
Restart=on-failure
RestartSec=5
LimitNOFILE=1048576
StandardOutput=append:/var/log/chromadb/chromadb.log
StandardError=append:/var/log/chromadb/chromadb.err
[Install]
WantedBy=multi-user.target
UNIT
cat > /etc/chromadb/log_config.yml <<'LOG'
version: 1
disable_existing_loggers: false
formatters:
default:
format: '%(asctime)s [%(levelname)s] %(name)s: %(message)s'
handlers:
default:
class: logging.StreamHandler
formatter: default
stream: ext://sys.stdout
root:
level: INFO
handlers: [default]
LOG
echo "==> nginx TLS terminator on 8443"
cat > /etc/nginx/sites-available/chromadb.conf <<EOF
server {
listen 8443 ssl http2;
server_name ${NODE_HOSTNAME};
ssl_certificate ${TLS_CERT_PATH};
ssl_certificate_key ${TLS_KEY_PATH};
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
client_max_body_size 128m;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_http_version 1.1;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header Authorization \$http_authorization;
proxy_read_timeout 300s;
}
}
EOF
ln -sf /etc/nginx/sites-available/chromadb.conf /etc/nginx/sites-enabled/chromadb.conf
rm -f /etc/nginx/sites-enabled/default
nginx -t
systemctl enable --now nginx
systemctl daemon-reload
systemctl enable --now chromadb
echo "==> Wait for Chroma"
for i in {1..60}; do
if curl -fsS http://127.0.0.1:8000/api/v1/heartbeat >/dev/null 2>&1; then break; fi
sleep 2
done
echo "==> Backup script + cron"
cat > /usr/local/bin/chromadb-backup.sh <<EOF
#!/usr/bin/env bash
set -euo pipefail
export AWS_ACCESS_KEY_ID=${S3_ACCESS_KEY}
export AWS_SECRET_ACCESS_KEY=${S3_SECRET_KEY}
export AWS_DEFAULT_REGION=${S3_REGION}
ts=\$(date -u +%Y%m%dT%H%M%SZ)
WORK=\$(mktemp -d)
trap 'rm -rf "\${WORK}"' EXIT
# 1) Online backup of SQLite metadata using the .backup pragma — safe while
# Chroma is running. The HNSW segment files are append-mostly on disk and
# tar'ing them while writes happen is OK at the cost of a slightly stale
# index for the restored copy.
sqlite3 /var/lib/chroma/chroma.sqlite3 ".backup '\${WORK}/chroma.sqlite3'"
# 2) Tarball the segment directory in parallel
tar -C /var/lib/chroma -czf "\${WORK}/segments.tgz" \\
--exclude='chroma.sqlite3*' .
# 3) Upload both with the same timestamp prefix
aws s3 cp --no-progress "\${WORK}/chroma.sqlite3" \\
"s3://${S3_BUCKET}/\${ts}/chroma.sqlite3"
aws s3 cp --no-progress "\${WORK}/segments.tgz" \\
"s3://${S3_BUCKET}/\${ts}/segments.tgz"
# Manifest for the restore script
cat > "\${WORK}/MANIFEST.json" <<JSON
{
"timestamp_utc": "\${ts}",
"chromadb_version": "${CHROMA_VERSION}",
"host": "${NODE_HOSTNAME}"
}
JSON
aws s3 cp --no-progress "\${WORK}/MANIFEST.json" \\
"s3://${S3_BUCKET}/\${ts}/MANIFEST.json"
EOF
chmod 700 /usr/local/bin/chromadb-backup.sh
cat > /etc/cron.d/chromadb-backup <<'CRON'
# m h dom mon dow user command
30 2 * * * root /usr/local/bin/chromadb-backup.sh >> /var/log/chromadb/backup.log 2>&1
CRON
echo
echo "========================================"
echo "DONE"
echo "========================================"
echo
echo "Tokens saved to /etc/chromadb/credentials.json (0600)."
echo " admin: ${CHROMA_ADMIN_TOKEN}"
echo " reader: ${CHROMA_READ_TOKEN}"
echo
echo "Listeners:"
ss -lntp | grep -E ':(8000|8443)\b' || true
echo
echo "Health:"
curl -fsS http://127.0.0.1:8000/api/v1/heartbeat && echo
echo
echo "Connect from a client:"
echo " chromadb.HttpClient(host='${NODE_HOSTNAME}', port=8443, ssl=True, headers={'Authorization': 'Bearer ${CHROMA_ADMIN_TOKEN}'})"
Make it executable and run:
chmod 700 /root/setup-chromadb-server.sh
/root/setup-chromadb-server.sh
A note on the backup strategy that’s specific to Chroma. The SQLite file holds collection metadata, tenant config, and an inventory of segment files; the segment directory holds the actual HNSW vector indices and document/embedding payloads. A useful restore needs both, and they must be from the same point in time. The script above uses SQLite’s online .backup (which is atomic at the SQLite level) and then tars the segment directory immediately after — the two artifacts can drift slightly if writes happen between them, but the only impact is that a few rows present in the SQLite snapshot might point at segments that didn’t yet exist when the tar ran. Chroma handles missing segments by skipping queries for them, so the restored DB is consistent in the “no incorrect data” sense but might have a slightly lower vector count than the source at backup time. For stricter point-in-time guarantees, stop the service for the duration of the backup; on most workloads the few-second drift is acceptable. Test restore quarterly into a sandbox VM running the same Chroma version — the version pin matters because Chroma occasionally migrates the SQLite schema on startup.
Stack Harbor runs ChromaDB servers under environment management with SQLite integrity checks, HNSW segment growth alerts, and restore drills as part of the operational cadence. Talk to our monitoring team or book a scoping call if you’d like the embedded-to-server migration handled for you.