Functional:
API design
Here's a breakdown of the essential REST
API for our Employee Swap System.
User service:
PUT /auth/login - authenticate a user
PUT /auth/logout - log out user
POST /auth/register - register new user:
{ "name": "name1"
"email":....
"phone": ...
"employe_id":
"position":
"department":
"manager_id"
}
Employee shift matching service:
PUT /shift_matching/v1/swap/{employee_id1}/{shift_id1}/swap/{employee_id2}/{shift_id2} - try to swap the shift_id1 of the employee_id1 with shift_id2 of employee_id2:
Return :
{ "swap_id"....
"status": IN_PROGRESS,APPROVED_BY_MANAGER,APPROVED_BY_OTHER_EMPLOYEE,CANCELED
"createdAt": ....
}
GET /shift_matching/v1/swap/{employee_id}/status/{shift_id} - return the swap attempt status:
{ "swap_id"....
"status": IN_PROGRESS,APPROVED_BY_MANAGER,APPROVED_BY_EMPLOYEE,CANCELED
"createdAt": ....
}
GET /shift_matching/v1/shift/{employee_id}
return the available shifts for an employee
{[.
'shift_id':
'employee_id':
'start_time':
'end_time':
'last_swap_date':
]}
PUT /shift_matching/v1/swap/{employee_id}/approve/{shift_id} - an employee approves the suggested shift.
PUT /shift_matching/swap/manager/{manager_id}/approve/{shift_id} - a manager approves the suggested shift if both employees agree.
Employee Shift service:
GET /employee_shift/v1/shift/{employee_id}/shifts - get the list of the shifts scheduled by the employee_id:
{ "employee_id":...
"shifts":[
{ "shift_id":....
"startFrom":
"endTo":
'status':
'last_swap_date'
},
....
]
POST /employee_shift/v1/shift/{employee_id}
Persist the new shift for an employee.
body:
{ 'shift_id'
'employee_id'
'start_date':
'end_date':
'status':
'last_swap_date':
}
PUT /employee_shift/v1/shift/{employee_id}
Update the shift information for an employee.
See the diagram from the high-level architecture.
API Gateway provides DDoS protection and TLS termination, and routes the requests to the right service nodes.
The user service:
Employee shift matching service:
Employee shift service:
Kafka:
Notification service:
Postgres:
Redis:
Dig deeper into 2-3 components and explain in detail how they work. For example, how well does each component scale? Any relevant algorithm or data structure you like to use for a component? Also you could draw a diagram using the diagramming tool to enhance your design...
Employee shift matching service:
This is essential service and it's used to match the given employee shift. For that the service the Redis structures to hold the employee shift start time for every employee. When someone requests to swap the two employees shift, the service query the Redist startTime from the Redis, verifies that's shifts are available and update the employee shift in Redis. Further the other employee should approve it
Defining the system data model early on will clarify how data will flow among different components of the system. Also you could draw an ER diagram using the diagramming tool to enhance your design...