A simple and effective Elixir library for building multitenant applications using Ecto and database schemas.
Triplex is an Elixir library that implements database multitenancy for applications using Ecto. It solves the problem of data isolation between tenants by leveraging database-level segregation techniques like PostgreSQL schemas or separate MySQL databases. This allows developers to build SaaS applications where each tenant's data is kept separate while using the same codebase.
Elixir developers building multi-tenant SaaS applications, especially those using Ecto with PostgreSQL or MySQL who need secure and scalable data separation between customers.
Developers choose Triplex because it integrates directly with Ecto, requires minimal configuration, and provides a clean API for tenant management without introducing complex abstractions. It’s inspired by proven solutions like the Ruby apartment gem but designed specifically for the Elixir ecosystem.
Database multitenancy for Elixir applications!
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Only requires adding the prefix option in queries, as shown in the README with examples like Repo.all(User, prefix: Triplex.to_prefix("my_tenant")), leveraging Ecto's built-in capabilities.
Provides functions like Triplex.create/1 and Triplex.drop/1 that handle schema creation and migration execution automatically, simplifying tenant lifecycle operations.
Supports both PostgreSQL schemas and MySQL databases for data isolation, allowing developers to choose based on their infrastructure needs.
Includes configurable Plugs such as SubdomainPlug to easily load tenants from HTTP requests, reducing boilerplate code for API development.
For custom SQL in migrations, developers must manually use Ecto's prefix() function, as noted in the README, adding complexity and potential for errors.
Requires additional configuration and a tenants table for MySQL, or reliance on information_schema.schemata, which can be cumbersome and less intuitive.
Running migrations across all tenants can be slow and resource-intensive, as mentioned in the README, making it less ideal for applications with a high number of tenants.
Only works with Ecto-based applications, so it's not suitable for projects using other data access layers or frameworks outside the Elixir ecosystem.