I've been reading a lot of articles about DDD and noticed that most are using GUID as their ID when persisting to a database. They say that GUID scales well and auto incrementing ID's are a big no-no when it comes to scalability.
Im confused now whether to use GUID
or auto-increment
.
Basically the Domain is about membership system (binary tree). (tracking of register members)
The first requirement is that we should have something that uniquely identifies them in the system (we call it Account No.
) perhaps 7digit.
Then new Members
can be registered by another Member
. We call it referral.
Now what Im planning to do is to have MemberId
of GUID type as the DomainObject Id where it serves as the primary key which will be used for joins, foreign keys (on Referral, referer_id would be the GUID MemberId
). AccountNo
will be an auto-increment column or maybe it will be acquired from repository by MAX() + 1. Mainly it will be used for search features in the system and in links.
Should the ID of DomainObject remain hidden to users of the system since its just a technical implementation?
Is it ok to combine both? GUID as row_id in database (Surrogate Key). and Auto-Increment for (Natural Key)?
Is it okay to exclude the AccountNo
from the constructor because it will be auto-incremented anyway? What about the need to enforce invariants? So is getting the next ID from repository the way to go and include AccountNo
in the constructor?
Should I just stick with Auto-Increment ID and forget about GUID, remove MemberId
and let the AccountNo
be the ID of the DomainObject?
NOTE:
I am not building the next facebook of some kind.
I just want to practice the Tactical side of DDD to learn how to make hard architectural decisions knowing their PROS and CONS.
I just want to practice the Strategic side of DDD to learn how to make hard architectural decisions knowing their PROS and CONS and their implementation.
If we will make 3 scenarios with member registration:
- First Scenario: Member registration happens every minute.
- Second Scenario: Member registration happens every hour.
- Third Scenario: Member registration happens atmost 5 daily.
How will it affect the decisions?
Technology Stack:
- ASP MVC 5
- Sql Server 2014
- C#
- Dapper ORM