Multi tenant app with database-per-tenant

I recently started building an architecture for a multi-tenant app to support a database per tenant (customer) scenario for one of my customers. Splitting your data in multiple databases like that has a few benefits like easy backup and restore per customer, better security by separation of data, and potential performance benefits. Especially the separation of data was a hard requirement here. I found this to be a nice challenge as it involves many moving parts to get it right. There’s of course the software, but there’s also the infrastructure on Azure. This post is the first of a series of blogs that I will write over the coming weeks/months. The result will use a .NET Core API, Azure SQL with Elastic pooling, Entity Framework Core with Migrations, and the Elastic Database Tooling client library to manage all the tenant databases and acquire a connection to the correct one.

I’ll divide this series into the following posts:

  • Infrastructure
    • We need infrastructure to support our model and will use Azure SQL with Elastic Pools read…
  • Adding a catalog database
    • We need someplace where we store data like which tenant uses which database and where does that reside. We’ll use Entity Framework Core and EF Migrations. Deployment of database changes will be done during the release in Azure DevOps
  • Managing the Tenant databases
    • We will use the Elastic Database client library and ARM templates to manage existing tenants and create new ones
  • Retrieval of a specific Tenants connection-string
    • This blog will show how to get the correct connection-string per request in our .NET Core API

Before we start building our catalog database, I first want to point you to a couple of useful Microsoft documentation pages. I think it’s worthwhile to read them because they explain the concepts used in these blog posts a lot better than I ever could. The first one is about the different multi-tenancy database patterns you could apply. We’re using the ‘Multi-tenant app with database-per-tenant’-pattern.

The second one is an introduction to scaling on Azure SQL, introduces the Elastic tooling, and explains sharding.

The third one explains the Shard Map Manager, which will be at the heart of our database per code.