Ben Phung Ngoc
Ben Phung Ngoc

Reputation: 112

Database pattern for SaaS and Microservices

I'm at the very beginning phase building a SaaS solution. The requirements are:

  1. All customers must use the same version of the app.
  2. Data from different customers must be isolated.

So, I think that I should go with microservices and database-per-tenant. I'm now trying to find out how to design the databases.

My first thought is if I have 10 services and 15 tenants then I have 150 databases because each service should have its own DB and each tenant should have its own DB as well.

Is that a valid approach or should I go with another design? Also, what should I do to route the connection from a service to the correct tenant DB?

Upvotes: 0

Views: 141

Answers (1)

Robert Howe
Robert Howe

Reputation: 324

Yes: that's exactly the right approach.

Use a subdomain in the URL to route traffic to the correct portal service like this: https://tenantN.domain.tld

You've probably thought of this too, but set up access controls such that somebody authenticated for one tenant cannot access another tenant's services by guessing an FQDN, or a malicious person using brute force generation of FQDNs.

Upvotes: 1

Related Questions