Problem Statement
- We need to choose the best desing 1 or 2 that satisfies all the
considerations
listed
Today Consideration
- Department Id keeps growing
- The number of employees in a given department will be between 0 and 2500
- MongoDb Enterprise 4.2 Atlas
- Should involve less database maintenance
- Should support strong ACID properties
Future Consideration
- Should accommodate future business growth. i.e the number of employeees can grow more and more, reaching 20,000 in next 6 months
- Read operations should not be impacted
- Should stay on low latency level on both read and update operatios
- High availability of document
The Design 1 - Single Document Design
{
"_id" : "",
"departmentId" : "",
"employees" : [{
"employeeId" : 213132,
"name" : "John",
"building" : "123"
},
{
"employeeId" : 213132,
"name" : "John",
"building" : "123"
}]
}
The Design 2 - Multi Document Design
Doc 1:
{
"_id" : "1",
"departmentId" : "1",
"employeeId" : 213132,
"name" : "John",
"building" : "123 QWE 213"
}
Doc 1:
{
"_id" : "2",
"departmentId" : "2",
"employeeId" : 2132,
"name" : "Paul",
"building" : "123 QWE 213"
}
Use Case
- update the employee building for a given departmentId
- update the employee building for a given departmentId and list of employeeIds