fullstackhero / dotnet-starter-kit

Production Grade Cloud-Ready .NET 8 Starter Kit (Web API + Blazor Client) with Multitenancy Support, and Clean/Modular Architecture that saves roughly 200+ Development Hours! All Batteries Included.
https://fullstackhero.net/dotnet-webapi-boilerplate/
MIT License
5.19k stars 1.56k forks source link

Database Sharding Plan #38

Closed aldycool closed 3 years ago

aldycool commented 3 years ago

Hi,

Have you considered about database sharding plan? If you've planned to support it, I've read that you primarily support PostgreSQL, and Citus Data is one of the sharding solution for it.

According to Citus docs, one of the requirements is to have composite primary keys:

http://docs.citusdata.com/en/v10.1/use_cases/multi_tenant.html#preparing-tables-and-ingesting-data

But it seems that your Dtos are based on a single primary key:

https://github.com/fullstackhero/dotnet-webapi-boilerplate/blob/main/src/Shared/Shared.DTOs/Catalog/ProductDetailsDto.cs

What do you think about this? Thanks

iammukeshm commented 3 years ago

Hi @aldycool,

This is my Entity

https://github.com/fullstackhero/dotnet-webapi-boilerplate/blob/main/src/Core/Domain/Entities/Catalog/Product.cs

Essentially, has a combination of both a Guid Id and a Tenant Id.

aldycool commented 3 years ago

Hi @iammukeshm,

My mistake, I thought the entities are on the Shared project.

I see, the BaseEntity super class carries the Id field and it became the primary key by convention in EF Core. The tenancy identifier is the TenantId field in the derived class. Also, in order to be compliant with Citus sharding, we can enforce the creation of composite primary key (to override the convention Id as primary key) by using the EF Core's ModelBuilder.HasKey() during OnModelCreating(), as specified in the example: https://docs.microsoft.com/en-us/ef/core/modeling/keys?tabs=data-annotations#configuring-a-primary-key.

Very nice, your boilerplate is very flexible to allow this. Thanks for your insights!