PostgreSQL Configuration
Frontier uses PostgreSQL to store users, organizations, subscriptions, billing data, and other application state.Requirements
- PostgreSQL 12 or higher
- Database with appropriate permissions for schema migrations
- SSL/TLS recommended for production
Configuration
Database driver. Currently only PostgreSQL is supported.
PostgreSQL connection string.Format:
postgres://[user]:[password]@[host]:[port]/[database]?[parameters]Maximum number of idle connections in the pool.Idle connections are kept open for reuse. Increase for high-traffic applications.
Maximum number of open connections to the database.Limits total concurrent connections. Should be set based on your PostgreSQL
max_connections setting.Recommended: Set to PostgreSQL’s max_connections divided by number of application instances.Maximum amount of time a connection can be reused.Helps prevent connection leaks and ensures connections are refreshed periodically.
Maximum execution time for individual database queries.Queries exceeding this timeout will be cancelled.
Connection String Parameters
Common PostgreSQL connection parameters:-
sslmode - SSL connection mode
disable- No SSL (development only)require- Require SSL but don’t verify certificateverify-ca- Require SSL and verify certificateverify-full- Require SSL, verify certificate and hostname
- connect_timeout - Connection timeout in seconds
- application_name - Application name for PostgreSQL logs
- search_path - Default schema search path
Example Configurations
Database Initialization
Frontier automatically runs migrations on startup. To initialize the database:Performance Tuning
For production deployments:-
Connection Pool Sizing
-
Query Timeout
-
PostgreSQL Settings (postgresql.conf)
SpiceDB Configuration
SpiceDB is Frontier’s authorization database, implementing Google Zanzibar-style permissions.Requirements
- SpiceDB v1.22.0 or higher
- Running SpiceDB instance (see SpiceDB installation)
- Network connectivity between Frontier and SpiceDB
Configuration
Hostname or IP address of the SpiceDB service.
Port number for SpiceDB gRPC API.
Authentication key for SpiceDB communication.
Consistency mode for SpiceDB operations.Options:
full- Guarantees fresh data, slower performancebest_effort- Balances freshness and performance (recommended)minimize_latency- Prioritizes speed, may return slightly stale data
Enable detailed tracing for SpiceDB permission checks.
Deprecated: Use
consistency: "full" instead.Ensures fully consistent API responses at the cost of performance.Example Configurations
SpiceDB Deployment
Using Docker
Using Docker Compose
docker-compose.yml
Production Deployment
For production, SpiceDB should use PostgreSQL or CockroachDB as its datastore:Consistency Modes Explained
| Mode | Use Case | Trade-offs |
|---|---|---|
| full | Financial transactions, critical operations | Highest consistency, slower performance |
| best_effort | General application use | Balanced consistency and speed (recommended) |
| minimize_latency | Read-heavy applications, dashboards | Fastest, may show slightly stale data |
Monitoring SpiceDB
SpiceDB exposes metrics at:9090/metrics (Prometheus format). Key metrics:
grpc_server_handled_total- Total requestsgrpc_server_handling_seconds- Request durationspicedb_datastore_read_namespaces_total- Read operations
Complete Example
Troubleshooting
PostgreSQL Connection Issues
Problem:connection refused
too many connections
- Reduce
max_open_connsin Frontier config - Increase PostgreSQL
max_connections - Check for connection leaks
SpiceDB Connection Issues
Problem:unauthenticated
- Verify
pre_shared_keymatches SpiceDB configuration - Check SpiceDB logs for authentication errors
deadline exceeded
- Check network connectivity to SpiceDB
- Verify SpiceDB is running and healthy
- Consider adjusting
consistencymode
- Disable
check_traceif enabled - Use
minimize_latencyconsistency mode - Scale SpiceDB horizontally