Setting up AWS RDS databases for simple multi-tenant design

,

I am a newbie to Amazon RDS. I have a very simple server app that is a Windows executable that uses a local MySQL server (localhost).
I want to move this server to the AWS cloud. I have the app running in a Windows EC2 talking to a local MySQL server just fine. Now I want to make it use an RDS database in a multi-tenant design such that each app (i.e. each customer) has their own database.
I have setup multiple clusters each with their own single database, but then each database would have a different DNS address.

Is there a way to have a single database server (i.e. single DNS address) and each tenant have their own database contained within?


Related discussions:

You can have multiple databases within one RDS instance. Just give you databases unique names which match your client names or IDs or whatever you’re using.

Yes, an RDS instance can contain multiple user databases. Connect to your instance with your normal client tool(s) and create databases within the instance. Permission database grants as required. Your customers would use the same DNS endpoint but a customer specific database in their connection string/profile.

There’s no way to stick a database inside of another one. That being said, there are ways to handle multiple groups of data. There are several ways you could handle this, the best way isn’t immediately clear without knowing specific requirements:

  1. You could have a centralized DB that holds the name of each customer and then the RDS endpoint.
  2. Depending on number of customers you could have a single DB, and instead of making new databases for each customer, you’d make a new table for them.
  3. You could keep multiple DBs and then essentially stick them behind an ALB that handles the different paths.

Why is the endpoint the problem? Is it because it’s dynamic? Or is it that you’d like to have only 1 DB endpoint? (If you’re set on the single endpoint idea, you’re going to have to resolve how to know which Customer’s information to grab at some point along the stack)

Edit: misread OPs question. You can have multiple DBs on an RDS instance.

why cant you create more database on your rds instance? https://forums.aws.amazon.com/thread.jspa?messageID=771296

Firstly RDS provides a database instance that runs a single engine but can contain multiple databases. It’s not a database in a database, it just creates a single database by default.

Secondly, your points:

  1. Why add this complexity when the OP wanted a simple multi tenant solution, what will he do with the RDS to customer endpoint mapping? The customer is making the connection.

  2. Why when you can just create a database. What if the customer wants to create/needs multiple tables (which is highly likely).

  3. Putting a HTTP LB in front of multiple databases is a not good idea nor will it work since the DB connections are not HTTP/S. There are valid use cases for putting a L7 LB in front of multiple databases (read replicas) but this isn’t one of them, and you’d want to use an SQL aware LB to do that, which ALB is not.

Thanks! I will give that a try. I’m not sure how to set that up from their web GUI, but I will try to figure that out.

I’m sorry, I misspoke. My current windows executable can use up to 26 databases, so I need to be able to create a set of up to 26 databases per tenant. Each of those 26 databases don’t need to be separate from each other, but I would like each set of 26 databases (tenant A) to be separate from the next set of 26 databases (tenant B). Is that possible with a single server/dns address within AWS?

Can you provide more detail on why you need a single DNS endpoint for all these databases? What is the challenge/requirement you have for a single DNS endpoint?

Can you use Postgres?

That’s not done via web console, that’s just MySQL commands like create database database1.

Although, I’d bet you probably want to just run a .sql file against your database to get everything set up as you want it.

Yeah this makes most sense create a database per customer, you also want to create a unique database user with permissions just to access that database. Then give each of your clusters the customer specific db user & password. In general avoid using master/root database credentials in your application, always create a more restricted user.

The downside of this approach is if one of your customers becomes a larger user than others they may impact your other customers, if that happens you may need to split out the ‘noisy neighbor’ to their own RDS instance (and charge appropriately), or throttle customers to specific usage constraints.

The customer id approach is also applicable if you want maintain just one infrastructure and isolation is tolerable at the application level via customer user access, your application then has to enforce isolation via checking who the current user is and what data they are allowed to access.

These days I would always recommend the managed RDS route as the backup, replication, & patching features are too good to give up unless you really like database administration.

Just thinking out loud, but you could setup a Galera Database Cluster and stick that behind an ELB and let it round robin into the cluster. The Galera Cluster takes care of the redundancy and in the case of failure of one node, the ELB simply cuts off access to that node. Of course you’d be operating in degraded mode (which depending on how many nodes you have may or may not matter). When I say this out loud it feels like it needs to be a special use-case scenario since simply using RDS with multi-AZ will handle failover for you.

Why are there 26 databases per tenant in first place?

Its a legacy app that uses M/S SQL Express. The databases got larger than its limit and they had to be split out into multiple databases. As we move to MySQL/Aurora we are looking to re-design the schema to get rid of these multiple databases, but we are not there yet.

Mainly because we need to configure each of our EC2’s with the database DNS name and it is more of a hassle to keep track of a different database DNS name for each EC2. Not a requirement, just a nice to have.