- Related course module: Distributed Systems
- Tutorial scope: DS Design and Implementation
- Technologies: Linux, Docker, OpenAPI, Cloud Native
During this tutorial, we will learn few things like:
- How to design a microservice using OpenAPI
- How to develop a RESTful µService
- Deploy the service using docker compose
- Scale out/in the microservice
Note: In the following, you will see
Discoverif you should play around and see the documentation or test. You will seeActionif you should run a command, write a program, or something similar. You will seeQuestionwhen there is a question to provide an answer to.
- A functional linux environment
- A function Docker installation
- Github or Gitlab account
Check out these tutorials on how to get a Linux OS up and running:
Check out Lab0: Foundations 1 - Deployment of a Centralized App to learn more about installing docker and docker compose.
I recommend that you create a text file with your favorite editor where you will continuously copy the commands and their output to help you with your Lab report.
Note: Your report should include a link to your project's git repo
Discover
Explore these links
Question
- What do we mean by
graceful shutdown? give an example from the 12factor App methodology. - How OpenAPI can be used in the context of Microservices ?
- How server and client basic code can be generated using OpenAPI ?
The microservice you will be developping will be a dummy app that if ping'ed replies with Pong and an ID (more about it later).
Discover
You can find in this repo, a basic OpenAPI specification of the RESTful API of our app.
If needed, you can use this app to convert YAML to JSON.
Question
- What is main route of this API ?
- Which HTTP verbs are allowed for each route ?
- What are the properties of a message ?
- Which encoding is used in the reply ?
- What happens if the request is malformed ?
Discover
Explore this link:
Question
- What is Codegen and what is it used for ?
Action
To generate the server, we will be using Codegen. First, select your preferred language. To explore all the supported languages, we can use:
docker run --rm swaggerapi/swagger-codegen-cli-v3 langsQuestion
- What are the supported languages ?
- What is the size of the Codegen container image ?
Action
Generate the server code using the generate command.
Example using Python:
docker run --rm -v ${PWD}:/local swaggerapi/swagger-codegen-cli-v3 generate -i /local/ping.yaml -l python-flask -o /local/app -DserviceAction
Install the dependencies and execute the server (assuming a python version) locally.
Note: I highly recommend using a virtual environment to install the requirements:
python3 -m venv venv
Note: In
requirements.txtmake sure to replaceconnexion >= 2.6.0byconnexion < 3.0.0
Finally make sure to exclude venv folder from the list of git track list by adding it to your .gitignore. To learn more about gitignore you can check this link.
💡Please find below a list of hints to help you navigate the bootstrap phase:
pip list # list installed packages
pip install -r requirements.txt # install app requirements
python3 setup.py install --record files.txt # install the generated server package
xargs rm -rf < files.txt # delete the installed server packageThis is a sample output to give you an idea about what you should expect:
(venv) velectron:~/.../lab2/ping-app$ swagger_server
* Serving Flask app 'swagger_server.__main__'
* Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on all addresses (0.0.0.0)
* Running on http://127.0.0.1:8000
* Running on http://192.10.104.32:8000
Press CTRL+C to quit
127.0.0.1 - - [28/Mar/2026 17:50:10] "GET /ping HTTP/1.1" 200 -Action
For the client part, cURL is enough to run some tests:
curl -X GET --header 'Accept: application/json' 'http://127.0.0.1:8080/ping'Question
- What is the result of the cURL command ?
Action
Try to locate the server code and update it to return an ID. This ID should be the hostname of your machine.
You can use the following code snippet to get the hostname:
import socket
print(socket.gethostname())Action
Codegen also generates a Dockerfile. Use that file to build your docker image.
You can use the following command to build the image:
docker build -t ping-app:latest .
Please feel free to use your own image tag, but make sure to use the correct one for the rest of this lab.
Discover
A compose file is provided for this part. Examine its content.
Question
- What are the services defined in this stack ?
- What are the ports used by each service ?
- What is the difference between a proxy, a reverse proxy, an API gateway and a Load balancer ?
- Which one is used in our case ?
Action
Fix any issues in this docker-compose.yaml file and used to deploy our µService.
Question
What is the output of the following command:
curl http://localhost/pingYou can optionally use jq for a better presentation.
Question
- How can we scale out the ping µService ?
Action
Scale out the ping service to 10 replicas.
What is the output of the following command after scaling our service:
curl http://localhost/pingTHE END.