As a hypothetical example, say I wanted to shard a PostgreSQL database for a multi-tenant setup. Each of the tenants has an ID that is stored as a foreign key in a column on every record of every table. Is it possible to then shard the database by the tenants' ID for each record and allow querying by the shard?
Say there are four physical servers, all with one shard, and that there are four tenants:
- Server 1 - Shard 1 - Tenant 1's data
- Server 2 - Shard 2 - Tenant 2's data
- Server 3 - Shard 3 - Tenant 3's data
- Server 4 - Shard 4 - Tenant 4's data
Would it then be possible to allow an application such as a web framework, knowing what tenant it is serving, to then connect to and query (including reading and writing) the respective server with the respective shard?