Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yes, for multi-tenancy. Database per tenant works alright if you have enterprise customers - i.e. in the hundreds, not millions - and it does help in security. With the right idioms in the codebase, it pretty much guarantees you don't accidentally hand one tenant data belonging to a different tenant.

MySQL connections can be reused with database per tenant. Rack middleware (apartment gem) helps with managing applying migrations across all databases, and with the mechanics of configuring connections to use a tenant based on Host header as requests come in.

For async jobs in Java, allocating a connection can idiomatically only be done via a callback - e.g. `executeInTenantContext(Tenant tenant, Runnable block)` - which ensures that all connections handed out have the right tenant selected, and everything is reset to the default tenant (an empty database) when exiting. Per-tenant jobs either iterate through all tenants, or have a tenant parameter under which they get executed, and the rest of the code can be more or less tenant unaware.

It gives you the "freedom" to move tenants to separate servers, or consolidate them into single servers, if tenants are much larger or much smaller than expected. In reality this is sufficiently painful it's mostly illusory. We're looking at Vitess to help scale out, and move away from a mix of multi-tenant servers and single-tenant servers.



It also makes sharding/ horizontal scalability a non-issue, at least until you get a big enough customer.


But like, every database is easy to shard/horizontally scale until you get a big enough customer. Why do the extra leg work?


If you have 500 medium customers and you need to add sharding to a multitenant production behemoth, it's not trivial.


It's mostly a contractual decision, not because the engineering team wants to implement it for giggles.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: