Ask HN: Has anybody shipped a web app at scale with 1 DB per account?
Where I work we&#x27;re about to move from a single DB across all tenants to a separation of sorts, due to scaling and customer demands.  Very large enterprise customers will get their own DB as a &quot;group of one&quot;, and &quot;groups&quot; of smaller customers will share a DB.  Certain groups will get more up-to-date software with more software version churn, likely a higher number of issues.  Other groups will get only rock-solid older versions with back-ported bug fixes ... both kinds of groups will then see benefits along a feature-to-stability curve.  Tenants who pay will get test tenants and a chance for those to be in a &quot;group&quot; that&#x27;s ahead, software-version-wise, of their normal formal tenant.<p>We do not generally want to fork the product for different versions or schemas or special features -- the goal instead is to roll upgrades through different groups so we have more time to react to issues.  We still want one single software version and data storage layout lineage.  This matches the Salesforce.com model, so we won&#x27;t need to deal with lots of different data migration histories, custom fields, etc. (I&#x27;m curious to see how long we stick with that).  (I realize SFDC is all about custom objects, fields, UIs, etc. ... but their underlying software is same for all tenants.  We also have some measure of customization, but within the same underlying DB layout that&#x27;s the same across all tenants.)<p>The backend tenants use is written largely in Java &#x2F; Spring with managed-RDBMS and other data-storage technologies from one of the big cloud vendors.  Orchestration is into a Kubernetes&#x2F;ISTIO environment provisioned from raw cloud-compute, not a managed service.  The coordinator between the managed storage-and-other services, Kubernetes&#x2F;ISTIO, the Docker backend-software registries, the secrets-managers, etc., is a custom Django REST Framework (DRF) server app that lets DevOps provision &quot;groups&quot;, attached to them fixed data resources (that don&#x27;t usually change from deployment-to-deployment) as well as periodically revised&#x2F;upgraded software resources (i.e., Docker containers with backend software).<p>The DRF server app&#x27;s main job is to let DevOps define the next-desired-state aka &quot;deployment&quot; for a &quot;group&quot; (upgrading one or more of the backend servers ... changing the provisioning parameters for a fixed resource ... etc.), and then the kick off a transition to that desired state.  Each such &quot;deployment&quot; reviews and validates once again all resource availability, credentials, secrets, etc. ... stopping along the way as appropriate for human verifications.  Each step is done within a Django transaction, leading from &quot;old deployment&quot; to &quot;new deployment&quot;.  Any failure in any step (after an appropriate number of retries) leads to a rollback to the previous deployment state.  There&#x27;s only one low-level step whose failure would lead to an undetermined &quot;emergency&quot; state getting stuck &quot;between deployments&quot;, and that&#x27;s very unlikely to fail since by that point all elements needed for the crucial &quot;switch&quot; in upgraded software have been touched multiple times such that failure at that point is real unlikely.  There&#x27;s a fairly straightforward recovery from that state as well, after human intervention.<p>We chose this custom method because there are so many elements in so many different infrastructures to verify and tie together that wrapping all the operations in transaction-mediated Python made sense, plus the Python APIs for all infrastructure elements a very good, and mostly involve sending&#x2F;receiving&#x2F;inspecting JSON or JSON-like data.  There&#x27;s plenty of logging, and plenty of side-data stored as JSON blobs in DB records for proper diagnosis and accounting when things to go wrong.  Groups can have their software upgraded without impact to other groups in the system.  Another advantage is that as the &quot;architecture&quot; or &quot;shape&quot; of data and software resources attached to a &quot;group&quot; changes (changes to how configuration is done; introduction of a new backend service; introduction of a new datastore), the DRF server app can seamlessly transition the group from the old to the new shape (after software revision to make the DRF server app aware of what those changes are).<p>The DRF server app itself is easy to upgrade, and breaking changes can be resolved by an entire parallel deployment of the DRF server app and all the &quot;groups&quot; using the same per-group backend datastores .. the new deployment listens on a &quot;future&quot; form of all tenant URLs.  At switchover time the pre-existing DRF server app&#x27;s tenant URLs get switched to an &quot;past&quot; form, the new DRF server app&#x27;s groups tenant URLs get switched.<p>In any case, these are some of the advantages of the approach.  The main takeaways so far have been:<p><pre><code>  - there was major commitment to building this infrastructure, it hasn&#x27;t been easy

  - controlled definition of &quot;groups&quot; and upgrades to &quot;groups&quot; are very important, we want to avoid downtime

  - Kubernetes and ISTIO are great platforms for hosting these apps -- the topology of what a &quot;group&quot; and its tenants look like is a bit complicated but the infrastructure works well

  - giving things a unique-enough name is crucial ... as a result we&#x27;re able to deploy multiple such constellations of fake-groups-of-tenants in development&#x2F;test environments, each constellation managed by a DRF server

  - the DRF will host an ever-growing set of services related to monitoring and servicing the &quot;groups&quot; -- mostly it can be a single-source-of-data with links to appropriate consoles in Kibana, Grafana, cloud-provider infrastructure, etc.,
</code></pre>
We&#x27;re still early in the use but so far so good.