Understanding Multi-Tenancy in Dolibarr

Multi-tenancy in Dolibarr refers to an architecture where a single instance of the ERP/CRM software serves multiple clients (tenants) simultaneously. Each tenant operates independently, with their data securely isolated from others, while sharing the same application codebase and infrastructure. This approach contrasts with single-tenant setups, where each client has a separate Dolibarr installation.

The primary advantage of multi-tenancy is resource efficiency. By consolidating multiple clients onto a single instance, you reduce hardware, software licensing, and maintenance overhead. However, this architecture introduces complexities, particularly around data isolation, customization, and scalability.

Database Design for Multi-Tenancy

There are two primary database strategies for multi-tenant Dolibarr setups:

Database-per-Tenant

In this approach, each client has a dedicated database, while sharing the same Dolibarr application codebase. This ensures strong data isolation, as each tenant's data is physically separate. However, it requires careful management of database connections and may increase resource usage.

Shared Database with Tenant Separation

Here, all tenants share a single database, with tenant-specific data distinguished by a tenant_id column in relevant tables. This approach is more resource-efficient but demands rigorous query filtering to prevent data leakage between tenants.

Tenant Identification and Routing

Effective tenant identification is crucial in a multi-tenant Dolibarr setup. Common methods include:

  • Subdomain Routing: Each client accesses Dolibarr via a unique subdomain (e.g., client1.example.com, client2.example.com).
  • Custom Login Flow: Users select their tenant during login, typically via a dropdown or company identifier field.
  • Separate Client Folders: Each tenant has a distinct folder within the Dolibarr directory structure.

Configuration and Management

While tenants share the core Dolibarr application, certain configurations must be tenant-specific:

  • Company Information: Each tenant requires unique settings for company name, logo, and contact details.
  • VAT Rules: Tax configurations may vary by tenant, especially in multinational setups.
  • Email Servers: Tenants may need separate SMTP configurations for outgoing emails.

These tenant-specific settings can be managed through Dolibarr's configuration system, either via the admin interface or by extending the conf.php file.

Monitoring and Support

Effective multi-tenant Dolibarr hosting requires robust monitoring and support mechanisms:

  • Performance Monitoring: Track application performance metrics per tenant to identify and address bottlenecks.
  • Error Logging: Maintain separate error logs for each tenant to simplify troubleshooting.
  • Resource Usage: Monitor CPU, memory, and disk usage per tenant to ensure fair resource allocation.

Implementing these monitoring strategies ensures that you can support individual tenants without impacting others.

Scaling and Isolation

As your multi-tenant Dolibarr instance grows, scaling becomes a critical consideration. Horizontal scaling can be achieved by distributing tenant workloads across multiple servers or containers. Technologies like Kubernetes or Docker can provide additional isolation and resource management capabilities.

For high-security environments, consider implementing tenant-specific virtual machines or containers to further isolate workloads. This approach adds overhead but enhances security and resource control.