Fork me on GitHub

We are testing datomic-cloud and are planning to start using it soon. We have a business SaaS product and currently use a single multi-tenant database. The question is, is there any recommended architecture for multi-tenant apps? Single database, multiple databases?

Mark Addleman15:08:41

I had success with the following architecture: design a schema for multi-tenancy but place each tenant in a separate database. We also had an admin or account database that served as a catalog of accounts.

Mark Addleman15:08:01

By designing the schema for multi-tenants, we were able to more directly handle new business requirements around free-tier accounts (all of those went into a single db) and we anticipated that would be easier to handle requirements around subaccounts


Let me see if I understand what you are saying. You kept an :account/id attribute for every record that needed that, but instead of using one db you used multiple dbs?


I was considering using different db for each tenant (account) to be able to get rid of the :account/id in every single record. So I wanted to know if there was some hard limit on the number of dbs you can create in datomic or if it’s not a best practice, etc

Mark Addleman14:08:54

Yes, I kept :account/id and it (almost always) had the same value within the db.

Mark Addleman14:08:59

I don't believe there is a hard limit on number of dbs. However, Stu once said that an implementation detail kept multiple dbs from being as performant at current transact operations as it theoretically could be. I suggest you contact Datomic support if you are concerned about high throughput concurrent transactions across dbs.


Thanks a lot @UAMEU7QV7 for sharing your thoughts

👍 4
Sam Ferrell02:08:39

Beginner question... using a datalog query, how would I assert the value is non-nil? [?e :my/attr ???]


You can't have nil values in Datomic so you want to assert that an attribute exists for the entity which you can do with [?e :my/attr].

Sam Ferrell15:08:20

thank you both!