- Prerequisits
- Super quick start
- Run API tests
- Manual build
- API
- How it works?
- Data store choose explained
- TO-DO improvements
Docker-compose & docker
Simply run:
cd <project-dir>/compose
./run.sh up -d
This will pull 3 containers (service, mongo & redis).
Access service on http://localhost:8080/app
Access Swagger API on http://localhost:8080/app/swagger
Run api tests (with embeded mongo & redis)
mvn test
To build (including docker container)
mvn package
To run
docker run -p 8080:8080 e MONGO_IP=<mongo_host> -e MONGO_PORT=<mongo_port> -e REDIS_IP=<redis_host> - e REDIS_PORT=<redis_port> -e LOGGING_LEVEL_ROOT=info
Api is available on http://localhost:8080/app/swagger
It is selfdescriptive and proivdes examples. Based on swagger.
This service is highly scalable and threadsafe. This is achieved by using redis as distributed lock and mongo as database.
When booking endpoint is called:
- Service gets lock on range date (multilock containing each day of a range and locks it as one with no deadlocks) so any other thread or service replica can't modify same days.
- Gets read lock for configuration overbooking ratio (to prevent making reservations in case if someone is changeing documentation in write lock mode)
- Checks in DB for limits for each day, that the're not higher then overbooking ratio
- Increments all days limits by 1
- Releases all locks.
When configuration endpoint is called:
- Service gets write lock on configuration (so no-one can create reservartion at the same time)
- Saves new configuration
- Releases locks
MongoDB is fast, easy to use, highly scalable database and perfectly suits for such cases. It faster and easier to use then SQL database and provides partition tolerance with high availability. Especially when there is no need in transactions, because parallel execution is controlled by application (based on distributed locks)
Redis is used as distributed lock storage, to let Service be scalable and allow to synchronze multiple instances. Basicaly it allows multiple processes of service to work as if it is multiple threads of one process.
- add more logging
- expand DB schema, use room ids for choosing a room, save reservation details etc.
- add indexes for days collections for faster search
- add TTLs for days to clean-up automatically
- add TTLs for locks in REDIS to clean-up automatically
- run tests in another docker container