Skip to main content
This guide covers best practices and considerations for deploying the Horse Trust platform to production.

Pre-Deployment Checklist

Before deploying to production, ensure you have completed the following:
1

Security Audit

Environment variables are properly secured
JWT secrets are strong and unique
CORS origins are restricted to specific domains
Rate limiting is configured
Helmet.js security headers are enabled
2

Database Preparation

MongoDB production cluster is set up
Database backups are configured
Connection pooling is optimized
Database indexes are created
3

Code Quality

All tests are passing
Linting errors are resolved
TypeScript compilation is successful
Dependencies are up to date
4

Performance

Build optimization is complete
Images are optimized
API response times are acceptable
Socket.io performance is tested

Environment Configuration

Production Environment Variables

Never use development settings in production. Update all configuration values.

Server (Backend) Production .env

Client (Frontend) Production .env.production

Deployment Options

Option 1: Vercel (Frontend) + Railway/Render (Backend)

Recommended for easy deployment with minimal configuration.

Deploy Frontend to Vercel

1

Install Vercel CLI

2

Navigate to Client Directory

3

Deploy

Or connect your GitHub repository through the Vercel Dashboard:
  1. Import your repository
  2. Configure project settings:
    • Framework: Next.js
    • Root Directory: client
    • Build Command: npm run build
    • Output Directory: .next
  3. Add environment variables in Vercel dashboard
  4. Deploy
4

Configure Environment Variables

In Vercel dashboard, add:
  • NEXT_PUBLIC_API_URL
  • NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME
  • NEXT_PUBLIC_CLOUDINARY_UPLOAD_PRESET

Deploy Backend to Railway

1

Create Railway Account

Sign up at Railway.app
2

Create New Project

  • Connect your GitHub repository
  • Select the server directory as root
3

Configure Build Settings

4

Add Environment Variables

In Railway dashboard, add all server environment variables:
  • PORT (Railway auto-provides this)
  • NODE_ENV=production
  • MONGO_URI
  • JWT_SECRET
  • JWT_EXPIRES_IN
  • BCRYPT_SALT_ROUNDS
  • CORS_ORIGINS
5

Deploy

Railway will automatically deploy on git push to main branch.

Option 2: Docker Deployment

For containerized deployments on any platform.

Server Dockerfile

Client Dockerfile

Docker Compose

Deploy with Docker Compose:

Option 3: VPS Deployment (Ubuntu/Debian)

For deployment on a virtual private server.
1

Server Setup

2

Clone and Build

3

Configure PM2

Create ecosystem.config.js:
Start applications:
4

Configure Nginx

Create /etc/nginx/sites-available/horsetrust:
Enable and restart:
5

Set Up SSL with Let's Encrypt

Production Considerations

Security

Strong Secrets

Use cryptographically secure random strings for JWT_SECRET:

CORS Restriction

Never use CORS_ORIGINS=* in production. Specify exact domains.

HTTPS Only

Always use SSL/TLS certificates. Use Let’s Encrypt for free certificates.

Rate Limiting

The server includes express-rate-limit - ensure it’s properly configured.

Database

Production Database Checklist:
  • Use MongoDB Atlas production tier with automated backups
  • Configure proper network security (IP whitelist)
  • Enable database auditing and monitoring
  • Set up connection pooling
  • Create appropriate indexes for queries
  • Implement backup and disaster recovery procedures

Performance

Server Optimization:
Next.js Optimization:

Monitoring

1

Application Monitoring

Use PM2 monitoring or services like:
  • Datadog
  • New Relic
  • Sentry (error tracking)
2

Database Monitoring

MongoDB Atlas provides built-in monitoring:
  • Query performance
  • Connection metrics
  • Storage usage
3

Server Health Checks

Implement health check endpoints:
4

Logging

The server uses Morgan for HTTP logging. In production:

Graceful Shutdown

The server already implements graceful shutdown:
This ensures:
  • Active connections are completed
  • Socket.io connections are closed properly
  • Database connections are released

Continuous Deployment

GitHub Actions Example

Troubleshooting Production Issues

  • Check for memory leaks with Node.js profiling
  • Ensure proper database connection pooling
  • Monitor Socket.io connections
  • Consider horizontal scaling
  • Add database indexes
  • Implement caching (Redis)
  • Optimize MongoDB queries
  • Use CDN for static assets
  • Enable gzip compression
  • Verify WebSocket support on your host
  • Check proxy configuration for WebSocket upgrades
  • Ensure sticky sessions for load balancers
  • Review CORS settings
  • Verify MongoDB Atlas IP whitelist
  • Check connection string format
  • Monitor connection pool usage
  • Review MongoDB Atlas metrics

Rollback Strategy

In case of deployment issues:

Next Steps

Monitoring Setup

Implement comprehensive monitoring and alerting

Backup Strategy

Set up automated database backups and recovery procedures

Load Testing

Perform load testing to identify bottlenecks

Documentation

Document your deployment process and runbooks