Skip to main content
Deploying TrailBase to production requires careful consideration of security, reliability, and performance. This guide covers best practices and essential configuration for production environments.

Production Checklist

Before deploying TrailBase to production, ensure you’ve completed these essential steps:
1

Set a public URL

Configure the public URL for OAuth redirects and email links:
Or via environment variable:
2

Bind to the correct address

For production behind a reverse proxy:
For direct internet exposure, bind to localhost and use a reverse proxy:
3

Configure CORS

Restrict CORS origins to your domains:
4

Set up SMTP for emails

Configure email delivery for auth verification and password resets. Edit traildepot/config.textproto:
5

Review authentication settings

Adjust token TTLs in config.textproto:
6

Set up SSL/TLS

Use a reverse proxy (nginx, Caddy, Traefik) for SSL/TLS termination. Never expose TrailBase directly to the internet without HTTPS.
7

Configure backups

Implement automated backups of the data directory (see Backup Strategies below).
8

Set up monitoring

Implement health checks and monitoring (see Monitoring section below).
Never disable or weaken security features for convenience. Always use HTTPS, strong passwords, and proper CORS settings in production.

Security Best Practices

SSL/TLS Configuration

Always run TrailBase behind a reverse proxy with SSL/TLS:

File Permissions

Secure the data directory with proper permissions:

Secrets Management

TrailBase separates configuration into two files:
  • config.textproto - Non-sensitive configuration
  • secrets.textproto - Sensitive values (OAuth secrets, SMTP passwords)
Secrets marked with [(secret) = true] in the protobuf schema are automatically redacted to <REDACTED> in config.textproto and stored in secrets.textproto.
You can also override any configuration value using environment variables prefixed with TRAIL_, for example: TRAIL_EMAIL_SMTP_PASSWORD.

Admin Access

For production, consider separating admin UI access:
This binds:
  • Public API to 0.0.0.0:4000 (accessible externally)
  • Admin UI to 127.0.0.1:4001 (localhost only)
Access the admin UI through an SSH tunnel:

Rate Limiting

Implement rate limiting at the reverse proxy level:

Firewall Configuration

Backup Strategies

Regular backups are essential for production deployments.

Full Data Directory Backup

The simplest approach is backing up the entire data directory:
Schedule with cron:

SQLite Backup

For online backups without stopping the server, use SQLite’s backup API:

Cloud Backup

Sync backups to cloud storage:

Restore from Backup

To restore from a backup:
Always test your backup and restore procedures before you need them. Perform regular restore drills to ensure backups are valid.

Monitoring

Health Check Endpoint

TrailBase provides a health check endpoint:
Returns 200 OK if the server is healthy.

Uptime Monitoring

Use external monitoring services:
  • UptimeRobot: Simple HTTP monitoring
  • Pingdom: Advanced monitoring with alerting
  • Better Uptime: Modern uptime monitoring
  • StatusCake: HTTP and performance monitoring
Example configuration:
  • Monitor URL: https://yourdomain.com/api/healthcheck
  • Check interval: 60 seconds
  • Alert after: 2 consecutive failures

Log Monitoring

TrailBase stores access and error logs in the logs.db SQLite database:
For stdout logging (e.g., in Docker):

Log Retention

Configure log retention in config.textproto:

Resource Monitoring

Monitor system resources:
For automated monitoring, use:
  • Prometheus + Grafana: Metrics and dashboards
  • Netdata: Real-time performance monitoring
  • Datadog: Full-stack monitoring

Performance Metrics

Key metrics to monitor:
  • Request latency: P50, P95, P99 response times
  • Request rate: Requests per second
  • Error rate: 4xx and 5xx responses
  • Database size: Growth rate
  • CPU usage: Average and peak
  • Memory usage: RSS and growth
  • Disk I/O: Read/write operations

Scaling

Vertical Scaling

For most workloads, vertical scaling is the simplest approach:
  • Small: 1 CPU, 512 MB RAM - Up to 100 req/s
  • Medium: 2 CPU, 2 GB RAM - Up to 500 req/s
  • Large: 4 CPU, 4 GB RAM - Up to 2000 req/s
  • X-Large: 8 CPU, 8 GB RAM - Up to 5000+ req/s
TrailBase is extremely efficient. SQLite’s sub-millisecond latencies mean most applications won’t need horizontal scaling.

Horizontal Scaling (Read Replicas)

For read-heavy workloads:
1

Primary instance

Run a single write instance:
2

Create read replicas

Periodically copy the database to read-only instances:
3

Route traffic

Use a load balancer to route:
  • Writes → Primary instance
  • Reads → Read replicas (round-robin)
SQLite does not have built-in replication. For true high-availability and write scaling, consider commercial solutions like Turso or LiteFS.

CDN for Static Assets

If serving static files:
Place a CDN (CloudFlare, Fastly, CloudFront) in front to:
  • Cache static assets globally
  • Reduce load on TrailBase
  • Improve latency for users worldwide

Database Optimization

Optimize SQLite performance:
Run maintenance periodically:

Systemd Service

Run TrailBase as a systemd service:
/etc/systemd/system/trailbase.service
Enable and start:

Troubleshooting

High CPU Usage

Check for:
  • Expensive queries (add indexes)
  • Too many realtime subscriptions
  • Insufficient runtime-threads for WASM workloads

Database Locked

SQLite allows one writer at a time:
  • Enable WAL mode (enabled by default in TrailBase)
  • Reduce write transaction duration
  • Consider read replicas for read-heavy loads

Memory Leaks

Monitor memory over time:
If memory grows unbounded, file a bug report with:
  • TrailBase version
  • Memory growth rate
  • Request patterns
  • Configuration

Next Steps

Configuration

Detailed configuration options and environment variables

Self-Hosting

Learn about different deployment strategies