Build configuration
Build script
Toots uses the following build script defined inapps/web/package.json:
- Prisma client is generated
- Database migrations are applied
- Next.js builds the production bundle
Environment variables
In production, ensure all required environment variables are set:Database configuration
Connection pooling
For production PostgreSQL, use connection pooling to handle concurrent requests efficiently:Migration strategy
Run migrations before deployment
Always apply migrations before deploying new application code:Or use Prisma’s deploy command for production:
Database backups
Implement automated backups:- Frequency: Daily at minimum, more often for high-traffic applications
- Retention: Keep at least 30 days of backups
- Testing: Regularly test backup restoration
Security best practices
Authentication secrets
Generate a strongBETTER_AUTH_SECRET:
Database credentials
- Use strong, unique passwords
- Limit database user permissions to only what’s needed
- Enable SSL/TLS for database connections in production
- Restrict database access to application servers only
HTTPS configuration
Always use HTTPS in production:Performance optimization
Node.js configuration
Set appropriate Node.js memory limits:Next.js optimization
The build process automatically optimizes:- Static page generation
- Image optimization
- Code splitting
- Minification
- Output caching: Cache API responses and database queries
- CDN integration: Serve static assets from a CDN
- ISR (Incremental Static Regeneration): For semi-dynamic pages
Database optimization
- Add indexes for frequently queried fields
- Use database query caching where appropriate
- Monitor slow queries with
pg_stat_statements - Consider read replicas for high-traffic applications
Platform-specific deployment
Vercel
Toots can be deployed to Vercel with a managed PostgreSQL database:Railway
Railway provides managed PostgreSQL and automatic deployments:- Connect your GitHub repository
- Add a PostgreSQL service
- Configure environment variables
- Railway automatically runs build and migrations
AWS / Cloud platforms
For AWS, Google Cloud, or Azure:- Use managed PostgreSQL (RDS, Cloud SQL, Azure Database)
- Deploy containers to ECS, Cloud Run, or App Service
- Use load balancers for high availability
- Configure auto-scaling based on traffic
Monitoring and logging
Application monitoring
Monitor key metrics:- Response times
- Error rates
- Database query performance
- Memory and CPU usage
- Sentry for error tracking
- Datadog or New Relic for APM
- LogRocket for session replay
Database monitoring
Track:- Connection pool usage
- Query performance
- Disk space
- Replication lag (if using replicas)
Logging
Centralize logs using:- CloudWatch (AWS)
- Cloud Logging (Google Cloud)
- Papertrail or Logtail
- ELK stack for self-hosted solutions
Health checks
Implement health check endpoints for load balancers and orchestration platforms:Scaling considerations
Horizontal scaling
Toots is stateless and can scale horizontally:- Run multiple application instances behind a load balancer
- Use sticky sessions if needed for WebSocket connections
- Share session state via database or Redis
Database scaling
For high traffic:- Vertical scaling: Increase database instance size
- Read replicas: Route read queries to replicas
- Connection pooling: Use pgBouncer or AWS RDS Proxy
- Caching: Add Redis for frequently accessed data
Rollback strategy
Prepare for rollbacks:- Version control: Tag releases in Git
- Database migrations: Test rollback migrations
- Blue-green deployment: Run old and new versions simultaneously
- Feature flags: Disable new features without redeploying
Checklist
Before going to production:- All environment variables are set securely
- Database backups are configured and tested
- HTTPS is enabled
- Authentication secrets are strong and unique
- Database connections use SSL
- Monitoring and logging are configured
- Health check endpoints are implemented
- Error tracking is set up
- Load testing has been performed
- Rollback procedure is documented
- On-call rotation is established (if applicable)