Skip to main content
Deploy MQTT Gateway to production with proper security, monitoring, and reliability configurations.

Production checklist

Before deploying to production, ensure you have:
  • Secure database credentials (not default demo/demo)
  • Network isolation between gateway and databases
  • Log retention and rotation policy
  • Monitoring and alerting configured
  • Backup strategy for database
  • Container restart policy configured
  • Resource limits defined
  • Flow configuration tested in staging

Secure configuration

Use secrets management

Never hardcode credentials in Docker commands or environment files. Use Docker secrets or external secrets management:

Database security

Create a dedicated database user with minimal permissions:
Update environment variables:

Network isolation

Isolate the gateway on a dedicated Docker network:

Resource limits

Define CPU and memory limits to prevent resource exhaustion:

Logging and monitoring

Centralized logging

Mount logs to a persistent location:
The gateway creates daily log files with format YYYY-MM-DD.log in the configured LOG_DIR.

Log rotation

Implement log rotation to manage disk space:

Health monitoring

Monitor container health:
Set up alerts for:
  • Container restarts
  • Database connection failures
  • MQTT connection drops
  • Disk space in log directory

Flow configuration

Reload interval tuning

The gateway reloads flows from the database every FLOWS_RELOAD_INTERVAL_SECONDS (default 600 seconds / 10 minutes) as defined in src/config.py:48. Adjust based on your needs:
Shorter intervals increase database queries. Longer intervals delay flow configuration changes.

HTTP timeout configuration

For flows with action=POST_ENDPOINT, configure appropriate timeout based on endpoint response times:
Timeout is configured in src/config.py:45.

Database management

Connection pooling

The gateway uses SQLAlchemy with PyMySQL for database connections. Connection settings are defined in src/config.py:22:

Data retention

Implement data retention policies for the data table:
Schedule as a cron job or database event.

Backup strategy

Regularly backup the database:

High availability

Container restart policy

Use --restart unless-stopped to ensure the container restarts after crashes or host reboots:
Alternative restart policies:
  • no - Never restart (default)
  • on-failure - Restart only on non-zero exit
  • always - Always restart, even after manual stop
  • unless-stopped - Restart unless explicitly stopped

Multiple instances

Running multiple gateway instances requires careful MQTT client ID management to avoid conflicts.
To run multiple instances:
  1. Use unique MQTT_CLIENT_ID for each instance
  2. Partition flows by topic across instances
  3. Use a load balancer for HTTP endpoints

Performance optimization

Database indexes

Add indexes for frequently queried columns:

MQTT keepalive tuning

Adjust MQTT_KEEPALIVE based on network reliability:
Defined in src/config.py:47.

Troubleshooting production issues

Container won’t start

Check container logs:
Common issues:
  • Missing required environment variables (DB_HOST, DB_NAME, DB_USER, DB_PASSWORD)
  • Database connectivity issues
  • Invalid configuration values

Database connection failures

Verify connectivity from container to database:
Check firewall rules and network policies.

MQTT messages not processing

Verify enabled flows exist:
Check MQTT broker configuration:

POST_ENDPOINT failures

Check logs for HTTP errors. Verify:
  • Endpoint URL is correct and accessible
  • HTTP_TIMEOUT_SECONDS is appropriate
  • Endpoint returns proper HTTP response codes
  • Network connectivity to endpoint
Test endpoint manually: