We have built a scheduling system to control our client's appointments. This system is similar to the one used by Prometric to schedule an exam. The main concerns are: guarantee that there is no overscheduling, support at least one hundred thousand appointments per month and allow to increase/decrease the testing center capacity easily.
We devised the following design based on Capacity Vectors. We assumed that each appointment requires at least five minutes. A vector is composed by 288 slots (24 hours * 12 slots per hour), each one represented by one byte. The vector allows the system to represent up to 255 appointments every five minutes. The information used is composed by two vectors: one to store the testing center capacity (NOMINAL CAPACITY) and another to store the used capacity (USED CAPACITY). To recover the current capacity (CURRENT CAPACITY), the system takes the testing NOMINAL CAPACITY and subtracts the USED CAPACITY.
The database has the following structure:
NOMINAL CAPACITY
The nominal capacity represents the capacity for work days (Mon-Fri).
| TEST_CENTER_ID | NOMINAL_CAPACITY
| 1 | 0000001212121212....0000
| 2 | 0000005555555555....0000
...
| N | 0000000000010101....0000
USED CAPACITY
This table stores the used capacity for each day / testing center.
| TEST_CENTER_ID | DATE | USED_CAPACITY
| 1 | 01/01/2010 | 0000001010101010...0000
| 1 | 01/02/2010 | 0000000202020202...0000
| 1 | 01/03/2010 | 0000001010101010...0000
...
| 2 | 01/01/2010 | 0000001010101010...0000
...
| N | 01/01/2010 | 0000000000000000...0000
After the client chose the testing center and a date, the system presents the available slots doing the following calculation. For example:
TEST_CENTER_ID 1
DATE 01/01/2010
NOMINAL_CAPACITY 0000001212121212...0000
USED_CAPACITY 0000001010101010...0000
AVAILABLE_CAPAC 0000000202020202...0000
If the client decides to schedule an appointment, the system locks the chosen day (a row in # USED CAPACITY table) and increases the corresponding byte.
The system is working well now, but we foresee contention problems if the number of appointments increases too much.
Does anyone has a better/another model for this problem or suggestions to improve it?
We have thought in avoiding the contention by sub-diving the representation of a vector in hour and changing to an optimistic lock strategy. For example:
| TEST_CENTER_ID | DATE | USED_CAPACITY_0 | USED_CAPACITY_1 | ... | USED_CAPACITY_23
| 1 | 01/01/2010 | 000000101010 | 1010... | ... | ...0000
This way will don't need to lock a row and reduce collision events.