|
| 1 | +# ADR-003: Use MySQL Over MariaDB for Database Backend |
| 2 | + |
| 3 | +## Status |
| 4 | + |
| 5 | +Accepted |
| 6 | + |
| 7 | +## Context |
| 8 | + |
| 9 | +As part of the migration from SQLite to a production-ready database backend for the Torrust |
| 10 | +Tracker Demo, we needed to choose between MySQL and MariaDB. Both are popular open-source |
| 11 | +relational database management systems, with MariaDB being a fork of MySQL that aims to |
| 12 | +maintain compatibility while offering additional features and performance improvements. |
| 13 | + |
| 14 | +### Key Considerations |
| 15 | + |
| 16 | +1. **Official Torrust Tracker Support**: The Torrust Tracker project officially documents |
| 17 | + and tests specific database drivers |
| 18 | +2. **Compatibility and Reliability**: Ensuring maximum compatibility with the tracker |
| 19 | + application and minimal integration issues |
| 20 | +3. **Community and Documentation**: Availability of support, documentation, and |
| 21 | + troubleshooting resources |
| 22 | +4. **Future Maintenance**: Long-term maintainability and alignment with upstream project |
| 23 | + decisions |
| 24 | +5. **Performance**: Database performance for BitTorrent tracker workloads (primarily CRUD |
| 25 | + operations) |
| 26 | + |
| 27 | +### Technical Requirements |
| 28 | + |
| 29 | +The Torrust Tracker requires: |
| 30 | + |
| 31 | +- Support for connection pooling via `r2d2_mysql` Rust crate |
| 32 | +- MySQL-specific connection string format: `mysql://user:password@host:port/database` |
| 33 | +- Compatibility with tracker's database schema and SQL syntax |
| 34 | +- Auto-increment primary keys and foreign key constraints |
| 35 | +- UTF-8 character encoding support |
| 36 | + |
| 37 | +## Decision |
| 38 | + |
| 39 | +We will use **MySQL 8.0** as the default database backend for the Torrust Tracker Demo instead of MariaDB. |
| 40 | + |
| 41 | +## Rationale |
| 42 | + |
| 43 | +### 1. Official Torrust Tracker Support |
| 44 | + |
| 45 | +- **Documented Support**: Torrust Tracker documentation explicitly mentions "SQLite and |
| 46 | + MySQL" support, with no mention of MariaDB |
| 47 | +- **Default Configuration**: All official examples, Docker configurations, and test |
| 48 | + setups use MySQL 8.0 |
| 49 | +- **Codebase Implementation**: The tracker uses the `r2d2_mysql` crate specifically |
| 50 | + designed for MySQL, not a generic MariaDB-compatible driver |
| 51 | + |
| 52 | +### 2. Testing and Validation |
| 53 | + |
| 54 | +- **Integration Tests**: Torrust Tracker's test suite specifically uses MySQL 8.0 |
| 55 | + containers for database driver testing |
| 56 | +- **CI/CD Pipeline**: The official project's continuous integration validates against |
| 57 | + MySQL, ensuring compatibility |
| 58 | +- **Environment Variable**: Tests are controlled via |
| 59 | + `TORRUST_TRACKER_CORE_RUN_MYSQL_DRIVER_TEST=true`, indicating MySQL-specific testing |
| 60 | + |
| 61 | +### 3. Community and Ecosystem Alignment |
| 62 | + |
| 63 | +- **BitTorrent Community Standard**: The broader BitTorrent tracker community |
| 64 | + predominantly uses MySQL |
| 65 | +- **Documentation Consistency**: All troubleshooting guides, configuration examples, and |
| 66 | + community solutions reference MySQL |
| 67 | +- **Upstream Alignment**: Following the same database choice as the upstream Torrust |
| 68 | + Tracker project ensures consistent behavior |
| 69 | + |
| 70 | +### 4. Technical Implementation Benefits |
| 71 | + |
| 72 | +- **Connection String Compatibility**: MySQL connection strings are guaranteed to work |
| 73 | + with the tracker's database driver |
| 74 | +- **SQL Syntax Alignment**: The tracker's SQL queries are written and tested against |
| 75 | + MySQL 8.0 specifically |
| 76 | +- **Migration Path**: Future updates to Torrust Tracker will be tested against MySQL, |
| 77 | + ensuring smooth upgrades |
| 78 | + |
| 79 | +### 5. Reduced Risk Profile |
| 80 | + |
| 81 | +- **Known Configuration**: Using MySQL eliminates uncertainty about MariaDB compatibility edge cases |
| 82 | +- **Proven Compatibility**: MySQL 8.0 is the tested and validated database backend for Torrust Tracker |
| 83 | +- **Support Availability**: Issues and solutions are more readily available for MySQL configurations |
| 84 | + |
| 85 | +## Consequences |
| 86 | + |
| 87 | +### Positive |
| 88 | + |
| 89 | +- **Maximum Compatibility**: Guaranteed compatibility with current and future Torrust Tracker versions |
| 90 | +- **Better Documentation**: All configuration examples and troubleshooting guides apply directly |
| 91 | +- **Simplified Maintenance**: No need to test or validate MariaDB-specific compatibility issues |
| 92 | +- **Community Support**: Easier to get help from the Torrust community when using the standard database |
| 93 | +- **Future-Proof**: Alignment with upstream project decisions reduces migration risks |
| 94 | + |
| 95 | +### Neutral |
| 96 | + |
| 97 | +- **Performance**: Both MySQL and MariaDB would provide similar performance for tracker workloads |
| 98 | +- **Resource Usage**: Memory and CPU usage are comparable between the two databases |
| 99 | +- **Feature Set**: The tracker uses basic SQL features available in both databases |
| 100 | + |
| 101 | +### Negative |
| 102 | + |
| 103 | +- **Vendor Lock-in**: Choosing MySQL over MariaDB means following Oracle's MySQL development path |
| 104 | +- **License Considerations**: MySQL has Oracle's commercial licensing model (though GPL version is used) |
| 105 | +- **Missing MariaDB Features**: We won't benefit from MariaDB-specific performance improvements or features |
| 106 | + |
| 107 | +## Implementation |
| 108 | + |
| 109 | +The MySQL 8.0 configuration is implemented as follows: |
| 110 | + |
| 111 | +### Docker Compose Configuration |
| 112 | + |
| 113 | +```yaml |
| 114 | +mysql: |
| 115 | + image: mysql:8.0 |
| 116 | + environment: |
| 117 | + - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} |
| 118 | + - MYSQL_DATABASE=${MYSQL_DATABASE} |
| 119 | + - MYSQL_USER=${MYSQL_USER} |
| 120 | + - MYSQL_PASSWORD=${MYSQL_PASSWORD} |
| 121 | + command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci |
| 122 | +``` |
| 123 | +
|
| 124 | +### Tracker Configuration |
| 125 | +
|
| 126 | +```toml |
| 127 | +[core.database] |
| 128 | +driver = "mysql" |
| 129 | +path = "mysql://torrust:password@mysql:3306/torrust_tracker" |
| 130 | +``` |
| 131 | + |
| 132 | +### Environment Variables |
| 133 | + |
| 134 | +```env |
| 135 | +TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER=mysql |
| 136 | +TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__PATH=mysql://torrust:password@mysql:3306/torrust_tracker |
| 137 | +``` |
| 138 | + |
| 139 | +## Alternative Considered |
| 140 | + |
| 141 | +### MariaDB 10.x |
| 142 | + |
| 143 | +**Pros:** |
| 144 | + |
| 145 | +- Generally faster than MySQL in some benchmarks |
| 146 | +- More storage engines and advanced features |
| 147 | +- Fully open-source governance model |
| 148 | +- Active development and regular releases |
| 149 | + |
| 150 | +**Cons:** |
| 151 | + |
| 152 | +- Not officially supported or tested by Torrust Tracker |
| 153 | +- Potential compatibility issues with MySQL-specific driver code |
| 154 | +- Less documentation and community support for tracker use cases |
| 155 | +- Risk of subtle differences causing issues in production |
| 156 | +- May require additional validation and testing |
| 157 | + |
| 158 | +**Conclusion:** While MariaDB offers technical advantages, the benefits don't outweigh |
| 159 | +the risks and compatibility concerns for this specific use case. |
| 160 | + |
| 161 | +## References |
| 162 | + |
| 163 | +- [Torrust Tracker Documentation](https://docs.rs/torrust-tracker/) |
| 164 | +- [Torrust Tracker Database Configuration](https://docs.rs/torrust-tracker-configuration/latest/torrust_tracker_configuration/v2_0_0/database/struct.Database.html) |
| 165 | +- [Torrust Tracker MySQL Driver Implementation](https://github.com/torrust/torrust-tracker/blob/main/packages/tracker-core/src/databases/driver/mysql.rs) |
| 166 | +- [Torrust Tracker Docker Compose Example](https://github.com/torrust/torrust-tracker/blob/develop/docs/containers.md) |
| 167 | +- [Issue #12: Use MySQL instead of SQLite by default](../issues/12-use-mysql-instead-of-sqlite-by-default.md) |
| 168 | + |
| 169 | +## Revision History |
| 170 | + |
| 171 | +- **2025-07-08**: Initial decision document created |
| 172 | +- **Decision maker**: Development team |
| 173 | +- **Reviewed by**: N/A (initial implementation) |
0 commit comments