Yet another demo project about microservices. The idea is put difficult calculations into a jobs queue, and have a scalable number of workers.
The difficult calculation in this case is factorials of large numbers n!
sequenceDiagram
participant Web
participant Api
participant Db
participant Queue
participant Worker
Web ->> Api : Request calculation
Api ->> Db : Store state
Api ->> Queue : Queue calculation
Queue ->> Worker : Dequeue calculation
Worker ->> Api : Return result
Api ->> Db : Store result
Api -->> Web : Return result
Website for creating calculation jobs, and view pending and finished calculations.
Rest api for calculation jobs. Allows website to create jobs, and view status. Allows workers to post results. Stores information in its own database. Only the api has access to the database.
Stores calculation jobs, their status and results.
Queue of pending calculations
Listens for jobs on the queue. Posts results back to calc-api.
There is a docker-compose file, so all services can be spun up using
docker-compose build
docker-compose up
Up will display the logs of all services, prefixed with their container name. To run the services in the background run docker-compose up -d
To develop individual an service, in an integrated setup docker-compose up -d <name-of-service> <name-of-service> ...
or docker-compose up -d && docker-compose down <name of service>
and then follow how to run locally, for the service
All services run tests, just before the build step, in their Dockerfiles. Running docker-compose build
therefor also runs tests.
Each project can generate a test coverage report, by running npm run test:coverage
. It outputs to the terminal, and a html report.
There is a cypress integration test, that can be run with docker-compose run cypress
.
It is part of the services listed in the docker-compose file, but is ignore by up
, unless explicitly mentioned by name or profile.
All services work: web client, api, queue, workers. Some even have multiple implementations.
- Create-react-app, static build, served with nginx
- NextJS
- Node
- C#
- (incomplete rust, on a branch)
None of the implementations are particularly optimized, and use a simple/naive implementation of looping to calculate factorials. There are no attempts at parallel processing, or memory optimizations.
There is a docker-compose base setup, that works for local development, and testing in CI.
There is a few kubernetes yaml files for services/deployments, but not a full setup (there is a branch with an incomplete helm deploy).