Story Details

  • Shardines: SQLite3 Database-per-Tenant with ActiveRecord

    Posted: 2025-04-27 12:16:59

    Shardines is a Ruby gem that simplifies multi-tenant applications using SQLite3 by creating a separate database file per tenant. It integrates seamlessly with ActiveRecord, allowing developers to easily switch between tenant databases using a simple Shardines.with_tenant block. This approach offers the simplicity and ease of use of SQLite, while providing data isolation between tenants. The gem handles database creation, migration, and connection switching transparently, abstracting away the complexities of managing multiple database connections. This makes it suitable for applications where strong data isolation is required but the overhead of a full-fledged database system like PostgreSQL is undesirable.

    Summary of Comments ( 17 )
    https://news.ycombinator.com/item?id=43811400

    Hacker News users generally reacted positively to the Shardines approach of using a SQLite database per tenant. Several praised its simplicity and suitability for certain use cases, especially those with strong data isolation requirements or where simpler scaling is prioritized over complex, multi-tenant database setups. Some questioned the long-term scalability and performance implications of this method, particularly with growing datasets and complex queries. The discussion also touched on alternative approaches like using schemas within a single database and the complexities of managing large numbers of database files. One commenter suggested potential improvements to the gem's design, including using a shared connection pool for performance. Another mentioned the potential benefits of utilizing SQLite's online backup feature for improved resilience and easier maintenance.